判断是否是微信客户端的访问



public void testMethod1(){
ActionContext actx = ActionContext.getContext();  
HttpServletRequest request = (HttpServletRequest) actx.get(ServletActionContext.HTTP_REQUEST);  
HttpSession session= request.getSession();    
String userAgent = request.getHeader( "USER-AGENT" ).toLowerCase();      
if( userAgent ==null){      
userAgent = "";      
}   
 
System.out.println("userAgent="+userAgent);
if(userAgent.indexOf("micromessenger")==-1){
System.out.println("普通浏览器");
}else{
System.out.println("来自微信客户端");
}
//网页版微信客户端:mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/39.0.2171.95 safari/537.36 micromessenger/6.5.2.501 nettype/wifi win dowswechat
//安卓:                          mozilla/5.0 (linux; u; android 4.4.2; zh-cn; che2-tl00 build/honorche2-tl00) applewebkit/533.1 (khtml, like gecko)version/4.0 mqqbrowser/5.4 tbs/025491 mobile safari/533.1 micromessenger/6.3.15.49_r8aff805.760 nettype/wifi language/zh_cn
//IOS        mozilla/5.0 (iphone; cpu iphone os 9_3_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko) mobile/13e238 micromessenger/6.3.15 nettype/wifi language/zh_cn 
//google浏览器   mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/39.0.2171.99 safari/537.36
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值