微信网页授权获取code

<script>
(function(){
var code = GetQueryString(‘code‘);

if(code){
alert(code)
return false;

}else{
shouquan();
}

function shouquan(){
var redirect_uri = window.location.origin + window.location.pathname;
console.log(redirect_uri)

var appId = "wx70c81e11981cab3d";
var wx_link = ‘https://open.weixin.qq.com/connect/oauth2/authorize?appid=‘ + appId + ‘&redirect_uri=‘ +
redirect_uri + ‘&response_type=code&scope=snsapi_base#wechat_redirect‘;
console.log(1)
window.location.href = wx_link;
code = GetQueryString(‘code‘);
}


function GetQueryString(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return unescape(r[2]); return null;

}
})()

</script>

微信网页授权获取code

微信网页授权获取code

上一篇:判断浏览器是否为微信浏览器


下一篇:总想自己动动手系列·3·如何让微信公众号和外网服务交互之通过TOKEN验证(准备篇·1)