From a3015b8f9251562e1ebbfec55d285d24982c6f82 Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Thu, 1 Aug 2024 17:00:58 +0800 Subject: [PATCH] =?UTF-8?q?oss=E7=A7=98=E9=92=A5=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 10 +++++++ package.json | 2 ++ src/components/upload/config.js | 46 ++++++++++++++++++++++++------- src/components/upload/index.vue | 36 +++++++++--------------- src/components/upload/upload.js | 49 +++++++++++++++++---------------- src/utils/api.js | 1 + src/utils/http.js | 24 +++++++--------- src/views/Home.vue | 31 +++++++++++---------- 8 files changed, 114 insertions(+), 85 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7e7e2b6..95b0bd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4607,6 +4607,11 @@ "randomfill": "^1.0.3" } }, + "crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "css": { "version": "2.2.4", "resolved": "https://registry.npm.taobao.org/css/download/css-2.2.4.tgz", @@ -8637,6 +8642,11 @@ "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", "dev": true }, + "jsencrypt": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/jsencrypt/-/jsencrypt-3.3.2.tgz", + "integrity": "sha512-arQR1R1ESGdAxY7ZheWr12wCaF2yF47v5qpB76TtV64H1pyGudk9Hvw8Y9tb/FiTIaaTRUyaSnm5T/Y53Ghm/A==" + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", diff --git a/package.json b/package.json index 84622dc..af1ce40 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,10 @@ "ali-oss": "^6.18.1", "axios": "^0.19.2", "core-js": "^3.6.5", + "crypto-js": "^4.2.0", "element-ui": "^2.14.0", "image-webpack-loader": "^8.1.0", + "jsencrypt": "^3.3.2", "lib-flexible": "^0.3.2", "lodash": "^4.17.21", "mavon-editor": "^2.10.4", diff --git a/src/components/upload/config.js b/src/components/upload/config.js index f8a1254..326e680 100644 --- a/src/components/upload/config.js +++ b/src/components/upload/config.js @@ -1,15 +1,41 @@ /** * 阿里云oss配置 * */ +import { get } from '@/utils/http' +import api from '@/utils/api' +import CryptoJS from 'crypto-js' +import JSEncrypt from 'jsencrypt' - export default { - // oss账号信息 - config: { - region: 'oss-cn-shenzhen', - accessKeyId: 'LTAI4FzqQHnk4rozqLZ8jCNj', - accessKeySecret: 'mveW7B1OyFoKUkHm8WsxmrjHmkJWHq', - bucket: 'huoran' - }, - // 上传成功url前置部分(成功回调没有返回url) - preUrl: 'https://huoran.oss-cn-shenzhen.aliyuncs.com/' +const A = (key, encryptedData) => { + const keyHex = CryptoJS.enc.Base64.parse(key) + const decrypted = CryptoJS.AES.decrypt(encryptedData, keyHex, { + mode: CryptoJS.mode.ECB, + padding: CryptoJS.pad.Pkcs7 + }) + return decrypted.toString(CryptoJS.enc.Utf8) +} + +const R = (encryptedKey, privateKey) => { + const decrypt = new JSEncrypt() + decrypt.setPrivateKey(privateKey) + const decryptedKey = decrypt.decrypt(encryptedKey) + return decryptedKey +} + +export default async function () { + try { + const res = await get(api.encrypt) + const RE = A(R(res.encryptedKey, res.privateKey), res.encryptedData).split('/') + return { + // oss账号信息 + config: { + region: 'oss-cn-shenzhen', + accessKeyId: RE[0], + accessKeySecret: RE[1], + bucket: 'huoran' + }, + // 上传成功url前置部分(成功回调没有返回url) + preUrl: 'https://huoran.oss-cn-shenzhen.aliyuncs.com/' + } + } catch (e) { } } \ No newline at end of file diff --git a/src/components/upload/index.vue b/src/components/upload/index.vue index bddfc2a..1351505 100644 --- a/src/components/upload/index.vue +++ b/src/components/upload/index.vue @@ -1,25 +1,13 @@