代码提交
This commit is contained in:
parent
56b0a9dca4
commit
c12c5b26fa
|
@ -29,8 +29,8 @@ import TableProMax from "@/components/table/TableProMax.vue";
|
||||||
import {TableProMaxProps} from "@/types/components/table";
|
import {TableProMaxProps} from "@/types/components/table";
|
||||||
import {AccessKeyRes, GeneratedAccessKeyParams} from "@/types/views/openPlatform/openPlatform.ts";
|
import {AccessKeyRes, GeneratedAccessKeyParams} from "@/types/views/openPlatform/openPlatform.ts";
|
||||||
import {ComponentExposed} from "vue-component-type-helpers";
|
import {ComponentExposed} from "vue-component-type-helpers";
|
||||||
import axios from "axios";
|
|
||||||
import {md5} from "js-md5";
|
import {md5} from "js-md5";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
type TableProps = TableProMaxProps<AccessKeyRes>
|
type TableProps = TableProMaxProps<AccessKeyRes>
|
||||||
|
|
||||||
|
@ -128,37 +128,76 @@ const a = () => {
|
||||||
const accessKey = "w2wzi0wefmmo6s735z2el8tfzitya5gj"
|
const accessKey = "w2wzi0wefmmo6s735z2el8tfzitya5gj"
|
||||||
const secretKey = "db1b5214-02ee-497f-957c-88323b4351bf"
|
const secretKey = "db1b5214-02ee-497f-957c-88323b4351bf"
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const paramsMap = new Map();
|
const params = {
|
||||||
paramsMap.set('name', 'zhangsan')
|
name: 'zhangsan',
|
||||||
paramsMap.set('age', 14)
|
age: 14,
|
||||||
paramsMap.set('addr', '湖南省长沙市')
|
addr: '湖南省长沙市'
|
||||||
paramsMap.set('access-key', accessKey)
|
}
|
||||||
paramsMap.set('time-stamp', now)
|
|
||||||
|
|
||||||
// 将 Map 转换为数组并排序
|
const sign = generatedSign(params, now, accessKey, secretKey)
|
||||||
const entries = Array.from(paramsMap.entries());
|
|
||||||
entries.sort((a, b) => a[0].localeCompare(b[0]));
|
|
||||||
// 拼接成 URL 编码的字符串
|
|
||||||
let encodedParams = entries.map(([key, value]) => `${key}=${encodeURIComponent(value).replace(/%([0-9A-Fa-f]{2})/g, function (_, p1) {
|
|
||||||
return '%' + p1.toUpperCase();
|
|
||||||
})}`).join('&');
|
|
||||||
encodedParams = encodedParams + "&secret-key=" + secretKey
|
|
||||||
console.log(encodedParams);
|
|
||||||
|
|
||||||
const sign = md5(encodedParams).toUpperCase()
|
|
||||||
console.log(sign);
|
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
'access-key': accessKey,
|
'Access-Key': accessKey,
|
||||||
'time-stamp': now,
|
'Time-Stamp': now,
|
||||||
'sign': sign
|
'Sign': sign
|
||||||
}
|
}
|
||||||
console.log(headers);
|
// axios.get('http://127.0.0.1:8765/open/dataView', {
|
||||||
|
// params,
|
||||||
|
// headers
|
||||||
|
// })
|
||||||
|
|
||||||
api.get('/open/dataView', null, {
|
const params2 = {
|
||||||
headers
|
code: 'SSP001',
|
||||||
|
level: 5
|
||||||
|
}
|
||||||
|
const sign2 = generatedSign(params2, now, accessKey, secretKey)
|
||||||
|
const headers2 = {
|
||||||
|
'Access-Key': accessKey,
|
||||||
|
'Time-Stamp': now,
|
||||||
|
'Sign': sign2
|
||||||
|
}
|
||||||
|
axios.get('http://127.0.0.1:8765/open/dataView', {
|
||||||
|
params: params2,
|
||||||
|
headers: {
|
||||||
|
...headers2
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// api.get('/open/dataView', paramsMap, {
|
||||||
|
// headers
|
||||||
|
// })
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成签名
|
||||||
|
* @param params 参数
|
||||||
|
* @param timeStamp 时间戳
|
||||||
|
* @param accessKey
|
||||||
|
* @param secretKey
|
||||||
|
*/
|
||||||
|
const generatedSign = (params: Record<string, any>,
|
||||||
|
timeStamp: number,
|
||||||
|
accessKey: string,
|
||||||
|
secretKey: string): string => {
|
||||||
|
const paramsMap = new Map<string, any>();
|
||||||
|
if (params) {
|
||||||
|
for (let paramsKey in params) {
|
||||||
|
paramsMap.set(paramsKey, params[paramsKey])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
paramsMap.set('Access-Key', accessKey)
|
||||||
|
paramsMap.set('Time-Stamp', timeStamp)
|
||||||
|
// 将 Map 转换为数组并排序
|
||||||
|
const entries = Array.from(paramsMap.entries());
|
||||||
|
// 拼接成 URL 编码的字符串
|
||||||
|
const encodedParams = entries
|
||||||
|
.filter(([_, value]) => value !== null && value !== undefined && value !== '')
|
||||||
|
.sort((a, b) => a[0].localeCompare(b[0], undefined, {sensitivity: 'base', caseFirst: 'upper'}))
|
||||||
|
.map(([key, value]) => `${key}=${encodeURIComponent(value).replace(/%([0-9A-Fa-f]{2})/g, (_, p1) => '%' + p1.toUpperCase())}`)
|
||||||
|
.join('&') + "&Secret-Key=" + secretKey;
|
||||||
|
return md5(encodedParams).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
const allowedResources = ref<SelectNodeVo<string>[]>([])
|
const allowedResources = ref<SelectNodeVo<string>[]>([])
|
||||||
|
|
Loading…
Reference in New Issue