OC HTML5 跳转 微信支付(WKWebView)

- (void)webView:(WKWebView*)webView decidePolicyForNavigationAction:(WKNavigationAction*)navigationAction decisionHandler:(void(^)(WKNavigationActionPolicy))decisionHandler

{


    NSURLRequest*request  = navigationAction.request;

    NSString    *scheme  = [request.URLscheme];

    NSURL*curUrl = navigationAction.request.URL;

    NSLog(@"%@",navigationAction.request.URL.absoluteString);

    NSString    *url = [navigationAction.request.URL.absoluteStringstringByRemovingPercentEncoding];

    NSLog(@"%@",url);

    NSLog(@"%@",scheme);

    NSString *wxpayScheme = @"fuanwap.ulmsale.com://";

    NSString*endPayRedirectURL =nil;


    // 去除原有的URL回调地址,换成自己的配置

    if ([curUrl.absoluteString hasPrefix:@"https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb"]) {


        if(![curUrl.absoluteStringcontainsString:@"redirect_url"]) {

            decisionHandler (WKNavigationActionPolicyCancel);

            NSString*lastURL = curUrl.absoluteString;

            NSString*lastURL2 = [lastURLstringByAppendingString:[NSStringstringWithFormat:@"&redirect_url=%@",wxpayScheme]];

            NSLog(@"%@",lastURL2);

            endPayRedirectURL = lastURL2;

            NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:lastURL2]];

            [reqsetValue:@"http://fuanwap.ulmsale.com" forHTTPHeaderField:@"Referer"];

            [webViewloadRequest:req];

            return;

        }

        decisionHandler (WKNavigationActionPolicyAllow);

        return;


    }


    if(![schemeisEqualToString:@"https"] && ![schemeisEqualToString:@"http"]) {

        decisionHandler(WKNavigationActionPolicyCancel);

        if([schemeisEqualToString:@"weixin"]) {

            if(endPayRedirectURL) {

                [webViewloadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:endPayRedirectURL] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30]];

            }

        }else if ([scheme isEqualToString:[NSString stringWithFormat:@"weixin://wap/pay?prepayid"]]) {


        }


        BOOLcanOpen = [[UIApplicationsharedApplication]canOpenURL:request.URL];

        if(canOpen) {

            [[UIApplicationsharedApplication]openURL:request.URL];

        }else{

            [SVProgressHUD showInfoWithStatus:@"未安装相关应用"];

        }

        return;

    }



    decisionHandler (WKNavigationActionPolicyAllow);

    return;


}

你可能感兴趣的:(OC HTML5 跳转 微信支付(WKWebView))