通过user-agent判断用户是用QQ、微信还是支付宝打开链接或二维码
function is_weixn_qq(){
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
return "weixin";
} else if (ua.match(/QQ/i) == "qq") {
return "QQ";
}else if(ua.match(/AlipayClient/i) == 'alipayclient'){
return "Alipay";
}else{
...
}
后台代码中判断请求来源
//从httpServerletRequest中获得user-agent
String userAgent = req.getHeader("user-agent");
if (userAgent != null && userAgent.contains("AlipayClient")) {
return "支付宝";
}else if (userAgent != null && userAgent.contains("MicroMessenger")) {
return "微信";
}else{
return "其它";
}