From 3dc9bc5b1d741ec5b94a7d9deaf978303e5ad130 Mon Sep 17 00:00:00 2001 From: luorijun Date: Wed, 11 Mar 2026 13:08:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=AE=98=E6=96=B9=E6=89=8B=E6=9C=BA=E7=AB=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docker-deployment.md | 90 --------------------------------------- web/globals/wechatpay.go | 3 ++ web/services/trade.go | 19 +++++++++ 3 files changed, 22 insertions(+), 90 deletions(-) delete mode 100644 docs/docker-deployment.md diff --git a/docs/docker-deployment.md b/docs/docker-deployment.md deleted file mode 100644 index d40a747..0000000 --- a/docs/docker-deployment.md +++ /dev/null @@ -1,90 +0,0 @@ -# Docker 部署说明 - -本文档说明如何使用 Docker 构建和部署平台服务。 - -## 构建镜像 - -在项目根目录下执行以下命令构建 Docker 镜像: - -```bash -docker build -t platform:latest . -``` - -## 生产环境部署 - -由于涉及敏感的 `.pem` 证书文件,这些文件不包含在代码库或 Docker 镜像中,而是在运行时通过卷挂载的方式提供。 - -### 准备证书文件 - -1. 在生产服务器上创建一个目录用于存放证书文件,例如:`/path/to/certs/` -2. 将必要的证书文件放入此目录: - - `pub_key.pem` - - `apiclient_key.pem` - -### 运行容器 - -使用以下命令运行容器,挂载证书目录: - -```bash -docker run -d \ - --name platform \ - -p 8080:8080 \ - -e APP_PORT=8080 \ - -v /path/to/certs:/app/certs \ - platform:latest -``` - -### 环境变量 - -可以通过环境变量来配置应用程序: - -- `APP_PORT`: 应用监听的端口号(默认: 8080) -- 其他应用相关的环境变量可以通过 `-e` 参数添加 - -### 证书路径配置 - -如果应用程序需要知道证书的路径,可以通过环境变量配置: - -```bash -docker run -d \ - --name platform \ - -p 8080:8080 \ - -e APP_PORT=8080 \ - -e PUB_KEY_PATH=/app/certs/pub_key.pem \ - -e APICLIENT_KEY_PATH=/app/certs/apiclient_key.pem \ - -v /path/to/certs:/app/certs \ - platform:latest -``` - -## 使用 Docker Compose - -也可以通过 Docker Compose 进行部署,创建 `docker-compose.yml` 文件: - -```yaml -version: '3' - -services: - platform: - image: platform:latest - ports: - - "8080:8080" - environment: - - APP_PORT=8080 - - PUB_KEY_PATH=/app/certs/pub_key.pem - - APICLIENT_KEY_PATH=/app/certs/apiclient_key.pem - volumes: - - /path/to/certs:/app/certs - restart: unless-stopped -``` - -然后执行: - -```bash -docker-compose up -d -``` - -## 安全建议 - -1. 确保证书文件的权限设置正确,仅允许必要的用户访问 -2. 在生产环境中考虑使用 Docker Secrets 或 Kubernetes Secrets 来管理敏感信息 -3. 定期更新证书和密钥 \ No newline at end of file diff --git a/web/globals/wechatpay.go b/web/globals/wechatpay.go index 04dde53..ed02480 100644 --- a/web/globals/wechatpay.go +++ b/web/globals/wechatpay.go @@ -10,6 +10,7 @@ import ( "github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers" "github.com/wechatpay-apiv3/wechatpay-go/core/notify" "github.com/wechatpay-apiv3/wechatpay-go/core/option" + "github.com/wechatpay-apiv3/wechatpay-go/services/partnerpayments/h5" "github.com/wechatpay-apiv3/wechatpay-go/services/payments/native" "github.com/wechatpay-apiv3/wechatpay-go/utils" ) @@ -18,6 +19,7 @@ var WechatPay *WechatPayClient type WechatPayClient struct { Native *native.NativeApiService + H5 *h5.H5ApiService Notify *notify.Handler } @@ -71,6 +73,7 @@ func initWechatPay() error { // 创建 WechatPay 服务 WechatPay = &WechatPayClient{ Native: &native.NativeApiService{Client: client}, + H5: &h5.H5ApiService{Client: client}, Notify: handler, } return nil diff --git a/web/services/trade.go b/web/services/trade.go index 1ff40f1..d0f8f10 100644 --- a/web/services/trade.go +++ b/web/services/trade.go @@ -21,6 +21,7 @@ import ( wecahtpaycore "github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/smartwalle/alipay/v3" + "github.com/wechatpay-apiv3/wechatpay-go/services/partnerpayments/h5" "github.com/wechatpay-apiv3/wechatpay-go/services/payments/native" "gorm.io/gorm" ) @@ -150,6 +151,24 @@ func (s *tradeService) CreateTrade(uid int32, now time.Time, data *CreateTradeDa } paymentUrl = *resp.CodeUrl + // 微信 + 手机网站 + case method == m.TradeMethodWechat && platform == m.TradePlatformMobile: + resp, _, err := g.WechatPay.H5.Prepay(context.Background(), h5.PrepayRequest{ + SpAppid: &env.WechatPayAppId, + SpMchid: &env.WechatPayMchId, + OutTradeNo: &tradeNo, + Description: &subject, + TimeExpire: &expire, + NotifyUrl: &env.WechatPayCallbackUrl, + Amount: &h5.Amount{ + Total: u.P(amountReal.Mul(decimal.NewFromInt(100)).Round(0).IntPart()), + }, + }) + if err != nil { + return nil, err + } + paymentUrl = *resp.H5Url + // 商福通 + 电脑网站 case method == m.TradeMethodSftAlipay && platform == m.TradePlatformPC,