H5获取微信网页授权


//判断是否微信浏览器
isWeiXin: function(){
    let ua = window.navigator.userAgent.toLowerCase();
  return ua.match(/MicroMessenger/i) == "micromessenger";
},
 
//微信授权
weixin(){
if(Util.isWeiXin()){
//在微信中打开
  let banklink = encodeURIComponent(window.location.href);//提交时,网页中

  let link = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx70568d6c7bdeaa58&redirect_uri=' + banklink + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';//测试
 
  window.location.href = link;
}
},
 
//生命周期里的获取code方法
let that=this;
that.code_weixin= Util.UrlSearch('code');
if(that.code_weixin){                  //(如果有这个code则执行下面的)
  localStorage.setItem('code_weixin',that.code_weixin);       //(储存code)
  that.registerForWechatUserByH5({appType:'H5',code:that.code_weixin});      //方法调接口1
    axios.post('/接口地址/',{appType:'H5',code:codeWeixin传参        //直接调用接口2
}).then(()=>{});
}else{
  that.weixin();              //(如果没有就执行上面的微信授权方法)
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM