|
@@ -1,6 +1,7 @@
|
|
//网关对应地址
|
|
//网关对应地址
|
|
-var api = "http://gateway.js-dctech.com/api/";
|
|
|
|
|
|
+// var api = "http://gateway.js-dctech.com/api/";
|
|
// var api = "http://192.168.2.35:8080/api/";
|
|
// var api = "http://192.168.2.35:8080/api/";
|
|
|
|
+var api = "http://192.168.2.40:8080/api/";
|
|
|
|
|
|
//批次号
|
|
//批次号
|
|
var batch = getUrlParam("batch");
|
|
var batch = getUrlParam("batch");
|
|
@@ -17,20 +18,27 @@ var currentUrl = location.href.split('#')[0];
|
|
//缓存中的accessToken
|
|
//缓存中的accessToken
|
|
var accessToken = localStorage.getItem("access_token") || "";
|
|
var accessToken = localStorage.getItem("access_token") || "";
|
|
|
|
|
|
|
|
+//微信重定向后添加的code参数
|
|
|
|
+var oauthCode = getUrlParam("code");
|
|
|
|
+
|
|
|
|
+//调用微信鉴权方法
|
|
|
|
+redirectNoCodeUrl();
|
|
|
|
+
|
|
//封装ajax请求,自动在请求头中加入access_token
|
|
//封装ajax请求,自动在请求头中加入access_token
|
|
jQuery.extend({
|
|
jQuery.extend({
|
|
authAjax: function (options) {
|
|
authAjax: function (options) {
|
|
-
|
|
|
|
- if (accessToken == "" && (typeof(options.data) == "undefined" || options.data.oauthCode == null)) {
|
|
|
|
- alert("accessToken失效,请重新扫码");
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
var data = options.data || {};
|
|
var data = options.data || {};
|
|
data.batch = batch;
|
|
data.batch = batch;
|
|
data.columnSort = columnSort;
|
|
data.columnSort = columnSort;
|
|
data.qrCode = qrCode;
|
|
data.qrCode = qrCode;
|
|
|
|
|
|
|
|
+ //如果accessToken失效,重新发起静默授权
|
|
|
|
+ if (accessToken == "" && (typeof(options.data) == "undefined" || options.data.oauthCode == null)) {
|
|
|
|
+ data.redirectUrl = currentUrl.split('?')[0];
|
|
|
|
+ redirectAuthUrl(data);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
options.data = data;
|
|
options.data = data;
|
|
|
|
|
|
return $.ajax($.extend({
|
|
return $.ajax($.extend({
|
|
@@ -39,6 +47,37 @@ jQuery.extend({
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+//如果oauthCode不为空,进行微信用户鉴权,并重定向回不含code参数的地址
|
|
|
|
+function redirectNoCodeUrl() {
|
|
|
|
+ if (oauthCode != null) {
|
|
|
|
+ $.ajax({
|
|
|
|
+ url: api+"marketing/internal/redirectNoCodeUrl",
|
|
|
|
+ data: {
|
|
|
|
+ batch: batch,
|
|
|
|
+ columnSort: columnSort,
|
|
|
|
+ qrCode: qrCode,
|
|
|
|
+ redirectUrl: currentUrl.split('?')[0],
|
|
|
|
+ oauthCode: oauthCode
|
|
|
|
+ },
|
|
|
|
+ success: function (res) {
|
|
|
|
+ localStorage.setItem("access_token", res.data.access_token);
|
|
|
|
+ location.href = res.data.redictUrl;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//重定向到微信静默授权地址
|
|
|
|
+function redirectAuthUrl(data) {
|
|
|
|
+ $.ajax({
|
|
|
|
+ url: api+"marketing/internal/redirectAuthUrl",
|
|
|
|
+ data: data,
|
|
|
|
+ success: function (res) {
|
|
|
|
+ location.href = res;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
//获取url中的参数
|
|
//获取url中的参数
|
|
function getUrlParam(name) {
|
|
function getUrlParam(name) {
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
|
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
|
|
@@ -97,19 +136,18 @@ function getLocation(successFun, cancelFun) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-//回首页
|
|
|
|
-function hrefIndex() {
|
|
|
|
|
|
+//回活动首页
|
|
|
|
+function redirectActivityIndex() {
|
|
$.authAjax({
|
|
$.authAjax({
|
|
- url: api+"marketing/weixin/redirectUrl",
|
|
|
|
|
|
+ url: api+"marketing/internal/redirectActivityIndex",
|
|
async: false,
|
|
async: false,
|
|
success: function (res) {
|
|
success: function (res) {
|
|
location.href = res;
|
|
location.href = res;
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- // location.href = api+"marketing/weixin/redirectAuthUrl?batch="+batch+"&columnSort="+columnSort+"&qrCode="+qrCode;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-//拼接url
|
|
|
|
|
|
+//拼接含必需参数的url
|
|
function spliceUrl(url) {
|
|
function spliceUrl(url) {
|
|
return url + "batch="+batch+"&columnSort="+columnSort+"&qrCode="+qrCode;
|
|
return url + "batch="+batch+"&columnSort="+columnSort+"&qrCode="+qrCode;
|
|
}
|
|
}
|