vue 获取微信授权成功code值
var script1 = document.createElement("script");script1.type = "text/javascript";script1.src = "http://res.wx.qq.com/open/js/jweixin-1.2.0.js";document.body.appendChild(sc
·
var script1 = document.createElement("script");
script1.type = "text/javascript";
script1.src = "http://res.wx.qq.com/open/js/jweixin-1.2.0.js";
document.body.appendChild(script1);
let ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
if(window.location.search.indexOf('code')<0){
window.location.href ='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx269c8f3e5d0ed1c6&redirect_uri='+encodeURIComponent(location.href)+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
}else if(window.location.search.indexOf('code')>-1){
localStorage.setItem('wechatcode',this.getQueryString('code'))
}
}
下面这段代码要注意,appid与redirect_uri值需要特殊值 ,redirect_uri是白名单
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx269c8f3e5d0ed1c6&redirect_uri='+encodeURIComponent(location.href)+'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
更多推荐
已为社区贡献6条内容
所有评论(0)