| 260 | } |
| 261 | randomStr(length, charset) { var tmp1, tmp2, data = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), result = []; if (((charset = charset || data["length"]), length)) for (tmp1 = 0; tmp1 < length; tmp1++)result[tmp1] = data[0 | (Math.random() * charset)]; else for (result[8] = result[13] = result[18] = result[23] = "-", result[14] = "4", tmp1 = 0; tmp1 < 36; tmp1++)result[tmp1] || ((tmp2 = 0 | (16 * Math["random"]())), (result[tmp1] = data[19 === tmp1 ? (3 & tmp2) | 8 : tmp2])); return result["join"]("") } |
| 262 | decryptResponseBody(result, n) { |
| 263 | try { |
| 264 | const de1 = CryptoJS.enc.Hex.parse(result), |
| 265 | de2 = CryptoJS.enc.Base64.stringify(de1); |
| 266 | const decrypted = CryptoJS.AES.decrypt(de2, CryptoJS.enc.Utf8.parse(n.substr(10, 16)), { |
| 267 | iv: CryptoJS.enc.Utf8.parse(n.substr(20, 16)), |
| 268 | mode: CryptoJS.mode.CBC, |
| 269 | padding: CryptoJS.pad.Pkcs7, |
| 270 | }).toString(CryptoJS.enc.Utf8); |
| 271 | return decrypted; |
| 272 | } catch (error) { |
| 273 | n = "987654321012345678901234567890123456789012345678" |
| 274 | const de1 = CryptoJS.enc.Hex.parse(result), |
| 275 | de2 = CryptoJS.enc.Base64.stringify(de1); |
| 276 | const decrypted = CryptoJS.AES.decrypt(de2, CryptoJS.enc.Utf8.parse(n.substr(10, 16)), { |
| 277 | iv: CryptoJS.enc.Utf8.parse(n.substr(20, 16)), |
| 278 | mode: CryptoJS.mode.CBC, |
| 279 | padding: CryptoJS.pad.Pkcs7, |
| 280 | }).toString(CryptoJS.enc.Utf8); |
| 281 | return decrypted; |
| 282 | } |
| 283 | |
| 284 | } |
| 285 | //修复自 修改处理后 空值删除得情况 改为不删除 |
| 286 | calculateSign(requestBody) { const sortedKeys = Object.keys(requestBody).sort(); let signContent = sortedKeys.reduce((acc, key) => { const value = requestBody[key]; if (value === null) { return acc } if (typeof value === 'object' && !Array.isArray(value)) { return acc.concat(key).concat(JSON.stringify(value)) } if (Array.isArray(value)) { if (value.length > 0) { let typeOfFirstItem = typeof value[0]; if (typeOfFirstItem === 'object') { let arrayStr = ''; value.forEach((item, index) => { arrayStr += JSON.stringify(item) + (index !== value.length - 1 ? ',' : '') }); return acc.concat(key).concat(arrayStr) } } return acc.concat(key).concat(value.toString()) } return acc.concat(key).concat(value.toString()) }, ''); const secretKey = "048a9c4943398714b356a696503d2d36"; const hashedContent = CryptoJS.MD5(signContent.concat(secretKey)).toString(); return hashedContent } |
| 287 | |