好友
阅读权限10
听众
最后登录1970-1-1
|
var e = require("../@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.debounce = f, exports.request = a, exports.uploadFile = i;
var n = e(require("crypto-js")), t = require("./sha256"), o = require("./config"), r = 1;
function a(e, i, u) {
var f = e, d = i, l = u;
return new Promise(function(c, g) {
u || (u = {});
var p = JSON.parse(JSON.stringify(u));
p.organid = o.ORGANID, p.tokenType = 1, p.stadiumid = p.stadiumid || "" == p.stadiumid ? p.stadiumid : wx.getStorageSync("stadiumid");
var y = {
sign: function(e, r) {
var a = [], i = 0;
for (var s in e) a[i] = s, i++;
var u = a.sort(), f = "";
for (var d in u) u.hasOwnProperty(d) && -1 === u[d].indexOf("action") && -1 === u[d].indexOf("_noencry") && -1 === u[d].indexOf("_nosign") && (f += u[d] + "=" + e[u[d]] + "&");
f = r.indexOf("noToken") < 0 ? f + "token=" + wx.getStorageSync("token") + "&appkey=" + o.appkey : f + "appkey=" + o.appkey;
return f = (0, t.SHA256)(f).toUpperCase(), f = n.default.MD5(f).toString().toUpperCase();
}(function(e) {
for (var n in e) "token" !== n && "action" !== n && -1 === n.indexOf("_nosign") && -1 === n.indexOf("_noencry") && ("string" == typeof e[n] || "number" == typeof e[n] || "boolean" == typeof e[n] ? e[n] = s(e[n]) : e[n] = s(JSON.stringify(e[n])));
return e;
}(p), i),
token: wx.getStorageSync("token"),
"Content-Type": "application/x-www-form-urlencoded"
};
wx.request({
url: o.baseUrl + i,
method: e,
header: y,
data: p,
success: function(e) {
if (wx.hideLoading(), e.data.result && "false" !== e.data.result) c(e.data); else if (3 !== e.data.code && 2 !== e.data.code) if (4 === e.data.code) if (r < 3) {
r++;
var n = wx.getStorageSync("loginInfo"), t = {};
t.tokens = n.token, t.userid = n.userid, t.refresh_token = n.refresh_token, t.useriv = o.ivkey,
t.mq = !0, t.usermy = o.mftkey, t.userkey = n.username + "shanxi" + n.refresh_token + "taiyuan" + n.random,
wx.$api.refreshTokens(t).then(function(e) {
r = 1;
var n = wx.getStorageSync("loginInfo");
n.refresh_token = e.refresh_token, n.token = e.token, wx.setStorageSync("loginInfo", n),
wx.setStorageSync("token", e.token), a(f, d, l).then(function(e) {
c(e);
}).catch(function(e) {
wx.removeStorageSync("token"), wx.removeStorageSync("loginInfo"), wx.navigateTo({
url: "/pages/login/login"
});
});
}).catch(function(e) {});
} else wx.removeStorageSync("token"), wx.removeStorageSync("loginInfo"), wx.navigateTo({
url: "/pages/login/login"
}); else wx.showToast({
title: e.data.message,
icon: "none",
duration: 2e3
}), g(e); else wx.navigateTo({
url: "/pages/login/login"
});
},
fail: function(e) {
wx.hideLoading(), g(e), wx.showToast({
title: "服务器错误",
icon: "none",
duration: 2e3
});
}
});
});
}
function i(e, n, t) {
return console.log(n, t, "????????"), new Promise(function(e, r) {
wx.uploadFile({
url: o.baseUrl + n,
header: {
"Content-Type": "multipart/form-data"
},
name: "file",
filePath: t,
success: function(n) {
console.log(n, "result");
var t = JSON.parse(n.data);
-1 === t.status ? r(t) : e(t);
},
fail: function(e) {
console.log(e, "error");
var n = JSON.parse(e.data);
r(n);
}
});
});
}
function s(e) {
var t = n.default.enc.Utf8.parse(o.mftkey), r = n.default.enc.Utf8.parse(e);
return n.default.AES.encrypt(r, t, u).toString();
}
var u = {
iv: n.default.enc.Utf8.parse(o.ivkey),
mode: n.default.mode.CBC,
padding: n.default.pad.Pkcs7
};
function f(e) {
var n, t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 300;
return function(o) {
var r = this;
clearTimeout(n), n = setTimeout(function() {
e.call(r, o);
}, t);
};
}
module.exports = {
request: a,
uploadFile: i,
debounce: f
};
各位大神,这里面有段生成sign的代码,是怎么生成的sign呢?比如说是使用哪些数据来产生的sign?可以帮忙编写个脚本把我的特定数据生成sign吗? |
|