接口处理
This commit is contained in:
@@ -37,7 +37,9 @@ export class HiAesUtil {
|
||||
*/
|
||||
static encryptData(plainText, keyStr) {
|
||||
// 生成 ISO8601 时间戳 (与 Dart DateTime.now().toIso8601String() 对应)
|
||||
const nonce = new Date().toISOString()
|
||||
// Dart: 2025-12-30T21:05:06.075850 (no Z, 6 decimal places)
|
||||
const now = new Date()
|
||||
const nonce = now.toISOString().replace('Z', '') + '000'
|
||||
|
||||
const key = this._generateKey(keyStr)
|
||||
const iv = this._generateIv(nonce, keyStr)
|
||||
|
||||
@@ -97,13 +97,34 @@ export default class Request {
|
||||
config.data = HiAesUtil.encryptData(plainText, encryptionKey)
|
||||
}
|
||||
|
||||
if (config.method?.toLowerCase() === 'get' || config.params) {
|
||||
const paramsToEncrypt = config.params || {} // 为空则加密 "{}"
|
||||
const plainParamsText = JSON.stringify(paramsToEncrypt)
|
||||
const encryptedParams = HiAesUtil.encryptData(plainParamsText, encryptionKey)
|
||||
|
||||
// 将原参数替换为加密后的 data 和 time 字段
|
||||
config.params = {
|
||||
data: encryptedParams.data,
|
||||
time: encryptedParams.time,
|
||||
}
|
||||
}
|
||||
|
||||
if (config.data?.time) {
|
||||
console.log(
|
||||
'解密',
|
||||
HiAesUtil.decryptData(config.data.data, config.data.time, encryptionKey),
|
||||
)
|
||||
}
|
||||
|
||||
config.headers = mergeExtraConfig.formatHeader({
|
||||
...this.config.headers,
|
||||
...config.headers,
|
||||
lang: 'zh_CN',
|
||||
'login-type': 'device',
|
||||
...(mergeExtraConfig.withToken && {
|
||||
[mergeExtraConfig.tokenKey]: mergeExtraConfig.getToken(),
|
||||
}),
|
||||
})
|
||||
} as any)
|
||||
config.extraConfig = mergeExtraConfig
|
||||
if (mergeExtraConfig.cancelRepetition) {
|
||||
axiosCanceler.addPending(config)
|
||||
|
||||
Reference in New Issue
Block a user