微信静默授权

Posted 前段入门菜鸟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信静默授权相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        if (isWeiXin()) {
            const APPID = ‘wx1d5f44‘
            const code  = getQueryStringByName(‘code‘)
            console.log(code)
            const local = ‘https%3A%2F%2Fm.jdy.como‘
            if (code === null || code === ‘‘) {
                window.location = ‘ https://open.weixin.qq.com/connect/oauth2/authorize?appid=‘ + APPID + ‘&redirect_uri=‘ + encodeURIComponent(local) + ‘&response_type=code&scope=snsapi_base&state=123#wechat_redirect‘
            } else {
                this.getOpenId(code)
            }
            function getQueryStringByName(name){
              var result = location.hash.match(new RegExp("[?&]" + name + "=([^&]+)","i"));
              if(result == null || result.length < 1){
                return "";
              }
              return result[1];
            }
        } else {
        }
         // 判断是不是微信
        function isWeiXin(){
          var ua = window.navigator.userAgent.toLowerCase();
          if(ua.match(/MicroMessenger/i) == ‘micromessenger‘){
          return true;
          }else{
          return false;
          }
        }
    </script>
</body>
</html>

  

以上是关于微信静默授权的主要内容,如果未能解决你的问题,请参考以下文章

微信公众号开发 - 静默授权获取用户信息

微信第三方登录与静默授权和非静默授权

微信第三方登录(静默授权和非静默授权)

微信静默授权问题

网站微信静默授权流程

React H5 项目 微信授权登录 /静默登录