如何判断微信内置浏览器(JS & .Net)

    xiaoxiao2021-04-14  94

    微信内置浏览器的 User Agent

    如何判断微信内置浏览器,首先需要获取微信内置浏览器的User Agent,经过在 iPhone 上微信的浏览器的检测,它的 User Agent 是:

    Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329 MicroMessenger/5.0.1

    所以通过识别 MicroMessenger 这个关键字来确定是否微信内置的浏览器了。

    通过 JavaScript 判断

    function is_weixin(){ var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)=="micromessenger") { return true; } else { return false; } }

    通过 .Net

    /// <summary> /// 判断是否是微信客户端 /// </summary> /// <returns></returns> public static bool IsWechat() { string param = req.ServerVariables["HTTP_USER_AGENT"]; if (string.IsNullOrEmpty(param) == false) { return param.ToLower().Contains("MicroMessenger".ToLower()); } return false; } private static HttpRequest req { get { if (HttpContext.Current != null) return HttpContext.Current.Request; return null; } }

    通过 PHP 判断

    function is_weixin(){ if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) { return true; } return false; } 更多: 微信 js-sdk 界面操作接口使用 微信js-sdk 地理位置接口实例 微信js-sdk,分享接口常用逻辑分装
    转载请注明原文地址: https://ju.6miu.com/read-670266.html

    最新回复(0)