Swift H5 中 调起微信支付
2022-02-11 本文已影响0人
ZM_微笑向阳
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
}
}