微信公衆號使用隱藏頁判斷登錄

<script type="text/javascript">
   $(document).ready(function(){
      document.getElementById("over").style.display = "block";
      document.getElementById("layout").style.display = "block";
      //判斷是否之前走過授權
      // var token = window.localStorage.getItem('token');
      // if(token){
      //     window.location.href='http://zhibo.cnewhl.com/pages/common/supplyHall.html '
      // }
      var urlStr = window.location.href;
      function GetRequest(urlStr) {
         if (typeof urlStr == "undefined") {
            var url = decodeURI(location.search); //獲取url中"?"符後的字符串
         } else {
            var url = "?" + urlStr.split("?")[1];
         }
         var theRequest = new Object();
         if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
               theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
            }
         }
         return theRequest;
      }

var parms_1 = GetRequest();
      var type = parms_1['type'];
      if (type){
         window.localStorage.setItem('type', type);
      }
      //判斷是否之前走過授權
      // var token = window.localStorage.getItem('token');
      // if(token && window.localStorage.getItem('type') == 1){
      //     window.location.href='http://zhibo.cnewhl.com/pages/common/supplyHall.html '
      // }
      var oror = parms_1['code'];
      if (oror){
         mui.ajax(site_url + 'login', {
            data: {
               code: oror
            },
            dataType: 'json', //服務器返回json格式數據
            type: 'post', //HTTP請求類型
            success: function(data) {
               window.localStorage.setItem('token', data.data.token);
               if (data.data.user.phone != null) {
                  var types = window.localStorage.getItem('type');
                  if(types == 1){
                     // window.close();
                     window.location.href = '../common/supplyHall.html';
                     // window.close();
                  }else {
                     window.location.href = '../common/person.html';
                  }
               } else {
                  window.location.href = '../person/bindMobile.html'
               }
            },
            error: function(xhr, type, errorThrown) {
               //alert(123)
            }
         });
      }else {
         window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx819031dbf71618be&redirect_uri=http://zhibo.cnewhl.com/pages/common/login.html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
      }
      //$('#login').click(function(){
         // var token = window.localStorage.getItem('token');
         // // alert(token)
         // if(token){
         //     window.location.href='http://zhibo.cnewhl.com/pages/common/supplyHall.html '
         //     return
         // }
         // window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx819031dbf71618be&redirect_uri=http://zhibo.cnewhl.com/pages/person/bindMobile.html&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect '
      //})
   })
</script>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章