近期项目需要APP支持微信支付。下载了微信SDK1.8.6.1含支付功能后,发现从该版开始需要支持Universal Links (通用链接)。注意QQSDK最新版本也要支持Universal Links(暂时没有接入,后期更新)。
Universal Links苹果官方文档 https://developer.apple.com/documentation/uikit/inter-process_communication/allowing_apps_and_websites_to_link_to_your_content(文章末尾有友情提示)
微信SDK1.8.6.1含支付下载链接https://res.wx.qq.com/op_res/R0055ZIvvDXD50eUYe1IhT4dyDRavzPn1hcrlR3ZoCbxcumqRo9LdCQyenxpGcL-
简要步骤如下:
上述操作后,自动添加.entitlements文件,内容如下图
CODESigningEntitlements修改文件引用如 xxx工程目录/文件名.CODESigningEntitlements如下图
3-后台服务器(https协议)根目录或根目录/.well-known目录下添加apple-app-site-association文件,文件名为apple-app-site-association,不要任何后缀名;内容为json格式,内容如下:
{
"applinks": {
"apps": [],
"details": [{
"appID": "TeamID.BuildID",
"paths" : [ "/wap/*"]
}]
}
}
参考文件
微信 https://help.wechat.com/apple-app-site-association
QQ https://qm.qq.com/apple-app-site-association
Apple提供验证上述文件的链接 https://search.developer.apple.com/appsearch-validation-tool/文件验证可能会有时间延迟,刚刚配置的,不一定是下图验证结果。
4-微信后台设置通用链接
5-按照微信支付文档对接
文档链接:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html
//向微信注册
[WXApi registerApp:WX_APPKEY universalLink:@"https://xxx.xxx.xxx/wap/"];
// App唤起微信支付页面
PayReq *request = [PayReq new];
[WXApi sendReq:request completion:^(BOOL success) {
if ( completion ) {// 是否调用成功
completion(success);
}
}];
// 微信响应通过通用链接唤起App,App处理支付回调结果
- (void)onResp:(BaseResp *)resp { //WXApiDelegate 代理方法
// 微信支付
if ( [resp isKindOfClass:[PayResp class]] ) {
//
}
}
6-测试
微信SDK接入成功后,在测试机Run一下(最好先卸载),此时截包应该会有获取apple-app-site-association文件的请求。完成支付测试,小编已经测试通过了。
【小编感触】对接了好几天,有同事以前对接过Universal Links,但是没有成功,现在终于可以了。
【苹果官方文档】 https://developer.apple.com/documentation/uikit/inter-process_communication/allowing_apps_and_websites_to_link_to_your_content
建议看一下,下面有关跨域的说明
Support Universal Links
Take the following steps to support universal links:
- 【配置并生效】Create a two-way association between your app and your website and specify the URLs that your app handles, as described in Enabling Universal Links.
- 【处理】Update your app delegate to respond to the user activity object iOS provides when a universal link routes to your app, as described in Handling Universal Links.
.
.
.
【跨域重点】When a user browses your website in Safari and taps a universal link in the same domain, iOS opens that link in Safari, respecting the user’s most likely intent to continue within the browser. If the user taps a universal link in a different domain, iOS opens the link in your app.(from:https://developer.apple.com/documentation/uikit/inter-process_communication/allowing_apps_and_websites_to_link_to_your_content
)
【跨域重点】当用户在Safari中浏览你的网站并点击同一个域中的通用链接时,iOS会在Safari中打开该链接,以尊重用户最有可能在浏览器中继续浏览的意图。如果用户点击了不同域中的通用链接,iOS会在你的应用程序中打开该链接。