Home  >  Article  >  Backend Development  >  javascript - 大家好,微信支付判断是否为微信浏览器,上全部代码。

javascript - 大家好,微信支付判断是否为微信浏览器,上全部代码。

WBOY
WBOYOriginal
2016-06-06 20:36:501151browse

需求是这样的用户在微信中打开就采用微信支付,非微信浏览器就是支付宝支付,我用下面的方法是否靠谱呢??

if(typeof(WeixinJSBridge)!='undefined' && WeixinJSBridge)
{
alert('微信浏览器');

}
else
{
alert('普通浏览器');

}

回复内容:

需求是这样的用户在微信中打开就采用微信支付,非微信浏览器就是支付宝支付,我用下面的方法是否靠谱呢??

if(typeof(WeixinJSBridge)!='undefined' && WeixinJSBridge)
{
alert('微信浏览器');

}
else
{
alert('普通浏览器');

}

UA可以伪造模拟,要想真的实现限制在微信浏览器中,
可以用微信sdk的oauth的静默获取用户,如果获取到用户的openid就肯定是微信浏览器中打开的,否则就是其他浏览器。

根据UA来判断,不过支付方式应该让用户自己选择,而不是自动判断。

判断是否在微信浏览器打开
function is_weixn(){
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
return true;
} else {
return false;
}
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn