1、经过2天的坑总结一下两个支付集成:
浏览器alloc设置:
代理方法区分微信和支付宝跳转
- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void(^)(WKNavigationActionPolicy))decisionHandler {
NSString*urlString = [[navigationAction.requestURL]absoluteString];
urlString = [urlStringstringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if([urlStringcontainsString:@"weixin://wap/pay?"]) {
decisionHandler(WKNavigationActionPolicyCancel);
//解决wkwebview weixin://无法打开微信客户端的处理
NSURL*url = [NSURLURLWithString:urlString];
BOOL bSucc = [[UIApplication sharedApplication]openURL:url];
if(!bSucc) {
[self showHint:@"未检测到微信APP,请您先安装"];
}else
{
[[UIApplication sharedApplication]openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:^(BOOL success) {
}];
}
}else if ([urlString containsString:@"alipay://alipayclient/?"])
{
decisionHandler(WKNavigationActionPolicyCancel);
urlString = [urlStringstringByReplacingOccurrencesOfString:@"alipays" withString:kPaySchemeURL];
urlString=[urlStringstringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[NSCharacterSet URLQueryAllowedCharacterSet];
NSURL*url = [NSURLURLWithString:urlString];
BOOL bSucc = [[UIApplication sharedApplication]openURL:url];
if(!bSucc) {
[self showHint:@"未检测到支付宝APP,请您先安装"];
}else
{
[[UIApplication sharedApplication]openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:^(BOOL success) {
}];
}
}else{
decisionHandler(WKNavigationActionPolicyAllow);
}
}
配置这些以后应该能调起支付宝/微信了。
最后配置白名单:
这样微信/支付宝支付完成会调起我们的应用并在appdelegate里接到回调:
注意点:
1、支付宝可获取到是否支付成功标识
2、微信无法获取到支付结果,所以获取到订单编号,去本地服务器校验
3、支付宝return_url是无效的,需要客户端修改alipays为自己的白名单,其实就是fromAppUrlScheme对应的数据
服务器要做的:
1、微信h5可自定义支付返回结果,把客户端的白名单和订单编号一起返回