下面一段代码给大家介绍java判断浏览器是微信还是支付宝,具体代码如下所示:
1
2
3
4
5
6
7
8
9
10
11
|
@RequestMapping ( "getBrowser.do" )
public String getBrowser(HttpServletRequest req, HttpServletResponse resp) {
String userAgent = req.getHeader( "user-agent" );
if (userAgent != null && userAgent.contains( "AlipayClient" )) {
return "来自支付宝" ;
} else if (userAgent != null && userAgent.contains( "MicroMessenger" )) {
return "来自微信" ;
} else {
return "未知来源" ;
}
}
|
补充:下面看下js识别微信支付宝浏览器(移动端)
1
2
3
4
5
6
7
8
|
//判断是支付宝app的浏览器
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.match(/Alipay/i)== "alipay" ){
return true ;
} else {
return false ;
}
|
1
2
3
4
5
6
7
8
9
|
//判断是微信app的浏览器
function isWechat(){
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.match(/MicroMessenger/i)== "micromessenger" ) {
return true ;
} else {
return false ;
}
}
|
原文链接:https://blog.csdn.net/qq_25646191/article/details/80566425