需要重新构架makeSign,但是源程序看不懂,求助
发布于 6 年前 作者 vwen 3071 次浏览 来自 问答

我接手了公司一套微信小程序的二次开发工作,需要搞清楚里面的API_TOKEN是如何构造的,目前已知是通过makeSign这个函数以及传入参数,请读码能力强的大哥帮忙看一下,有偿,非常感谢,感兴趣的加微:997712

request: function(t, e) {

        var o = this;

        return new Promise(function(a, n) {

            wx.showLoading({

                title: “请稍后…”,

                mask: !1

            }), console.log(e.method + “:” + o.globalData.baseUrl + t), console.log(e.data);

            var r = o.globalData.userInfo.token;

            r && “/editLoginPassCode” != t && (e.data.u_token = o.base64_encode®);

            var s = o.deepCopy(e.data), i = o.makeSign(s, t);

            e.data.api_token = i, wx.request({

                url: o.globalData.baseUrl + t,

                method: e.method,

                data: e.data,

                header: {

                    “content-type”: “application/x-www-form-urlencoded”,

                    Accept: “application/json”

                },

                success: function(t) {

                    if (wx.hideLoading(), console.log(t.data), 200 === t.statusCode) {

                        if (t.data.code >= 1e4 && t.data.code < 2e4 || t.data.session_key) return a(t.data),

                        !1;

                        if (t.data.code >= 2e4 && t.data.code < 3e4) return 20021 != t.data.code && 20020 != t.data.code && (20065 == t.data.code ? (o.comToast(t.data.msg, !0),

                        setTimeout(function() {

                            wx.redirectTo({

                                url: “/pages/loginModule/login/login”

                            });

                        }, 300)) : o.comToast(t.data.msg)), n(t.data), !1;

                        if (27 == t.data.code || 28 == t.data.code) return o.comToast(“请先登录…”, !0), setTimeout(function() {

                            wx.redirectTo({

                                url: “/pages/loginModule/login/login”

                            });

                        }, 400), !1;

                        29 == t.data.code && wx.redirectTo({

                            url: “/pages/loginModule/login/login”

                       }), o.comToast(t.data.msg);

                    } else o.comToast(o.requestText(t.statusCode)), n(t.data);

                },

                fail: function(t) {

                    wx.hideLoading(), console.log(“fail”), console.log(t), o.comToast(t.errMsg.toString());

                }

            });

        });

    }

1 回复

deepCopy: function(e) {

        var o = Array.isArray(e) ? [] : {};

        for (var a in e) e.hasOwnProperty(a) && (“object” === t(e[a]) ? o[a] = this.deepCopy(e[a]) : o[a] = e[a]);

        return o;

    },

    makeSign: function(t, o) {

        var a = o.replace("/", “”);

        if (t) for (var n in t) a = a + n + t[n];

        var r = (a += “cdz2.0”).split("").sort().join("");

        return (0, e.default)®;

    },

    base64_encode: function(t) {

        for (var e, o, a, n = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=”, r = 0, s = t.length, i = “”; r < s; ) {

            if (e = 255 & t.charCodeAt(r++), r == s) {

                i += n.charAt(e >> 2), i += n.charAt((3 & e) << 4), i += “==”;

                break;

            }

            if (o = t.charCodeAt(r++), r == s) {

                i += n.charAt(e >> 2), i += n.charAt((3 & e) << 4 | (240 & o) >> 4), i += n.charAt((15 & o) << 2),

                i += “=”;

                break;

            }

            a = t.charCodeAt(r++), i += n.charAt(e >> 2), i += n.charAt((3 & e) << 4 | (240 & o) >> 4),

            i += n.charAt((15 & o) << 2 | (192 & a) >> 6), i += n.charAt(63 & a);

        }

        return i;

    }

回到顶部