美文网首页
iOS UIWebView 支付宝 h5支付 调起支付宝客户

iOS UIWebView 支付宝 h5支付 调起支付宝客户

作者: 巴拉拉能量 | 来源:发表于2018-01-25 16:33 被阅读1580次

公司用的支付宝H5支付,如果通过浏览器进入支付宝,会给人不安全的想法,所以我们要把手机网站转Native支付。

UIWebViewDelegate
self.webView.delegate=self;

//调用本接口对支付宝支付URL进行拦截和支付转化。
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType

 

    __weak CostViewController* wself = self;

    BOOLisIntercepted = [[AlipaySDKdefaultService]payInterceptorWithUrl:[request.URLabsoluteString]fromScheme:@"shizi"callback:^(NSDictionary*result) {

        // 处理支付结果

        NSLog(@"返回的的的的的d%@", result);

        // isProcessUrlPay 代表 支付宝已经处理该URL

        if([result[@"isProcessUrlPay"]boolValue]) {

            // returnUrl 代表 第三方App需要跳转的成功页URL

            NSString* urlStr = result[@"returnUrl"];

            [wselfloadWithUrlStr:urlStr];



        }

    }];

    if(isIntercepted) {

        returnNO;

}

    return YES;

}

- (void)loadWithUrlStr:(NSString*)urlStr

{

    if(urlStr.length>0) {

        dispatch_async(dispatch_get_main_queue(), ^{

            NSURLRequest*webRequest =[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]
                                                        cachePolicy:NSURLRequestReturnCacheDataElseLoad
                                                    timeoutInterval:10];

            [self.webViewloadRequest:webRequest];

        });

    }

}

相关文章

网友评论

      本文标题:iOS UIWebView 支付宝 h5支付 调起支付宝客户

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