var obj = {}; //url地址参数
var deviceId = “”; //设备id
var visitorId = “”; //手机唯一id
var openId = “”; // 每个人唯一
url(); //获取地址栏后的参数
code(); //初始化页面信息
//获取url地址后的参数
function url() {
//首先获取到当前页面的地址栏信息
var url = window.location.href;
var reg = /?/;
if(url.match(reg)) {
var chars = url.split(’?’)[1];
var arr = chars.split(’&’);
for(var i = 0; i < arr.length; i++) {
var num = arr[i].indexOf("=");
if(num > 0) {
var name = arr[i].substring(0, num);
var value = arr[i].substr(num + 1);
obj[decodeURIComponent(name)] = decodeURIComponent(value);
}
}
}
}
alert('111')
////页面授权获取个人信息展示页面
function code() {
alert(JSON.stringify(obj));
if(obj.code != undefined) {
deviceId = obj.state
$.ajax({
url: 'http:*****************************login',
type: "post",
data: {
code: obj.code,
},
dataType: 'json', // 请求方式为json
xhrFields: {
withCredentials: true
},
/*jsonpCallback: "onBack", */ // 自定义回调函数名
/*contentType: 'application/json',
xhrFields:{
withCredentials:true
},
crossDomain: "true",*/
success: function(res) {
alert(res.code)
},
error: function(res) {
alert("请重新扫码");
// window.close();
}
});
} else {
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxee36e74647e26a00&redirect_uri=http%3A%2F%2Ffangcang.zhongchuang365.com%2FfangCang%2Findex.html&response_type=code&scope=snsapi_base&state=" + obj.deviceId + "#wechat_redirect";
// window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5cf1ee7841428150&redirect_uri=http%3a%2f%2f192.168.10.125%3a8020%2fVisitor%2Findex.html&response_type=code&scope=snsapi_base&state=" + obj.deviceId + "#wechat_redirect";
}
}