iOS APP内使用H5支付不能唤起微信支付的事件处理

// 不能唤起微信支付事件处理
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
     
   WKNavigationActionPolicy actionPolicy = WKNavigationActionPolicyAllow;
    NSString*urlString = navigationAction.request.URL.absoluteString;

    urlString = [urlString stringByRemovingPercentEncoding];
    if ([urlString containsString:@"weixin://wap/pay?"]) {
        actionPolicy =WKNavigationActionPolicyCancel;
        //解决wkwebview weixin://无法打开微信客户端的处理
        NSURL*url = [NSURL URLWithString:urlString];
        if ([[UIApplication sharedApplication]respondsToSelector:@selector(openURL:options:completionHandler:)]) {
            [[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:^(BOOL success) {
            }];
        } else {
            [[UIApplication sharedApplication]openURL:webView.URL];
        }
    }
    //允许跳转
    decisionHandler(WKNavigationActionPolicyAllow);
}

// wkwebview打开微信返回app回调处理
    NSString *url = navigationAction.request.URL.absoluteString;
    if ([url containsString:@"https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?"]) {
        //传入的是微信支付链接:https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx201801291021026cb304f9050743178155&package=3456576571
        //这里把webView设置成一个像素点,主要是不影响操作和界面,主要的作用是设置referer和调起微信
        
        WebChatPayH5VIew *h5View = [[WebChatPayH5VIew alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
        //url是没有拼接redirect_url微信h5支付链接
        [h5View loadingURL:url withIsWebChatURL:NO];
        [self.view addSubview:h5View];
         decisionHandler(WKNavigationActionPolicyCancel);
    } else {
        decisionHandler(WKNavigationActionPolicyAllow);
     }


// 其中WebChatPayH5VIew为uiwebview  里面主要逻辑为如下
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

            dispatch_async(dispatch_get_main_queue(), ^{

                NSURL *url = [request URL];

                NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

                //设置授权域名

                [request setValue:@"www.payment.xy189.cn://" forHTTPHeaderField: @"Referer"];

                [self.myWebView loadRequest:request];

            });

        });

推荐阅读更多精彩内容