The webview in the APP cannot pay using WeChat H5 payment, and cannot pay in the iframe

1. Question 1

If it is just a simple webview, Alipay and WeChat cannot be used, because the webview only recognizes http and https by default, and Alipay and WeChat use the scheme when calling the APP, so you need to set WebViewClient and re-apply shouldOverrideUrlLoading. The IOS processing method is the same

2. Question 2 

After webview opens the website, using iframe to call WeChat H5 payment fails to make payment

Approach:

WeChat H5 payment will obtain the WeChat link, through simulated access, to obtain the code of the WeChat payment interface, and then use regular expressions to obtain the payment address starting with weixin://, and directly request the address after obtaining it, or call the iframe parent through window.parent The JS method of the page is processed, and the PHP code is below

<?php
//$mweb_url 通过微信H5支付方法获取
$return =  http_curl_get($mweb_url);

$pat ='/url="weixin:\/\/(.*?)";/';
preg_match($pat, $return, $data);

//获取到weixin://开头支付地址,可将这个地址直接访问或者传给父级界面处理
$pay_url = 'weixin://'.$data[1]; 

function http_curl_get($url,$type=1) {
      $curl = curl_init();
      curl_setopt($curl,CURLOPT_TIMEOUT,5000);
      curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
      curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
      curl_setopt($curl,CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
      curl_setopt($curl,CURLOPT_URL,$url);
      curl_setopt($curl, CURLOPT_REFERER, 'https://授权页面');
        	
      if($type == 1){
        	curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
       }
       $res = curl_exec($curl);
       if($res){
        	curl_close($curl);
        	return $res;
       }else {
        	$error = curl_errno($curl);
        	curl_close($curl);
        	return $error;
       }
}
?>

The article only provides solutions, and the actual problems shall prevail.

Guess you like

Origin blog.csdn.net/qq_24138677/article/details/132121095