iOS 通过URL打开支付宝

 self.url = @"https://qr.alipay.com/bax06385q32ssucugqxm00f1";
 NSURL *alipayURL = [NSURL URLWithString:self.url];
   
 [[UIApplication sharedApplication] openURL:alipayURL options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:^(BOOL success) {
        NSLog(@"");
    }];

原因:

 self.url = @"https://qr.alipay.com/bax06385q32ssucugqxm00f1";
上面的url解析得到如下:
        //https://ds.alipay.com/?from=mobilecodec&scheme=alipays://platformapi/startapp?saId=10000007&clientVersion=3.7.0.0718&qrcode=https%253A%252F%252Fqr.alipay.com%252Fbax041244dd0qf8n6ras805b%253F_s%253Dweb-other

如同下面跳转代码

- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
    //返回支付宝的信息字符串,alipays:// 以后的为支付信息,这个信息后台是经过 URLEncode 后的,前端需要进行解码后才能跳转支付宝支付(坑点)
      if ([urlStr containsString:@"alipays://"]) {
            NSRange range = [urlStr rangeOfString:@"alipays://"]; //截取的字符串起始位置
            NSString * resultStr = [urlStr substringFromIndex:range.location]; //截取字符串
            
            NSURL *alipayURL = [NSURL URLWithString:resultStr];
            
            [[UIApplication sharedApplication] openURL:alipayURL options:@{UIApplicationOpenURLOptionUniversalLinksOnly: @NO} completionHandler:^(BOOL success) {
                
            }];
        }
        WKNavigationResponsePolicy actionPolicy = WKNavigationResponsePolicyAllow;
        //这句是必须加上的,不然会异常
        decisionHandler(actionPolicy);
    
}


通过 alipays:// 进行了打开支付宝app。

下面设置未必要


image.png

你可能感兴趣的:(iOS 通过URL打开支付宝)