diff --git a/superManagement/src/views/openPlatform/index.vue b/superManagement/src/views/openPlatform/index.vue index 63737e1..4532a38 100644 --- a/superManagement/src/views/openPlatform/index.vue +++ b/superManagement/src/views/openPlatform/index.vue @@ -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 @@ -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, + timeStamp: number, + accessKey: string, + secretKey: string): string => { + const paramsMap = new Map(); + 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[]>([])