收藏
回答

需要重新构架makeSign,但是源程序看不懂,求助

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


回答关注问题邀请回答
收藏

1 个回答

  • 杭州弧途科技有限公司
    杭州弧途科技有限公司
    2019-06-04

    所以你贴代码片段吖

    2019-06-04
    赞同
    回复 4
    • 小舟
      小舟
      2019-06-07

      这是获取函数 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(r));

                  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());

                      }

                  });

              });

          }












      2019-06-07
      回复
    • 小舟
      小舟
      2019-06-07

      这是相关构造函数

      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)(r);

          },

          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;

          }


      2019-06-07
      回复
    • 小舟
      小舟
      2019-06-07

      这是举例:

      比如访问/inspectList,传的参数是

      page1
      list_rows20
      bill_type3
      api_token5da7581a02617afc6ada24d5a1e571ba
      u_tokenMTA4YjRkNjc5NWE2NDBmYTFkNjRhNTRhNGQ1MDlkNjE=


      2019-06-07
      回复
    • 杭州弧途科技有限公司
      杭州弧途科技有限公司
      2019-06-10

      代码片段:https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

      2019-06-10
      回复
登录 后发表内容