微信公众号禁止浏览器打开

js端限制:

var agent = navigator.userAgent.toLowerCase();
var isWeixin = agent.indexOf('micromessenger') != -1;
if (!isWeixin) {
    window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=888"
}

java:pc端限制

/** 
  检查访问方式是否为移动端 
  @Title: check 
  @Date : 2019-9-7 下午04:15:33 
  @param request 
    @param response
  @throws IOException  
 */  
public boolean check(HttpServletRequest request,HttpServletResponse response) throws IOException{  
    boolean isFromMobile=false;  
      
    HttpSession session= request.getSession();  
   //检查是否已经记录访问方式(移动端或pc端)  
    if(null==session.getAttribute("agent")){  
        try{  
            //获取ua,用来判断是否为移动端访问  
            String userAgent = request.getHeader( "USER-AGENT" ).toLowerCase();    
            if(null == userAgent){    
                userAgent = "";    
            }  
            isFromMobile=CheckMobile.check(userAgent);  
            //判断是否为移动端访问  
            if(isFromMobile){  
                System.out.println("移动端访问");  
                session.setAttribute("agent","mobile");  
            } else {  
                System.out.println("pc端访问");  
                session.setAttribute("agent","pc");  
            }  
        }catch(Exception e){}  
    }else{  
        isFromMobile=session.getAttribute("agent").equals("mobile");  
    }  
      
    return isFromMobile;  
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值