<!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>

  

posted on 2019-03-01 18:09  前端入门菜鸟  阅读(526)  评论(0编辑  收藏  举报