代码提交

This commit is contained in:
luozhun 2024-11-20 16:21:36 +08:00
parent 56b0a9dca4
commit c12c5b26fa
1 changed files with 64 additions and 25 deletions

View File

@ -29,8 +29,8 @@ import TableProMax from "@/components/table/TableProMax.vue";
import {TableProMaxProps} from "@/types/components/table";
import {AccessKeyRes, GeneratedAccessKeyParams} from "@/types/views/openPlatform/openPlatform.ts";
import {ComponentExposed} from "vue-component-type-helpers";
import axios from "axios";
import {md5} from "js-md5";
import axios from "axios";
type TableProps = TableProMaxProps<AccessKeyRes>
@ -128,37 +128,76 @@ const a = () => {
const accessKey = "w2wzi0wefmmo6s735z2el8tfzitya5gj"
const secretKey = "db1b5214-02ee-497f-957c-88323b4351bf"
const now = Date.now()
const paramsMap = new Map();
paramsMap.set('name', 'zhangsan')
paramsMap.set('age', 14)
paramsMap.set('addr', '湖南省长沙市')
paramsMap.set('access-key', accessKey)
paramsMap.set('time-stamp', now)
const params = {
name: 'zhangsan',
age: 14,
addr: '湖南省长沙市'
}
// Map
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 sign = generatedSign(params, now, accessKey, secretKey)
const headers = {
'access-key': accessKey,
'time-stamp': now,
'sign': sign
'Access-Key': accessKey,
'Time-Stamp': now,
'Sign': sign
}
console.log(headers);
// axios.get('http://127.0.0.1:8765/open/dataView', {
// params,
// headers
// })
api.get('/open/dataView', null, {
headers
const params2 = {
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>[]>([])