iOS app WebView微信H5支付,跳浏览器问题

如题所述

第1个回答  2022-07-24
因为微信H5 支付有个redirect_url = “”;当这个值带有http 的时候支付完成或者取消支付的时候,返回都打开了浏览器。

解决:1.可以修改 redirect_url 的值,修改成跳入自己app的scheme。

            2.如果无法修改 redirect_url 的话,只能在webView 加载时拦截连接进行替换。注意一点:自己app Scheme地址得和H5支付填写的域名保持一致。

如下:

if ([scheme hasPrefix:@"https://wx.tenpay.com/"] && ![scheme hasSuffix:[NSString stringWithFormat:@"redirect_url=自己appscheme://"]]) {

            decisionHandler(WKNavigationActionPolicyCancel);            NSString*redirectUrl =nil;

            if([schemecontainsString:@"redirect_url="]) {

                NSRangeredirectRange = [schemerangeOfString:@"redirect_url"];

                redirectUrl = [[schemesubstringToIndex:redirectRange.location]stringByAppendingString:[NSStringstringWithFormat:@"自己appscheme://"]];

            }else{

                redirectUrl = [schemestringByAppendingString:[NSStringstringWithFormat:@"自己appscheme://"]];

            }

            NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:redirectUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];

            newRequest.allHTTPHeaderFields= navigationAction.request.allHTTPHeaderFields;

            newRequest.URL= [NSURLURLWithString:redirectUrl];

            [webViewloadRequest:newRequest];

            return;

        }

如果返回app还得加载成功H5页面成功页面的话,可以保存或者拿到成功页面地址,进入app进行第二次加载。
相似回答