iOS使用微信H5支付无法跳转回APP的问题

//监听webview代理方法,处理支付链接
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    
    WBLog(@"request.url = %@", [request URL]);
    
    //拦截未处理下单链接
    NSURL *url = [request URL];
    NSString *newUrl = url.absoluteString;
    if (!_hasLoading) {
        if ([newUrl rangeOfString:@"https://wx.tenpay.com"].location != NSNotFound) {
            NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url
                                                                   cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                               timeoutInterval:60.0];
            [_webView loadRequest:request];
            _hasLoading = YES;
            return NO;
        }
    }
    
    //设置referer
    NSDictionary *headers = [request allHTTPHeaderFields];
    BOOL hasReferer = [headers objectForKey:@"Referer"] != nil;
    if (hasReferer) {
        return YES;
    } else {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                NSURL *url = [request URL];
                NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url
                                                                   cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                               timeoutInterval:60.0];
                [req setHTTPMethod:@"GET"];
                [req setValue:@"beisu100.com://" forHTTPHeaderField: @"Referer"];
                WBLog(@"req === %@", req);
                [_webView loadRequest:req];
            });
        });
        return NO;
    }
}

 

你可能感兴趣的:(iOS)