使用sign签名发送请求

import CryptoJS from "crypto-js";
import urlencode from "urlencode";
methods:{
    async initUser () {
      try {
        const url = "/api/info/self";
        let _param = {
          uid: this.uid,
          utoken: this.token,
          version: "1.0",
          ak: "test",
          ts: new Date().getTime(),
          nonce: "1234567890"
        }
        let sortData = {}
        let str = ""
        Object.keys(_param).sort().map(key => {
          sortData[key] = _param[key]
          str += (key + "=" + sortData[key] + "&")
        })
         let result = CryptoJS.HmacSHA1(str.substring(0, str.length - 1), "4544b93610d6aeea857db75a0e63edb4");
        console.log(result)
        let sig = result.toString();
        sig = encodeURI(sig);
        sig = urlencode(sig);
        sortData.sign = sig
        const { data: res } = await this.$http[0].get(
          url,
          {
            params: sortData,
          },
        );
        console.log(res.data);
      } catch (err) {
        console.dir(err);
      }
    }

  

上一篇:获取x-sign/x-mini-wua/x-sgext/x-umt


下一篇:使用IDEA创建Maven工程,集成SpringMVC和MyBatis框架,完成简单的签到程序