<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>
原文地址:https://www.cnblogs.com/yangshousheng/p/9946083.html