1. 程式人生 > >Java判斷瀏覽器是微信還是支付寶

Java判斷瀏覽器是微信還是支付寶

null 瀏覽器 bsp ins .get nbsp color else agent

 1     private static final String WX_AGENT = "micromessenger";
 2     private static final String ALI_AGENT = "alipay";
 3 
 4 
 5     public String getBrowser(HttpServletRequest request) {
 6         String agent = request.getHeader("User-Agent").toLowerCase();
 7         if(agent!=null) {
 8             if
(agent.toLowerCase().contains(WX_AGENT)) { 9 return "來自微信"; 10 } else if (agent.toLowerCase().contains(ALI_AGENT)) { 11 return "來自支付寶"; 12 } 13 } 14 return "來自未知星球"; 15 }

Java判斷瀏覽器是微信還是支付寶