God help me to see why this cannot be entered into the success function all the time. It has been alert (login failure), and it is circular. Because it cannot enter the success, it cannot save cookie, so it has been redirected and crashed
.let bind = Cookies.get("ptoken")
if (bind == undefined) {
location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd36b3798a2beb820&redirect_uri=http://testwechat.hotol.cn/dak/index.html&response_type=code&scope=snsapi_userinfo&state=1-sharpwechat_redirect";
let json = {
code:"001WYYaG1ffLF1038WdG1c81bG1WYYaa"
};
let url = location.hostname;
wx_login(json,function (res) {
console.log(res);
location.href = "http://" + url + "/dak/";
})
function wx_login(data, completion) {
let time = Date.parse(new Date());
let hash = hex_md5(time + "XXX");
$.ajax({
type: "post",
url: "192.168.18.85:8080/weChatUserLogin",
data: JSON.stringify(data),
async: false,
dataType: "text",
headers: {
"token": "",
"version": "1",
"client_type": "3",
"Timestamp": time,
"SignInfo": hash,
"Access-Control-Allow-Origin": "*",
},
contentType: "application/json;charset=UTF-8",
success: function (res) {
res = JSON.parse(res);
Cookies.set("ptoken","wwwww");
console.log(res);
if (res.code == 0) { //
console.log(res);
} else {
console.log(res.message);
}
},
error: function () {
alert("");
}
})
}
}