微信公衆號授權登錄

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";
				}
			}
發佈了18 篇原創文章 · 獲贊 4 · 訪問量 2174
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章