提交 5c84fea4 authored 作者: JarvanMo's avatar JarvanMo

update docs.

上级 92ea2dc5
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
## Preparation ## Preparation
[Migrate to V4 now](./doc/MIGRATE_TO_V4_CN.md)
`Fluwx` is good but not God. You'd better read [official documents](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1) before `Fluwx` is good but not God. You'd better read [official documents](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1) before
integrating `Fluwx`. Then you'll understand how to generate Android signature, what's universal link for iOS, how to add URL schema for iOS and so on. integrating `Fluwx`. Then you'll understand how to generate Android signature, what's universal link for iOS, how to add URL schema for iOS and so on.
...@@ -46,23 +48,34 @@ dependencies: ...@@ -46,23 +48,34 @@ dependencies:
`Fluwx` without pay: `Fluwx` without pay:
```yaml > Developers who need to exclude payment for iOS can enable `no_pay` in [pubspec.yaml](./example/pubspec.yaml).
dependencies:
fluwx_no_pay: ^${latestVersion}
```
![pub package](https://img.shields.io/pub/v/fluwx_no_pay.svg) ![pub package](https://img.shields.io/pub/v/fluwx_no_pay.svg)
> NOTE: Never forget to replace ^${latestVersion} with actual version. > NOTE: Never forget to replace ^${latestVersion} with actual version.
## Configurations
`Fluwx` enables multiple configurations in the section `fluwx` of `pubspec.yaml` from v4, you can reference [pubspec.yaml](./example/pubspec.yaml)
for more details.
> For iOS, some configurations, such as url_scheme,universal_link, LSApplicationQueriesSchemes, can be configured by `fluwx`,
> what you need to do is to fill configurations in `pubspec.yaml`
- app_id. Required. It'll be used to generate scheme on iOS and register WxApi on Android side if app is cold boot.
- debug_logging. Optional. Enable logs by setting it `true`.
- flutter_activity. Optional. This is usually used by cold boot from WeChat on Android. `Fluwx` will try to launch launcher activity if not set.
- universal_link. Required for iOS. It'll be used to generate universal link on your projects.
## Register WxAPI ## Register WxAPI
Register your app via `fluwx` if necessary. Register your app via `fluwx` if necessary.
```dart ```dart
registerWxApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.univerallink.com/link/"); Fluwx fluwx = Fluwx();
fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.univerallink.com/link/");
``` ```
The param `universalLink` only works with iOS. You can read [this document](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) to learn The param `universalLink` only works with iOS. You can read [this document](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) to learn
how to create universalLink. You can also learn how to add URL schema, how to add `LSApplicationQueriesSchemes` in your iOS project. This is essential. how to create universalLink. You can also learn how to add URL schema, how to add `LSApplicationQueriesSchemes` in your iOS project. This is essential.
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
## 准备 ## 准备
[迁移到V4指南](./doc/MIGRATE_TO_V4_CN.md)
`Fluwx` 可以做很多工作但不是所有. 在集成之前,最好读一下[官方文档](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1). `Fluwx` 可以做很多工作但不是所有. 在集成之前,最好读一下[官方文档](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1).
然后你才知道怎么生成签名,怎么使用universal link以及怎么添加URL schema等. 然后你才知道怎么生成签名,怎么使用universal link以及怎么添加URL schema等.
...@@ -42,23 +44,32 @@ dependencies: ...@@ -42,23 +44,32 @@ dependencies:
``` ```
![pub package](https://img.shields.io/pub/v/fluwx.svg) ![pub package](https://img.shields.io/pub/v/fluwx.svg)
`Fluwx`,不带支付: 不带支付的`Fluwx`:
```yaml
dependencies:
fluwx_no_pay: ^${latestVersion}
```
![pub package](https://img.shields.io/pub/v/fluwx_no_pay.svg) > 一些开发者并不需要在iOS端使用支付能力,此时您可以通过在[pubspec.yaml](./example/pubspec.yaml).
![pub package](https://img.shields.io/pub/v/fluwx_no_pay.svg)中开启`no_pay`
> NOTE: 别忘记替换 ^${latestVersion} !!!! > NOTE: 别忘记替换 ^${latestVersion} !!!!
## 配置
`Fluwx` 从v4开始可以在`pubspec.yaml``fluwx`进行一些配置。具体可以参考[pubspec.yaml](./example/pubspec.yaml)
> V4开始,iOS中的url_scheme,universal_link, LSApplicationQueriesSchemes可以不必开发者手动配动。只需在`pubspec.yaml`
> 中填写即可。
- app_id. 必填. 它将用于生成iOS的url_scheme以及在Android端冷启动时,重新初始化WxApi。
- debug_logging. 可选. 把它设置成`true`可以开启日志。
- flutter_activity. 可选. 这个通常是用于Android的冷启动。如果不设置任何值,`Fluwx`将尝试启动launcher activity.
- universal_link. iOS 必填. 它将用自动配置universal_link。
## 注册 WxAPI ## 注册 WxAPI
通过 `fluwx` 注册WxApi. 通过 `fluwx` 注册WxApi.
```dart ```dart
registerWxApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.univerallink.com/link/"); Fluwx fluwx = Fluwx();
fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.univerallink.com/link/");
``` ```
参数 `universalLink` 只在iOS上有用. 查看[文档](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) 以便了解如何生成通用链接. 参数 `universalLink` 只在iOS上有用. 查看[文档](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) 以便了解如何生成通用链接.
......
...@@ -4,8 +4,9 @@ The purpose of `sendWeChatAuth` is to get auth code and then get information for ...@@ -4,8 +4,9 @@ The purpose of `sendWeChatAuth` is to get auth code and then get information for
Getting `access_token` is not supported in `fluwx`. For `access_token`, please visit [official documents](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Development_Guide.html). Getting `access_token` is not supported in `fluwx`. For `access_token`, please visit [official documents](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Development_Guide.html).
```dart ```dart
sendWeChatAuth(scope: "snsapi_userinfo", state: "wechat_sdk_demo_test"); Fluwx fluwx = Fluwx();
``` fluwx.authBy(which: NormalAuth(scope: 'snsapi_userinfo', state: 'wechat_sdk_demo_test'));
```
> WHY? I think we shall fetch access_token or user info at backend. > WHY? I think we shall fetch access_token or user info at backend.
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
`sendWeChatAuth`的目的是为了获取code,拿到了code才能进行微信登录,可以通过[官方文档](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Development_Guide.html)查看具体流程。 `sendWeChatAuth`的目的是为了获取code,拿到了code才能进行微信登录,可以通过[官方文档](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Development_Guide.html)查看具体流程。
```dart ```dart
sendWeChatAuth(scope: "snsapi_userinfo", state: "wechat_sdk_demo_test"); Fluwx fluwx = Fluwx();
fluwx.authBy(which: NormalAuth(scope: 'snsapi_userinfo', state: 'wechat_sdk_demo_test'));
``` ```
> 为什么不支持获取用户信息? 我认为获取用户信息应该后端来做,即使没有后端,你也可以在dart层自己实现. > 为什么不支持获取用户信息? 我认为获取用户信息应该后端来做,即使没有后端,你也可以在dart层自己实现.
......
## Basic knowledge ## Basic knowledge
### Response from WeChat ### Response from WeChat
Actually, almost every result from functions like `shareToWeChat` or `payWithWeChat` which call `sendRequest` in native doesn't makes sense. The `bool` value is the result of `sendRequest`. Actually, almost every result from functions like `share` or `pay` which call `sendRequest` in native doesn't makes sense. The `bool` value is the result of `sendRequest`.
So if you want get the real result you shall do like this: So if you want get the real result you shall do like this:
```dart ```dart
fluwx.weChatResponseEventHandler.listen((res) { fluwx.subscribeResponse((response) {
if (res is fluwx.WeChatPaymentResponse) { if (response is WeChatAuthResponse) {
// do something here
} }
}); });
``` ```
Take a look at subclasses of `BaseWeChatResponse` for help. Take a look at subclasses of `WeChatResponse` for help.
> NOTE: If you get `errCode = -1`, please read the WeChatSDK document for help. There are to many cases lead to that. > NOTE: If you get `errCode = -1`, please read the WeChatSDK document for help. There are to many cases lead to that.
You can also unsubscribe response by calling `fluwx.subscribeResponse`.
### Images in WeChat ### Images in WeChat
The are four built-in types of `WeChatImage` in `fluwx`: The are four built-in types of `WeChatImage` in `fluwx`:
......
...@@ -6,15 +6,17 @@ ...@@ -6,15 +6,17 @@
为了获取真实的回调,你应该这样做: 为了获取真实的回调,你应该这样做:
```dart ```dart
fluwx.weChatResponseEventHandler.listen((res) { fluwx.subscribeResponse((response) {
if (res is fluwx.WeChatPaymentResponse) { if (response is WeChatAuthResponse) {
// do something here
} }
}); });
``` ```
> 笔记: 如果你的 `errCode = -1`, 那请阅读微信官方文档,因为-1的原因数不胜数. > 笔记: 如果你的 `errCode = -1`, 那请阅读微信官方文档,因为-1的原因数不胜数.
你也可以通过`fluwx.unsubscribeResponse`取消订阅消息。
### 图片 ### 图片
有四种内置 `WeChatImage`: 有四种内置 `WeChatImage`:
......
## Launch App from H5
Fluwx supports launch app from `<wx-open-launch-app>`, and pass `extInfo` to your app.
For Android side, you need add the following action for your FlutterActivity in `AndroidManifest.xml`:
```
<intent-filter>
<action android:name="${applicationId}.FlutterActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="${applicationId}"
android:path="/"
android:scheme="wechatextmsg" />
</intent-filter>
```
At the same time, you also need to add `<meta-data>` in application which used to store your WeChat AppId:
```xml
<meta-data
android:name="weChatAppId"
android:value="12345678" />
```
If you want to pass `extInfo` to Flutter, you need to add the following code in `MainActivity.kt`:
```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//If you didn't configure WxAPI, add the following code
WXAPiHandler.setupWxApi("wxd930ea5d5a258f4f",this)
//Get Ext-Info from Intent.
FluwxRequestHandler.handleRequestInfoFromIntent(intent)
}
```
If you want to custom your request logic, you need add the `<meta-data>` in application:
```xml
<meta-data
android:name="handleWeChatRequestByFluwx"
android:value="false" />
```
And then, set `FluwxRequestHandler.customOnReqDelegate` on your own.
## on Android 11
Please add the following queries in your app's `AndroidManifest.xml`:
```xml
<queries>
<intent>
<action android:name="${applicationId}.FlutterActivity" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data
android:host="${applicationId}"
android:path="/"
android:scheme="wechatextmsg" />
</intent>
</queries>
```
## IOS ## IOS
Please register your WXApi in your `AppDelegate`: Please register your WXApi in your `AppDelegate`:
```oc ```oc
......
## 从H5启动app
Fluwx 支持从`<wx-open-launch-app>`启动你的app, 并且支持传递`extInfo`给你的app.
对于Android来说,你要在`AndroidManifest.xml`中给你的`Activity`加上一个标签:
```
<intent-filter>
<action android:name="${applicationId}.FlutterActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="${applicationId}"
android:path="/"
android:scheme="wechatextmsg" />
</intent-filter>
```
与此同时,你还需要在需要在application中加上`<meta-data>`,把你的appId放进去:
```xml
<meta-data
android:name="weChatAppId"
android:value="12345678" />
```
如果你想把`extInfo`传给Flutter, 你要在`MainActivity`加上如下代码:
```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//If you didn't configure WxAPI, add the following code
WXAPiHandler.setupWxApi("wxd930ea5d5a258f4f",this)
//Get Ext-Info from Intent.
FluwxRequestHandler.handleRequestInfoFromIntent(intent)
}
```
如果你想自定义你的调用逻辑, 你需要在application中加上`<meta-data>`:
```xml
<meta-data
android:name="handleWeChatRequestByFluwx"
android:value="false" />
```
然后, 自己实现 `FluwxRequestHandler.customOnReqDelegate`.
## 兼容Android 11
请在你的应用的`AndroidManifest.xml`中添加以下queries:
```xml
<queries>
<intent>
<action android:name="${applicationId}.FlutterActivity" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data
android:host="${applicationId}"
android:path="/"
android:scheme="wechatextmsg" />
</intent>
</queries>
```
## IOS ## IOS
请在你的`AppDelegate`中主动注册`WXApi` 请在你的`AppDelegate`中主动注册`WXApi`
......
## Upgrade to V4
`Fluwx v4` not only brings a lot exciting functionalities but also breaking changes。
- Now we need to initialize the instance using `Fluwx fluwx = Fluwx()`
- Listening response from WeChat changed to `subscribeResponse` and also adding `unsubscribeResponse` to support
cancel listening.
- Keyword `wechat` in some functions is removed.
- Some functions are extracted to a single function,and now you can pass different params instead.
- Some configurations are moved to[pubspec.yaml](../example/pubspec.yaml),for example, you can enable/disable log in `pubspec.yaml`.
- `no_pay` can be enabled by [pubspec.yaml](../example/pubspec.yaml), reference example for more details.
\ No newline at end of file
## 升级到V4
`Fluwx v4`带来了很多令人兴奋的功能,但也带来了少破坏性更新。
- 现在我们需要使用`Fluwx fluwx = Fluwx()`初始化实例
- 监听微信回调变成了`subscribeResponse`并且增加了`unsubscribeResponse`以支持取消监听
- 很多带有`wechat`关键字的函数已经把`wechat`关键字删除了
- 很多方法被整到了一个函数中,现在你可以传递不同的对象实现对应的业务
- 一些配置被移动到了[pubspec.yaml](../example/pubspec.yaml),可以通过`pubspec.yaml`配置是否开启日志等等
- `no_pay`现在也通过[pubspec.yaml](../example/pubspec.yaml)配置,具体可以参加example.
\ No newline at end of file
...@@ -3,15 +3,16 @@ ...@@ -3,15 +3,16 @@
Calling payment is easy but to make it work isn't not so easy: Calling payment is easy but to make it work isn't not so easy:
```dart ```dart
payWithWeChat( fluwx.pay(
appId: result['appid'], which: Payment(
partnerId: result['partnerid'], appId: result['appid'].toString(),
prepayId: result['prepayid'], partnerId: result['partnerid'].toString(),
packageValue: result['package'], prepayId: result['prepayid'].toString(),
nonceStr: result['noncestr'], packageValue: result['package'].toString(),
timeStamp: result['timestamp'], nonceStr: result['noncestr'].toString(),
sign: result['sign'], timestamp: result['timestamp'],
); sign: result['sign'].toString(),
));
``` ```
Take a look at [payment document](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=11_1#) for help. Take a look at [payment document](https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=11_1#) for help.
...@@ -3,31 +3,16 @@ ...@@ -3,31 +3,16 @@
调用支付方法很简单,但想成功并不简单: 调用支付方法很简单,但想成功并不简单:
```dart ```dart
payWithWeChat( fluwx.pay(
appId: result['appid'], which: Payment(
partnerId: result['partnerid'], appId: result['appid'].toString(),
prepayId: result['prepayid'], partnerId: result['partnerid'].toString(),
packageValue: result['package'], prepayId: result['prepayid'].toString(),
nonceStr: result['noncestr'], packageValue: result['package'].toString(),
timeStamp: result['timestamp'], nonceStr: result['noncestr'].toString(),
sign: result['sign'], timestamp: result['timestamp'],
); sign: result['sign'].toString(),
``` ));
## iOS 支付
* 配置`URL Schemes` ,内容为应用的`AppID`, 可以登录微信开放平台查看。编辑`ios/Runner/Info.plist`
```xml
<key>CFBundleURLSchemes</key>
<array>
<string>wx84cxxxxxx</string>
</array>
```
* 配置`LSApplicationQueriesSchemes`
![image-20210523140138835](https://gitee.com/inkkk0516/typora/raw/master/image-20210523140138835.png)
* 使用 * 使用
......
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
Simple and easy: Simple and easy:
```dart ```dart
shareToWeChat(WeChatShareTextModel("source text", scene: WeChatScene.SESSION)); fluwx.share(WeChatShareTextModel("source text", scene: WeChatScene.SESSION));
``` ```
The destination of sharing can be SESSION(default),TIMELINE or FAVORITE.However,mini-program only support SESSION. The destination of sharing can be SESSION(default),TIMELINE or FAVORITE.However,mini-program only support SESSION.
```dart ```dart
///[WeChatScene.SESSION]会话 ///[WeChatScene.session]会话
///[WeChatScene.TIMELINE]朋友圈 ///[WeChatScene.timeline]朋友圈
///[WeChatScene.FAVORITE]收藏 ///[WeChatScene.favorite]收藏
enum WeChatScene { enum WeChatScene {
SESSION, session,
TIMELINE, timeline,
FAVORITE favorite
} }
``` ```
......
...@@ -2,21 +2,22 @@ ...@@ -2,21 +2,22 @@
简单: 简单:
```dart ```dart
shareToWeChat(WeChatShareTextModel("source text", scene: WeChatScene.SESSION)); fluwx.share(WeChatShareTextModel("source text", scene: WeChatScene.SESSION));
``` ```
绝大部分分享可以分享到会话,朋友圈,收藏(小程序目前只能分享到会话)。默认分享到会话。 绝大部分分享可以分享到会话,朋友圈,收藏(小程序目前只能分享到会话)。默认分享到会话。
```dart ```dart
///[WeChatScene.SESSION]会话 ///[WeChatScene.session]会话
///[WeChatScene.TIMELINE]朋友圈 ///[WeChatScene.timeline]朋友圈
///[WeChatScene.FAVORITE]收藏 ///[WeChatScene.favorite]收藏
enum WeChatScene { enum WeChatScene {
SESSION, session,
TIMELINE, timeline,
FAVORITE favorite
} }
``` ```
支持的分享各类: 支持的分享各类:
- WeChatShareTextModel - WeChatShareTextModel
......
...@@ -64,10 +64,7 @@ class _PayPageState extends State<PayPage> { ...@@ -64,10 +64,7 @@ class _PayPageState extends State<PayPage> {
nonceStr: result['noncestr'].toString(), nonceStr: result['noncestr'].toString(),
timestamp: result['timestamp'], timestamp: result['timestamp'],
sign: result['sign'].toString(), sign: result['sign'].toString(),
)) ));
.then((data) {
print('---》$data');
});
}, },
child: const Text('pay'), child: const Text('pay'),
), ),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论