美文网首页
Swift H5 中 调起微信支付

Swift H5 中 调起微信支付

作者: ZM_微笑向阳 | 来源:发表于2022-02-11 16:59 被阅读0次
       func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        
        print("scheme -------------- :\(navigationAction.request.url?.scheme)")
        print("schemeurl -------------- :\(navigationAction.request.url)")
        
        //获取当前的url
        let curUrl = navigationAction.request.url
        let newcUrUrl =  curUrl?.absoluteString ?? ""
        // 去除原有的URL回调地址,换成自己的配置
        if (newcUrUrl.hasPrefix("https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb")) {
            
            let dic = navigationAction.request.allHTTPHeaderFields
            let refer = dic?["Referer"] ?? ""
            if refer != "dev.maas.chelaile.net.cn://"{
    
                decisionHandler(WKNavigationActionPolicy.cancel)
    
                //对微信的url 进行处理 拼接 App 的标识
                var lastURL = curUrl?.absoluteString ?? ""                
                let req = NSMutableURLRequest(url: URL(string: lastURL)!)
                req.httpMethod = "GET"
                req.setValue("dev.maas.chelaile.net.cn://", forHTTPHeaderField: "Referer")
                self._webView?.load(req as URLRequest)
                
                return;
            }
            decisionHandler(WKNavigationActionPolicy.allow)
        }else{
            decisionHandler(WKNavigationActionPolicy.allow)
        }
       
        if navigationAction.request.url?.scheme == "tel" {
            //吊起拨打电话
            UIApplication.shared.openURL(navigationAction.request.url!);
            decisionHandler(WKNavigationActionPolicy.cancel)
        }
        
        let scheme = navigationAction.request.url?.scheme ?? ""
        if (scheme != "https" && scheme != "http") {
            if scheme == "weixin" {
                //调用微信
                UIApplication.shared.open(navigationAction.request.url!, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly:false]) { flag in }
                return
            }
            return
        }
    }
    

    相关文章

      网友评论

          本文标题:Swift H5 中 调起微信支付

          本文链接:https://www.haomeiwen.com/subject/infzkrtx.html