/*
used...
<script src="js/vue.js"></script>
<script src="js/axios.js"></script>
<script src="js/qs.js"></script>
<script src="js/crypto-js/crypto-js.js"></script>
*/
var nowDate = new Date();
var dateTime = nowDate.toUTCString();
//dateTime = "Mon, 19 Mar 2018 12:00:44 GMT"
var SecretId = 'your SecretId'; // 密钥对的 SecretId
var SecretKey = 'your SecretKey'; // 密钥对的 SecretKey
var source = 'xxxxxx'; // 签名水印值,可填写任意值
var auth = "hmac id=\\"" + SecretId + "\\", algorithm=\\"hmac-sha1\\", headers=\\"x-date source\\", signature=\\"";
var signStr = "x-date: " + dateTime + "\\n" + "source: " + source;
console.log(signStr)
var sign = CryptoJS.HmacSHA1(signStr, SecretKey)
console.log(sign.toString())
sign = CryptoJS.enc.Base64.stringify(sign)
sign = auth + sign + "\\""
console.log(sign)
console.log(dateTime)
var instance = axios.create({
baseURL: 'http://service-xxxxxxxx-1234567890.ap-guangzhou.apigateway.myqcloud.com/release/api/shoplist', // 用户 API 的访问路径
timeout: 5000,
headers: {
"Source":source,
"X-Date":dateTime,
"Authorization":sign
// 如果是微服务 API,Header 中需要添加'X-NameSpace-Code'、'X-MicroService-Name'两个字段,通用 API 不需要添加。
"X-NameSpace-Code": "testmic",
"X-MicroService-Name": "provider-demo",
},
withCredentials: true
});
instance.get()
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});;
本页内容是否解决了您的问题?