feat 添加回调事件例子

This commit is contained in:
little-snow-fox 2020-04-08 09:29:59 +08:00
parent c72129f17d
commit b98ecb50b5
2 changed files with 22 additions and 1 deletions

View File

@ -375,6 +375,27 @@ Sends request for proceeding payment, then returns an object:
| templateId | String | 订阅消息模板 ID在微信开放平台提交应用审核通过后获得 |
| reserved | String | 用于保持请求和回调的状态,授权请后原样带回给第三方。该参数可用于防止 csrf 攻击(跨站请求伪造攻击),建议第三方带上该参数,可设置为简单的随机数加 session 进行校验,开发者可以填写 a-zA-Z0-9 的参数值,最多 128 字节,要求做 urlencode |
#### 订阅回调事件
```
WeChat.registerApp(Global.APP_ID, Global.UNIVERSAL_LINK);
DeviceEventEmitter.addListener('WeChat_Req', req => {
console.log('req:', req)
if (req.type === 'LaunchFromWX.Req') { // 从小程序回到APP的事件
miniProgramCallback(req.extMsg)
}
});
DeviceEventEmitter.addListener('WeChat_Resp', resp => {
console.log('res:', resp)
if (resp.type === 'WXLaunchMiniProgramReq.Resp') { // 从小程序回到APP的事件
miniProgramCallback(resp.extMsg)
} else if (resp.type === 'SendMessageToWX.Resp') { // 发送微信消息后的事件
sendMessageCallback(resp.country)
} else if (resp.type === 'PayReq.Resp') { // 支付回调
payCallback(resp)
}
});
```
## License
MIT

View File

@ -1,6 +1,6 @@
{
"name": "react-native-wechat-lib",
"version": "1.1.15",
"version": "1.1.16",
"description": "react-native library for wechat app. 支持分享和拉起小程序。",
"main": "index.js",
"scripts": {