商家在网页中调用支付宝提供的网页支付接口调起支付宝客户端内的支付模块,商家网页会跳转到支付宝中完成支付,支付完后跳回到商家网页内,最后展示支付结果。若无法唤起支付宝客户端,则在一定的时间后会自动进入网页支付流程。
注意:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { // NOTE: ------ 对alipays:相关的scheme处理 ------- // NOTE: 若遇到支付宝相关scheme,则跳转到本地支付宝App NSString* reqUrl = request.URL.absoluteString; // NOTE: 跳转支付宝App BOOL bSucc = [[UIApplication sharedApplication]openURL:request.URL]; // NOTE: 如果跳转失败,则跳转itune下载支付宝App if (!bSucc) { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@ "提示" message:@ "未检测到支付宝客户端,请安装后重试。" delegate:self cancelButtonTitle:@ "立即安装" otherButtonTitles:nil]; [alert show]; } return NO; } return YES; } - ( void )alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // NOTE: 跳转itune下载支付宝App NSString* urlStr = @ "https://itunes.apple.com/cn/app/zhi-fu-bao-qian-bao-yu-e-bao/id333206289?mt=8" ; NSURL *downloadUrl = [NSURL URLWithString:urlStr]; [[UIApplication sharedApplication]openURL:downloadUrl]; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public boolean shouldOverrideUrlLoading( final WebView view, String url) { // 获取上下文, H5PayDemoActivity为当前页面 final Activity context = H5PayDemoActivity. this ; // ------ 对alipays:相关的scheme处理 ------- if (url.startsWith( "alipays:" ) || url.startsWith( "alipay" )) { try { context.startActivity( new Intent( "android.intent.action.VIEW" , Uri.parse(url))); } catch (Exception e) { new AlertDialog.Builder(context) .setMessage( "未检测到支付宝客户端,请安装后重试。" ) .setPositiveButton( "立即安装" , new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { context.startActivity( new Intent( "android.intent.action.VIEW" , alipayUrl)); } }).setNegativeButton( "取消" , null ).show(); } return true ; } // ------- 处理结束 ------- if (!(url.startsWith( "http" ) || url.startsWith( "https" ))) { return true ; } view.loadUrl(url); return true ; } |