Commit 6770f387 by 前端

oss

1 parent 6ec5cb89
module.exports = { module.exports = {
// 请求域名 格式:https://xxx.xxx.com // 请求域名 格式:https://xxx.xxx.com
HTTP_REQUEST_URL: 'http://127.0.0.1:8000/api', HTTP_REQUEST_URL: "http://127.0.0.1:8000/api",
// 阿里云oss域名 格式:https://xxx.oss-cn-xxx.aliyuncs.com // 阿里云oss域名 格式:https://xxx.oss-cn-xxx.aliyuncs.com
OSS_DOMAIN: '', OSS_DOMAIN: "https://glsk-oss.oss-cn-shenzhen.aliyuncs.com",
// 文件直传到阿里云oss时需用到 // 文件直传到阿里云oss时需用到
ACCESSKEYID: '', ACCESSKEYID: "LTAI5tCRcCUgd7bt1J7JY596",
ACCESSKEYSECRET: '', ACCESSKEYSECRET: "kJos9mgylkR5ztosnDt8Asrc3ulgqy",
BUKET_NAME: "glsk-oss",
FOLDER: "quality/",
// 与后端约定的token字段名 // 与后端约定的token字段名
TOKEN_NAME: 'Authorization' TOKEN_NAME: "glsk-oss",
} };
const target = ['ip', 'dev', 'uat', 'prod', 'preRelease'] const target = ["ip", "dev", "uat", "prod", "preRelease"];
const index = 2 const index = 2;
/** /**
* *
0本地 0本地
...@@ -12,109 +12,109 @@ const secretKey = { ...@@ -12,109 +12,109 @@ const secretKey = {
ip: {}, ip: {},
dev: { dev: {
sso: { sso: {
appKey: '8b31ae1009ccb0f96130ca4bd90e3d89', appKey: "8b31ae1009ccb0f96130ca4bd90e3d89",
secret: '02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b' secret: "02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b",
} },
}, },
uat: { uat: {
sso: { sso: {
appKey: '8b31ae1009ccb0f96130ca4bd90e3d89', appKey: "8b31ae1009ccb0f96130ca4bd90e3d89",
secret: '02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b' secret: "02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b",
} },
}, },
prod: { prod: {
sso: { sso: {
appKey: '8b31ae1009ccb0f96130ca4bd90e3d89', appKey: "8b31ae1009ccb0f96130ca4bd90e3d89",
secret: '02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b' secret: "02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b",
} },
}, },
preRelease: { preRelease: {
sso: { sso: {
appKey: '8b31ae1009ccb0f96130ca4bd90e3d89', appKey: "8b31ae1009ccb0f96130ca4bd90e3d89",
secret: '02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b' secret: "02d60f17ae714872845d2aa9d3b087e109ccb0f96130ca4b",
} },
} },
}[target[index]] }[target[index]];
const domain = { const domain = {
// ip: 'http://192.168.2.94:8558', // ip: 'http://192.168.2.94:8558',
// ip: 'http://192.168.2.3:8315', // ip: 'http://192.168.2.3:8315',
ip: 'http://192.168.1.170:8315', ip: "http://192.168.1.170:8315",
/**登录: 192.168.2.3:8315 /**登录: 192.168.2.3:8315
商城: 192.168.2.3:8558 */ 商城: 192.168.2.3:8558 */
dev: 'https://scrm.dev.glsx.com.cn', dev: "https://scrm.dev.glsx.com.cn",
uat: 'https://scrm.test.glsx.com.cn', uat: "https://scrm.test.glsx.com.cn",
preRelease: 'https://scrm.beta.glsx.com.cn', preRelease: "https://scrm.beta.glsx.com.cn",
prod: 'https://scrm.glsx.com.cn' prod: "https://scrm.glsx.com.cn",
}[target[index]] }[target[index]];
const djDomain = { const djDomain = {
ip: 'http://192.168.2.59:8292', ip: "http://192.168.2.59:8292",
// ip: 'http://192.168.2.80:8558', // ip: 'http://192.168.2.80:8558',
dev: 'https://dj.dev.glsx.com.cn', dev: "https://dj.dev.glsx.com.cn",
beta: 'https://dj.beta.glsx.com.cn', //预发布 appid: wx9f91c1ec493eb425 beta: "https://dj.beta.glsx.com.cn", //预发布 appid: wx9f91c1ec493eb425
uat: 'https://dj.test.glsx.com.cn', //测试 appid: wxe10067a63c1856ac uat: "https://dj.test.glsx.com.cn", //测试 appid: wxe10067a63c1856ac
prod: 'https://dj.glsx.com.cn', prod: "https://dj.glsx.com.cn",
pet: 'https://cdptest.glsx.com.cn' //压测 appid: wx7ce755e425603084 pet: "https://cdptest.glsx.com.cn", //压测 appid: wx7ce755e425603084
}[target[index]] }[target[index]];
const merchantDomain = { const merchantDomain = {
ip: 'http://rop-merchant.dev.glsx.com.cn', ip: "http://rop-merchant.dev.glsx.com.cn",
dev: 'http://rop-merchant.dev.glsx.com.cn', dev: "http://rop-merchant.dev.glsx.com.cn",
beta: 'https://rop-merchant.beta.glsx.com.cn', beta: "https://rop-merchant.beta.glsx.com.cn",
uat: 'https://rop-merchant.test.glsx.com.cn', uat: "https://rop-merchant.test.glsx.com.cn",
prod: 'https://commodity.glsx.com.cn', prod: "https://commodity.glsx.com.cn",
pet: '' pet: "",
}[target[index]] }[target[index]];
const djSecretKey = { const djSecretKey = {
ip: { ip: {},
},
dev: { dev: {
appKey: '48e5e13229b82c1b4e6e8c96151f0637', appKey: "48e5e13229b82c1b4e6e8c96151f0637",
secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b', secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
}, },
uat: { uat: {
appKey: '48e5e13229b82c1b4e6e8c96151f0637', appKey: "48e5e13229b82c1b4e6e8c96151f0637",
secret: 'c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b', secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
}, },
beta: { beta: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022', appKey: "d7ffc3346fc9a45bccaaa35300d59022",
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353', secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353",
}, },
prod: { prod: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022', appKey: "d7ffc3346fc9a45bccaaa35300d59022",
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353' secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353",
}, },
pet: { pet: {
appKey: 'd7ffc3346fc9a45bccaaa35300d59022', appKey: "d7ffc3346fc9a45bccaaa35300d59022",
secret: '4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353' secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353",
} },
}[target[index]] }[target[index]];
const pathEnum = { const pathEnum = {
sso: '/rop-scrm-sso/', sso: "/rop-scrm-sso/",
shopmall: '/rop-scrm-shopmall/', shopmall: "/rop-scrm-shopmall/",
coupon: '/rop-scrm-coupon/', coupon: "/rop-scrm-coupon/",
carlife: '/rop-scrm-carlife/', carlife: "/rop-scrm-carlife/",
live: '/rop-scrm-live/', live: "/rop-scrm-live/",
equity: '/rop-scrm-equity/', equity: "/rop-scrm-equity/",
entmicro: '/rop-scrm-entmicro/', entmicro: "/rop-scrm-entmicro/",
wechat: '/rop-scrm-wechat/', wechat: "/rop-scrm-wechat/",
boutiquecoupon: '/rop-scrm-boutiquecoupon/', boutiquecoupon: "/rop-scrm-boutiquecoupon/",
material: '/rop-scrm-marketing/', //素材 material: "/rop-scrm-marketing/", //素材
sop: '/rop-scrm-sop/', sop: "/rop-scrm-sop/",
customercollect: '/rop-scrm-bigdatautil/', customercollect: "/rop-scrm-bigdatautil/",
drac: '/rop-scrm-entmicro/', mindworkplate: "/rop-dj-smartcarlife/",
busassistant: '/rop-scrm-busassistant/', drac: "/rop-scrm-entmicro/",
boutique: '/rop-dj-car-boutique/' busassistant: "/rop-scrm-busassistant/",
} boutique: "/rop-dj-car-boutique/",
};
const CONFIG_ENV_MAP = { const CONFIG_ENV_MAP = {
1: 'develop', 1: "develop",
2: 'test', 2: "test",
3: 'production', 3: "production",
4: 'beta' 4: "beta",
} };
module.exports = { module.exports = {
index, index,
domain, domain,
...@@ -123,5 +123,5 @@ module.exports = { ...@@ -123,5 +123,5 @@ module.exports = {
env: CONFIG_ENV_MAP[index], env: CONFIG_ENV_MAP[index],
djDomain, djDomain,
merchantDomain, merchantDomain,
djSecretKey djSecretKey,
} };
...@@ -2,7 +2,9 @@ import config from '@/config.js' ...@@ -2,7 +2,9 @@ import config from '@/config.js'
// 在h5端上传涉及到跨域,需在阿里云上配置跨域规则才能正常使用 // 在h5端上传涉及到跨域,需在阿里云上配置跨域规则才能正常使用
module.exports = { module.exports = {
uploadImageUrl: config.OSS_DOMAIN + '/', // 默认存在根目录后面要跟个'/' (在你当前小程序的后台的uploadFile 合法域名也要配上这个域名) bucketName: config.BUKET_NAME,
folder: config.FOLDER,
uploadUrl: config.OSS_DOMAIN + '/', // 默认存在根目录后面要跟个'/' (在你当前小程序的后台的uploadFile 合法域名也要配上这个域名)
AccessKeySecret: config.ACCESSKEYSECRET, // AccessKeySecret 去你的阿里云上控制台上找 AccessKeySecret: config.ACCESSKEYSECRET, // AccessKeySecret 去你的阿里云上控制台上找
OSSAccessKeyId: config.ACCESSKEYID, // AccessKeyId 去你的阿里云上控制台上找 OSSAccessKeyId: config.ACCESSKEYID, // AccessKeyId 去你的阿里云上控制台上找
timeout: 87600 // 这个是上传文件时Policy的失效时间 timeout: 87600 // 这个是上传文件时Policy的失效时间
......
This diff could not be displayed because it is too large.
/*
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-07 17:09:51
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-04-08 10:53:29
* @FilePath: \gl_tape\utils\ossUploadFile\uploadFile.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
// base64,Hmac,Sha1,Crypto 相关算法 // base64,Hmac,Sha1,Crypto 相关算法
import config from './config.js'; import config from "./config.js";
import base64 from './base64.js'; import base64 from "./base64.js";
import Hmac from './hmac.js'; import Hmac from "./hmac.js";
import Sha1 from './sha1.js'; import Sha1 from "./sha1.js";
import Crypto from './crypto.js'; import Crypto from "./crypto.js";
/** /**
* 上传文件到阿里云oss * 上传文件到阿里云oss
* @param {string} filePath 图片的本地资源路径 * @param {string} filePath 图片的本地资源路径
* @param {string} dir 表示要传到哪个目录下 * @param {string} dir 表示要传到哪个目录下
* @return 完整的图片地址 * @return 完整的图片地址
*/ */
const uploadFile = function(filePath, dir) { const uploadFile = function (filePath) {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
if (!filePath || filePath.length < 9) { if (!filePath || filePath.length < 9) {
uni.showModal({ uni.showModal({
title: '图片错误', title: "文件错误",
content: '请重试', content: "请重试",
showCancel: false, showCancel: false,
}) });
reject('图片错误'); reject("文件错误");
} }
console.log('上传图片中...');
// #ifdef H5
// 图片名字 可以自行定义
let aliyunFileKey = dir + '.png';
// #endif
// #ifndef H5
// 获取上传的文件类型 // 获取上传的文件类型
let fileTypeIndex = filePath.lastIndexOf('.'); let fileTypeIndex = filePath.lastIndexOf("/");
let fileType = filePath.substring(fileTypeIndex); let fileType = filePath.substring(fileTypeIndex + 1);
let aliyunFileKey = dir + fileType; let aliyunFileKey = config.folder + fileType;
// #endif const aliyunServerURL = config.uploadUrl; // OSS地址
const aliyunServerURL = config.uploadImageUrl; // OSS地址,需要https
const accessid = config.OSSAccessKeyId; const accessid = config.OSSAccessKeyId;
const policyBase64 = getPolicyBase64(); const policyBase64 = getPolicyBase64();
const signature = getSignature(policyBase64); // 获取签名 const { signature, securityToken, lsaccessKeyId } = await getSignature(
policyBase64
); // 获取签名
uni.uploadFile({ uni.uploadFile({
url: aliyunServerURL, // 开发者服务器url url: aliyunServerURL, // 开发者服务器url
filePath: filePath, // 要上传文件资源的路径 filePath: filePath, // 要上传文件资源的路径
name: 'file', // 必须填file name: "file", // 必须填file
formData: { formData: {
'key': aliyunFileKey, key: aliyunFileKey,
'policy': policyBase64, policy: policyBase64,
'OSSAccessKeyId': accessid, OSSAccessKeyId: lsaccessKeyId,
'success_action_status': '200', // 让服务端返回200, 不然默认会返回204 success_action_status: "200", // 让服务端返回200, 不然默认会返回204
'signature': signature, signature: signature,
"x-oss-security-token": securityToken, // 使用STS签名时必传。
}, },
success: function(res) { success: function (res) {
console.log(res, 444);
if (res.statusCode != 200) { if (res.statusCode != 200) {
reject(new Error('上传错误:' + JSON.stringify(res))); reject(new Error("上传错误:" + JSON.stringify(res)));
} }
resolve(aliyunServerURL + aliyunFileKey); resolve(aliyunServerURL + aliyunFileKey);
}, },
fail: function(err) { fail: function (err) {
err.domainName = aliyunServerURL; err.domainName = aliyunServerURL;
reject(err); reject(err);
}, },
})
}); });
} });
};
const getPolicyBase64 = function() { const getPolicyBase64 = function () {
let date = new Date(); let date = new Date();
date.setHours(date.getHours() + config.timeout); date.setHours(date.getHours() + config.timeout);
let srcT = date.toISOString(); let srcT = date.toISOString();
const policyText = { const policyText = {
"expiration": '2099-01-01T12:00:00.000Z', //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了 expiration: srcT, //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了
"conditions": [ conditions: [
["content-length-range", 0, 5242880] // 设置上传文件的大小限制(5m) ["content-length-range", 0, 1024 * 1024 * 1024], // 设置上传文件的大小限制(5m)
] ],
}; };
const policyBase64 = base64.encode(JSON.stringify(policyText)); const policyBase64 = base64.encode(JSON.stringify(policyText));
return policyBase64; return policyBase64;
} };
// 生成签名 // 生成签名
const getSignature = function(policyBase64) { const getSignature = function (policyBase64) {
const accesskey = config.AccessKeySecret; return new Promise(async (reslove) => {
const bytes = Crypto.HMAC(Crypto.SHA1, policyBase64, accesskey, { const result = uni.$api.commonApi.getToken({}).then((res) => {
asBytes: true const { lsaccessKeySecret, securityToken, lsaccessKeyId } = res;
const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret);
const signature = Crypto.enc.Base64.stringify(bytes);
reslove({
signature,
securityToken,
lsaccessKeyId,
});
});
// const result = await uni.request({
// url: 'https://dj.test.glsx.com.cn/rop-dj-smartcarlife/router',
// data: {
// method: 'dj.api.mindworkplate.badge.getToken',
// appKey: '48e5e13229b82c1b4e6e8c96151f0637',
// timestamp: '1712487472621',
// v: '1.0.0',
// format: 'json',
// locale: 'zh_CN',
// sessionId: '98152bee-7533-41ed-bc94-60310f2df6f0',
// sign: '238CE46892F88BBAD035BAEA73E27AC7C080F340'
// },
// success(res) {
// const {
// lsaccessKeySecret,
// securityToken,
// lsaccessKeyId
// } = res.data.data;
// const bytes = Crypto.HmacSHA1(policyBase64, lsaccessKeySecret);
// const signature = Crypto.enc.Base64.stringify(bytes);
// reslove({
// signature,
// securityToken,
// lsaccessKeyId
// })
// }
// })
}); });
const signature = Crypto.util.bytesToBase64(bytes); };
return signature;
}
module.exports = uploadFile; module.exports = uploadFile;
import defaultStorage from './storage';
export default defaultStorage;
\ No newline at end of file \ No newline at end of file
export default {
// 设置永久缓存
set(key, value) {
uni.setStorageSync(key, value);
},
// 获取永久缓存
get(key) {
return uni.getStorageSync(key);
},
// 移除永久缓存
remove(key) {
uni.removeStorageSync(key);
},
// 移除全部永久缓存
clear() {
uni.clearStorageSync();
},
};
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!