现在讲讲怎么实现微信支付网页支付,也就是公众号支付:
1.判断支付平台,在判断是微信平台时,必须使用window.location打开网页,使用其他方法在IOS版微信无法打开网页,至少现在的新版微信无法打开。对应的连接是请求获取code的链接。第2步会讲到。
判断客户平台}
if(isWeiXin()){
window.location='http://www.xxoo.com/InterfaceAPI/code';
} else if(isZFB()){
alert('支付宝即将开放....');
//var p = document.getElementsByTagName('p'); //p[0].innerHTML = window.navigator.userAgent;
}else{
alert('请使用微信或者支付宝App扫码');
}
}
functionisWeiXin(){
varua =window.navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
return true;
}else{
return false;
}
}
functionisZFB(){
varua =window.navigator.userAgent.toLowerCase();
if(ua.match(/AlipayClient/i) =='alipayclient'){
return true;
}else{
return false;
}
}
2.这里是获取code,回调地址必须使用URLEncoder的utf-8编码,这里最终只获取openid,需要获取UserInfo其他信息的自行测试,只需要修改一下 scope 的参数,
@RequestMapping({ "code"})
public voidgetCode(HttpServletRequest request, HttpServletResponse response) {
try{
//回调地址
String redirect_uri =URLEncoder.encode(
"http://www.xxoo.com/InterfaceAPI