服务器更替

This commit is contained in:
2026-03-27 17:38:41 +08:00
parent bb64ef92b5
commit 76c766f2d2
5 changed files with 56 additions and 93 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ VITE_DELETE_CONSOLE=false
#本地环境 #本地环境
#VITE_SERVER_BASEURL=http://liuyao.nat100.top/meiguowaimai #VITE_SERVER_BASEURL=http://liuyao.nat100.top/meiguowaimai
VITE_SERVER_BASEURL=http://192.168.5.58:8080 #VITE_SERVER_BASEURL=http://192.168.5.58:8080
#VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api
#VITE_SERVER_BASEURL=http://192.168.1.8:8811 #VITE_SERVER_BASEURL=http://192.168.1.8:8811
#VITE_SERVER_BASEURL=http://mifengchuantou.natapp1.cc/meiguowaimai #VITE_SERVER_BASEURL=http://mifengchuantou.natapp1.cc/meiguowaimai
+2 -2
View File
@@ -2,8 +2,8 @@
"name" : "CHEFLINK Merchant", "name" : "CHEFLINK Merchant",
"appid" : "__UNI__BB8E3C9", "appid" : "__UNI__BB8E3C9",
"description" : "美国外卖商户端", "description" : "美国外卖商户端",
"versionName" : "1.0.17", "versionName" : "1.0.21",
"versionCode" : 117, "versionCode" : 121,
"transformPx" : false, "transformPx" : false,
/* 5+App */ /* 5+App */
"app-plus" : { "app-plus" : {
@@ -20,7 +20,7 @@ const formData = ref({
latitude: '', // 商家纬度 latitude: '', // 商家纬度
businessHours: '', // 营业时间 businessHours: '', // 营业时间
minOrderPrice: '', // 最小订单金额 minOrderPrice: '', // 最小订单金额
selfPickup: true, // 是否支持自取(1-支持 2-不支持) selfPickup: false, // 是否支持自取(1-支持 2-不支持)
pickupTime: '', // 自取时长(如"30分钟") pickupTime: '', // 自取时长(如"30分钟")
deliveryService: true, // 是否支持配送(1-支持 2-不支持) deliveryService: true, // 是否支持配送(1-支持 2-不支持)
deliveryTime: '1', // 配送时长(单位:天,如"1") deliveryTime: '1', // 配送时长(单位:天,如"1")
@@ -495,7 +495,7 @@ function handleClickStatePicker() {
</view> </view>
<!-- 自取已隐藏 --> <!-- 自取已隐藏 -->
<view v-if="false" class="mt-44rpx"> <view class="mt-44rpx">
<view class="flex-center-sb h-44rpx"> <view class="flex-center-sb h-44rpx">
<view class="text-36rpx lh-36rpx text-#333 font-500">{{ <view class="text-36rpx lh-36rpx text-#333 font-500">{{
t('pages-user.store-management.index.isSelfPickup') t('pages-user.store-management.index.isSelfPickup')
+21 -41
View File
@@ -1,31 +1,13 @@
import Crypto from 'crypto-js'
import {Base64} from 'js-base64'
import {i18n} from "@/locale"; import {i18n} from "@/locale";
const UPLOAD_ENDPOINT = '/resource/oss/upload'
const CLIENT_ID = 'e5cd7e4891bf95d1d19206ce24a7b32e'
const env = { function parseUploadResponse(data: any): string {
uploadImageUrl: 'https://wendy123.oss-ap-southeast-1.aliyuncs.com/', // 默认存在根目录,可根据需求改 const parsed = typeof data === 'string' ? JSON.parse(data || '{}') : (data || {})
accessKeySecret: 'TSZOD1jULKPFsNp2zKhAopLe3c3AiH', // accessKeySecret 去你的阿里云上控制台上找 if (parsed.code && parsed.code !== 200) {
ossAccessKeyId: 'LTAI5tQq1bSBFCfsbvwX6DqQ', // AccessKeyId 去你的阿里云上控制台上找 throw new Error(parsed.msg || 'upload failed')
timeout: 87600, // 这个是上传文件时Policy的失效时间
} }
return parsed?.data?.url || parsed?.data || parsed?.url || ''
const getPolicyBase64 = function (): string {
const date = new Date()
date.setHours(date.getHours() + env.timeout)
const expirationTime = date.toISOString()
const policyText = {
expiration: expirationTime, // 设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了
conditions: [
['content-length-range', 0, 2000 * 1024 * 1024], // 设置上传文件的大小限制,2G
],
}
return Base64.encode(JSON.stringify(policyText))
}
const getSignature = function (policyBase64: string): string {
const bytes = Crypto.HmacSHA1(policyBase64, env.accessKeySecret)
return Crypto.enc.Base64.stringify(bytes)
} }
// 上传图片到阿里云oss // 上传图片到阿里云oss
@@ -35,32 +17,30 @@ const upload = function (filePath: string, suffix = '.png', dir = 'app/image/')
return uni.showToast({icon: "none", title: i18n.global.t('common.prompt.picture-wrong-please-try-again')}) return uni.showToast({icon: "none", title: i18n.global.t('common.prompt.picture-wrong-please-try-again')})
} }
// 图片名字 可以自行定义,这里是采用当前的时间戳 + 150内的随机数来给图片命名的
const fileKey = dir + new Date().getTime() + Math.floor(Math.random() * 150) + suffix
const aliyunServerURL = env.uploadImageUrl // OSS地址,需要https
const policyBase64 = getPolicyBase64()
const signature = getSignature(policyBase64) // 获取签名
uni.uploadFile({ uni.uploadFile({
url: aliyunServerURL, // 开发者服务器 url url: UPLOAD_ENDPOINT,
filePath: filePath, // 要上传文件资源的路径 filePath: filePath, // 要上传文件资源的路径
name: 'file', // 必须填file name: 'file', // 必须填file
timeout: 20000, timeout: 20000,
formData: { header: {
key: fileKey, clientid: CLIENT_ID,
policy: policyBase64,
OSSAccessKeyId: env.ossAccessKeyId,
signature: signature,
success_action_status: '200',
}, },
formData: {},
success: function (res) { success: function (res) {
console.log(res)
if (res.statusCode !== 200) { if (res.statusCode !== 200) {
reject(new Error('upload error:' + JSON.stringify(res))) reject(new Error('upload error:' + JSON.stringify(res)))
return return
} }
resolve(aliyunServerURL + fileKey) try {
const uploadedUrl = parseUploadResponse(res.data)
if (!uploadedUrl) {
reject(new Error('upload response url is empty'))
return
}
resolve(uploadedUrl)
} catch (error) {
reject(error)
}
}, },
fail: function (err) { fail: function (err) {
console.log(err) console.log(err)
+30 -47
View File
@@ -1,34 +1,16 @@
import CryptoJS from 'crypto-js'
import {Base64} from 'js-base64'
import {i18n} from '@/locale' import {i18n} from '@/locale'
const baseUrl = import.meta.env.VITE_SERVER_BASEURL
// === 👉 请在这里填写你的 AWS 信息 === const UPLOAD_ENDPOINT = '/resource/oss/upload'
const S3Config = { const CLIENT_ID = 'e5cd7e4891bf95d1d19206ce24a7b32e'
bucket: 'cheflink', // 你的存储桶名称
region: 'us-east-1', // 桶所在区域
accessKeyId: 'AKIA3LKQVMAPD3KFPJGS', function parseUploadResponse(data: any): string {
secretKey: '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', const parsed = typeof data === 'string' ? JSON.parse(data || '{}') : (data || {})
timeout: 0.1 // 签名有效时间(小时) if (parsed.code && parsed.code !== 200) {
throw new Error(parsed.msg || 'upload failed')
} }
return parsed?.data?.url || parsed?.data || parsed?.url || ''
// === 签名函数 ===
function getPolicyBase64(): string {
const expiration = new Date(Date.now() + 10 * 60 * 1000).toISOString() // 10分钟有效
const policyText = {
expiration,
conditions: [
{bucket: S3Config.bucket},
['starts-with', '$key', 'cheflink/'],
['starts-with', '$Content-Type', 'image/']
]
}
return Base64.encode(JSON.stringify(policyText))
}
function getSignature(policyBase64: string): string {
const bytes = CryptoJS.HmacSHA1(policyBase64, S3Config.secretKey)
return CryptoJS.enc.Base64.stringify(bytes)
} }
// === 图片压缩函数 === // === 图片压缩函数 ===
@@ -89,7 +71,7 @@ function compressImageIfNeeded(filePath: string, size: number): Promise<string>
}) })
} }
// === S3 上传函数 === // 上传文件到后端接口
const uploadToS3 = async function (filePath: string, suffix = '.jpg', dir = 'cheflink/'): Promise<string> { const uploadToS3 = async function (filePath: string, suffix = '.jpg', dir = 'cheflink/'): Promise<string> {
if (!filePath) { if (!filePath) {
uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.picture-wrong-please-try-again')}) uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.picture-wrong-please-try-again')})
@@ -120,32 +102,33 @@ const uploadToS3 = async function (filePath: string, suffix = '.jpg', dir = 'che
return Promise.reject(err) return Promise.reject(err)
} }
// 文件名
const filename = Date.now() + Math.floor(Math.random() * 1000) + suffix
const key = dir + filename
const policyBase64 = getPolicyBase64()
const signature = getSignature(policyBase64)
const uploadUrl = `https://${S3Config.bucket}.s3.${S3Config.region}.amazonaws.com/`
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.uploadFile({ uni.uploadFile({
url: uploadUrl, url:baseUrl+ UPLOAD_ENDPOINT,
filePath: uploadPath, filePath: uploadPath,
name: 'file', name: 'file',
formData: { header: {
key, clientid: CLIENT_ID,
AWSAccessKeyId: S3Config.accessKeyId,
policy: policyBase64,
signature,
'Content-Type': 'image/jpeg',
}, },
formData: {},
success: res => { success: res => {
if (res.statusCode === 204) { if (res.statusCode !== 200) {
uni.showToast({icon: 'none', title: i18n.global.t('common.operation-success')})
resolve(`${uploadUrl}${key}`)
} else {
uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.up-failed')}) uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.up-failed')})
reject(new Error(`上传失败,状态码: ${res.statusCode}`)) reject(new Error(`上传失败,状态码: ${res.statusCode}`))
return
}
try {
const uploadedUrl = parseUploadResponse(res.data)
if (!uploadedUrl) {
uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.up-failed')})
reject(new Error('上传失败,返回地址为空'))
return
}
uni.showToast({icon: 'none', title: i18n.global.t('common.operation-success')})
resolve(uploadedUrl)
} catch (error) {
uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.up-failed')})
reject(error)
} }
}, },
fail: err => { fail: err => {