Commit ab2e936b authored by 罗超's avatar 罗超

新增获取OPENID

parent 53e31ce8
...@@ -194,25 +194,10 @@ ...@@ -194,25 +194,10 @@
if (platform == 'H5' && ua.match(/MicroMessenger/i) != "micromessenger") { if (platform == 'H5' && ua.match(/MicroMessenger/i) != "micromessenger") {
$('.wx_bg').css('display', "block"); $('.wx_bg').css('display', "block");
} else if (platform == 'H5' && !userInfo.openid && window.location.href.indexOf('?') == -1) { } else if (platform == 'H5') {
let reu = encodeURIComponent(window.location.href); this.initOpenid()
location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx44c35529819fc345&redirect_uri=${reu}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
} else if (platform == 'H5' && !userInfo.openid && window.location.href.indexOf('code') != -1) {
let codes = href.split('?')[1].split("&");
let url_openid = `https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx44c35529819fc345&secret=2af0d735ab66341bec6c96d97bca2e4e&code=${codes[0].split("=")[1]}&grant_type=authorization_code`
$.getJSON("http://query.yahooapis.com/v1/public/yql", {
q: `select * from json where url="${url_openid}"`,
format: "json"
}, function(data) {
console.log(data)
if (data.query.results) {
console.log(data)
} else {
//$content.text('no such code: ' + code);
}
});
} }
var end = ''; var end = '';
var currentTime = ''; var currentTime = '';
localStorage.userInfo = JSON.stringify(userInfo) localStorage.userInfo = JSON.stringify(userInfo)
...@@ -236,10 +221,6 @@ ...@@ -236,10 +221,6 @@
$('.use_o').html(res.data.contact); $('.use_o').html(res.data.contact);
$('.use_t').html(res.data.customerName); $('.use_t').html(res.data.customerName);
$('.dataStatistics').dataStatistics({ $('.dataStatistics').dataStatistics({
max: num, max: num,
min: num, min: num,
...@@ -451,7 +432,29 @@ ...@@ -451,7 +432,29 @@
} }
function initOpenid() {
if (!localStorage.openid && window.location.href.indexOf('?') == -1) {
let reu = encodeURIComponent(window.location.href);
location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx44c35529819fc345&redirect_uri=${reu}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
} else if (!localStorage.openid && window.location.href.indexOf('code') != -1) {
let codes = href.split('?')[1].split("&");
let url_openid = `https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx44c35529819fc345&secret=2af0d735ab66341bec6c96d97bca2e4e&code=${codes[0].split("=")[1]}&grant_type=authorization_code`
url_openid = encodeURIComponent(url_openid);
$.ajax({
type: "GET",
url: 'http://reborn.oytour.com/api/test/GetHtmlByUrl?urlStr=' + url_openid,
async: false,
success: function(res) {
if (res) {
let r = JSON.parse(res);
if (r.openid) {
localStorage.openid = r.openid
}
}
}
});
}
}
$('.c_close').click(function() { $('.c_close').click(function() {
$('#notice').css('display', "none"); $('#notice').css('display', "none");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment