公众号

var wx_login = {//微信登录

base_url: 'http://xxx.com',
init:function(){
  var code = public_fun.getUrlParms('code');//获取地址栏参数判断是否已经授权
  code ? this.login(code) : this.getAuthorization();
  console.log(code)
},
getAuthorization: function() { //获取授权

  var current_url =window.location.href;
  var dir_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxxx&redirect_uri='+current_url+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
  location.href = dir_url;

},
login: function(code) { //登录
  var code = code;
  Vue.http({
    method: 'POST',
    url: this.base_url + '/auth/wxlogin.do',
    params: {
      code: code
    },
  headers: {
    "X-Requested-With": "XMLHttpRequest"
  },
  emulateJSON: true
  }).then(function(res) {
    console.log(res)
    var res = JSON.parse(res.bodyText),
    _url = sessionStorage.getItem('entry');
    location.href = _url;
    //登录成功,跳往已存储网页,每个页面都能过期,所以在后台返回过期状态码下存储网页
      Vue.$toast(res.msg);
    }).catch(function(error) {
      console.log(error);
    });
  }
}

posted @ 2018-08-09 18:09  树叶————  阅读(138)  评论(0编辑  收藏  举报