https://open.weixin.qq.com/connect/oauth2/authorize?appid=aaaaaaa&redirect_uri=http://www.xxx.com/GDsellers/?path=commission&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect
redirect_uri 跳转的链接中不能直接加#号。所以我们加了path参数
我是在main.js中获取code值然后传给后台的:
var urls = location.search; //获取url中"?"符后的字串
var theRequest: any = new Object();
if (urls.indexOf("?") != -1) {
var str = urls.substr(1);
let strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
if (theRequest.code) {
this.$store.state.wxCode = theRequest.code
console.log("code", theRequest.code)
}