通过官方文档把需要配置的都配好, 公众号appId,微信开放平台appId, 确保运行wx.ready能返回正确的结果
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html#22
在微信开放平台,增加配置js安全域名,要跟公众号平台配置保致一致,否则会报: launch:fail_check fail
h5端增加标签wx-open-launch-app, 加上跳转成功和失败的handler
extinfo用来传递参数: sign?start_lat=&start_lng&
vue
<wx-open-launch-app id="launch-btn" appid="xxx" extinfo="sign?start_lat=&start_lng&"
@error="handleError" @launch="handleLaunch">
<script type="text/wxtag-template">
<style>.btn { padding: 12px }</style>
<button class="btn">App内查看</button>
</script>
</wx-open-launch-app>
const handleError = (e) => {
console.log('handleError', e.detail)
Toast(`打开失败: ${e.detail}, 下载app...`)
}
const handleLaunch = (e) => {
console.log('handleLaunch', e.detail)
}
“launch:fail” | 当前场景不支持跳转,或Android上该应用未安装,或iOS上用户在弹窗上点击确认但该应⽤未安装 |
“launch:fail” | 当前打开h5页面的域名跟wx.ready里不一样时,也是同会报错, 例: 链接是http打头的,打开时自动转到https,此时wx.ready去验证的域名应该是https打头的,此时也会报错,解决方式: 用一致的域名打开,如果还提示,微信h5刷新一下页面即可 |
fluwx = Fluwx();//微信
fluwx.registerApi(appId: "xxx");
final String? extMsg = await fluwx.getExtMsg();//extMsg = sign?start_lat=&start_lng&
还原为标准的uri去处理
Uri initialUri = Uri.parse(extMsg);
fluwx里,已经把通过IWXAPIEventHandler把从微信过来的消息,放到methodChannel里,
kt
override fun onReq(req: BaseReq?) {
activityPluginBinding?.activity?.let { activity ->
req?.let {
if (FluwxConfigurations.interruptWeChatRequestByFluwx) {
when (req) {
is ShowMessageFromWX.Req -> handleShowMessageFromWX(req)
is LaunchFromWX.Req -> handleLaunchFromWX(req)
else -> {}
}
} else {
FluwxRequestHandler.customOnReqDelegate?.invoke(req, activity)
}
}
}
}
以下是默认的单次获取
dart
/// Get ext Message
@override
Future<String?> getExtMsg() {
return methodChannel.invokeMethod('getExtMsg');
}
如果需要接收extInfo的话.以上接收微息的消息,使用fluwx还有点问题
最终的处理方式