回调网址问题
注意:回调的网址需要编码 并且要在公众号进行配置
componentDidMount(){
var reg = new RegExp("(^|&)"+ "code" +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
console.log(r)
if(r==null){
location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid='+"wx5ac9c5301cbced7b"+'&redirect_uri='+CALLBACK_URL+'&response_type=code&scope=snsapi_userinfo&state='+""+'#wechat_redirect';
}else{
this.goLogin()
}
}
获取用户信息
var reg = new RegExp("(^|&)"+ "code" +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
传code给后台 后台拿到取openid与token就可以拿到信息 再传回前端。后端需要配置 解决中文乱码问题