如何在服务器端判断请求的客户端是微信调用的浏览器

2024-11-08 08:45:01
推荐回答(1个)
回答1:

// JAVA
request.getHeader("user-agent")

String ua = ((HttpServletRequest) request).getHeader("user-agent").toLowerCase();
if (ua.indexOf("micromessenger") > 0) {// 是微信浏览器
validation = true;
}

// C#
string ua = HttpContext.Current.Request.UserAgent.ToLower();
return ua.Contains("micromessenger");

// PHP
$user_agent = $_SERVER['HTTP_USER_AGENT'];
return strpos($user_agent, 'MicroMessenger');

// javascript
var ua = window.navigator.userAgent.toLowerCase();
return ua.match(/MicroMessenger/i) == "micromessenger";