码迷,mamicode.com
首页 > 微信 > 详细

微信网页授权获取code

时间:2018-11-12 14:57:44      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:alert   lin   ima   OAuth2   ppi   sns   OLE   new   author   

<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

标签:alert   lin   ima   OAuth2   ppi   sns   OLE   new   author   

原文地址:https://www.cnblogs.com/yangshousheng/p/9946083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!