关于微信支付redirect_uri中安卓和ios访问报错问题

问题描述:
在做微信JSAPI支付时,通过java调用微信接口获取授权信息并回调时,在程序中添加了redirect_uri地址,但是实测后发现,通过安卓手机可以成功进入回调页面,ios苹果手机显示网络异常。
java代码如下:

	@Override
	public String Authorize (String PatientId, String BillNo,String PatientName) throws Exception {
    
    
		// TODO Auto-generated method stub
		StringBuffer url = new StringBuffer();
		url.append("http://open.weixin.qq.com/connect/oauth2/authorize?");
		url.append("appid="+ qn_SysContants.yhConstantsmap.get("qn_AppID").toString());
		//?后参数需经过加密后进行传值
		url.append("&redirect_uri="+URLEncoder.encode ("http://"+ qn_SysContants.yhConstantsmap.get("IP").toString() +"/","UTF-8")+URLEncoder.encode("aggpay/lay/zf_wxcallback?","UTF-8")
				+URLEncoder.encode("&PatientName="+PatientName,"UTF-8")
			+URLEncoder.encode("&BillNo="+BillNo,"UTF-8")
			+URLEncoder.encode("&PatientId="+PatientId,"UTF-8"));
		url.append("&response_type=code&scope=snsapi_base&state=");//state参数是给传值的
	    url.append("#wechat_redirect");
	    return  url.toString();
	}

其中redirect_uri地址为:

http://xxxxxxxx/qn_aggpay/lay/zf_wxcallback?PatientId=5307&BillNo=4107209&PatientName=qqq

这里有两种解决办法

方法一:

对url拼接完成后,可以先跳转到一个html页进行处理,然后在html页进行windows.localtion.ref进行跳转,如1_OAuth.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>正在加载...</title>
<script type="text/javascript" src="js/params.js"></script>

<script language="javascript">
// 窗体载入执行
window.onload = function() {
    
    
   var gParams = {
    
    
		WxAppid:"wx7b79d0aa534a04f7",
		OAuth2RedirectUrl:"http://xxxxx/qn_aggpay/lay/zf_wxcallback?PatientId=5307&BillNo=4107209&PatientName=李军涛",
		tradeType:"123"
   } 
	
	// 腾讯OAuth2服务地址
	var wxurl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + gParams.WxAppid + "&redirect_uri=" + gParams.OAuth2RedirectUrl + "&response_type=code&scope=snsapi_base&state=" + gParams.tradeType + "#wechat_redirect";
	
	alert("访问:" + wxurl)
	location.replace(wxurl);
}
</script>
</head>

<body>

</body>
</html>

由html进行拼接授权的url,然后进行访问。

方法二

根据微信官网的定义,决定还是从原有程序入手。
这里看下微信官网对授权回调地址的做法:
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
在这里插入图片描述
需要对redirect_uri做urlEncode处理,之前的处理:
在这里插入图片描述
发现没有传encoding
修改后:
在这里插入图片描述
测试成功,两种系统手机均可以访问。

当然,前提时你在微信后台配置好了参数。如下所示:
在这里插入图片描述

在这里插入图片描述
不然会报10003的错误或者是微信支付台拉不来的问题。

猜你喜欢

转载自blog.csdn.net/weixin_40550118/article/details/107380168