使用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); } }
标签:urlencode,str,sig,sign,发送,sortData,签名,key,let 来源: https://www.cnblogs.com/chicidol/p/14885329.html