服务器更替

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://192.168.5.58:8080
#VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api
#VITE_SERVER_BASEURL=http://192.168.5.58:8080
VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api
#VITE_SERVER_BASEURL=http://192.168.1.8:8811
#VITE_SERVER_BASEURL=http://mifengchuantou.natapp1.cc/meiguowaimai
+2 -2
View File
@@ -2,8 +2,8 @@
"name" : "CHEFLINK Merchant",
"appid" : "__UNI__BB8E3C9",
"description" : "美国外卖商户端",
"versionName" : "1.0.17",
"versionCode" : 117,
"versionName" : "1.0.21",
"versionCode" : 121,
"transformPx" : false,
/* 5+App */
"app-plus" : {
@@ -20,7 +20,7 @@ const formData = ref({
latitude: '', // 商家纬度
businessHours: '', // 营业时间
minOrderPrice: '', // 最小订单金额
selfPickup: true, // 是否支持自取(1-支持 2-不支持)
selfPickup: false, // 是否支持自取(1-支持 2-不支持)
pickupTime: '', // 自取时长(如"30分钟")
deliveryService: true, // 是否支持配送(1-支持 2-不支持)
deliveryTime: '1', // 配送时长(单位:天,如"1")
@@ -495,7 +495,7 @@ function handleClickStatePicker() {
</view>
<!-- 自取已隐藏 -->
<view v-if="false" class="mt-44rpx">
<view class="mt-44rpx">
<view class="flex-center-sb h-44rpx">
<view class="text-36rpx lh-36rpx text-#333 font-500">{{
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";
const UPLOAD_ENDPOINT = '/resource/oss/upload'
const CLIENT_ID = 'e5cd7e4891bf95d1d19206ce24a7b32e'
const env = {
uploadImageUrl: 'https://wendy123.oss-ap-southeast-1.aliyuncs.com/', // 默认存在根目录,可根据需求改
accessKeySecret: 'TSZOD1jULKPFsNp2zKhAopLe3c3AiH', // accessKeySecret 去你的阿里云上控制台上找
ossAccessKeyId: 'LTAI5tQq1bSBFCfsbvwX6DqQ', // AccessKeyId 去你的阿里云上控制台上找
timeout: 87600, // 这个是上传文件时Policy的失效时间
function parseUploadResponse(data: any): string {
const parsed = typeof data === 'string' ? JSON.parse(data || '{}') : (data || {})
if (parsed.code && parsed.code !== 200) {
throw new Error(parsed.msg || 'upload failed')
}
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)
return parsed?.data?.url || parsed?.data || parsed?.url || ''
}
// 上传图片到阿里云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')})
}
// 图片名字 可以自行定义,这里是采用当前的时间戳 + 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({
url: aliyunServerURL, // 开发者服务器 url
url: UPLOAD_ENDPOINT,
filePath: filePath, // 要上传文件资源的路径
name: 'file', // 必须填file
timeout: 20000,
formData: {
key: fileKey,
policy: policyBase64,
OSSAccessKeyId: env.ossAccessKeyId,
signature: signature,
success_action_status: '200',
header: {
clientid: CLIENT_ID,
},
formData: {},
success: function (res) {
console.log(res)
if (res.statusCode !== 200) {
reject(new Error('upload error:' + JSON.stringify(res)))
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) {
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'
const baseUrl = import.meta.env.VITE_SERVER_BASEURL
// === 👉 请在这里填写你的 AWS 信息 ===
const S3Config = {
bucket: 'cheflink', // 你的存储桶名称
region: 'us-east-1', // 桶所在区域
accessKeyId: 'AKIA3LKQVMAPD3KFPJGS',
secretKey: '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',
timeout: 0.1 // 签名有效时间(小时)
const UPLOAD_ENDPOINT = '/resource/oss/upload'
const CLIENT_ID = 'e5cd7e4891bf95d1d19206ce24a7b32e'
function parseUploadResponse(data: any): string {
const parsed = typeof data === 'string' ? JSON.parse(data || '{}') : (data || {})
if (parsed.code && parsed.code !== 200) {
throw new Error(parsed.msg || 'upload failed')
}
// === 签名函数 ===
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)
return parsed?.data?.url || parsed?.data || parsed?.url || ''
}
// === 图片压缩函数 ===
@@ -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> {
if (!filePath) {
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)
}
// 文件名
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) => {
uni.uploadFile({
url: uploadUrl,
url:baseUrl+ UPLOAD_ENDPOINT,
filePath: uploadPath,
name: 'file',
formData: {
key,
AWSAccessKeyId: S3Config.accessKeyId,
policy: policyBase64,
signature,
'Content-Type': 'image/jpeg',
header: {
clientid: CLIENT_ID,
},
formData: {},
success: res => {
if (res.statusCode === 204) {
uni.showToast({icon: 'none', title: i18n.global.t('common.operation-success')})
resolve(`${uploadUrl}${key}`)
} else {
if (res.statusCode !== 200) {
uni.showToast({icon: 'none', title: i18n.global.t('common.prompt.up-failed')})
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 => {