Files
pay/internal/util/idgen.go
T
wangjia 6da6964451 初始提交:岩美 pay 收款服务(支付宝当面付 + 多商户多渠道架构)
- Go/Gin/GORM + 纯 Go SQLite(无 cgo)
- Channel 多渠道接口:支付宝当面付(precreate)/电脑网站支付(page.pay) 已实现,微信占位
- 多商户 merchants 表,回调验签+金额核对+幂等+查单兜底
- 收款页/结果页/二维码端点;docs/ 设计文档与部署 Runbook
- 密钥走环境变量/Bitwarden,不入库

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 07:21:48 +08:00

22 lines
498 B
Go

package util
import (
"fmt"
"strings"
"time"
"github.com/google/uuid"
)
// NewOutTradeNo 生成全局唯一的商户订单号:<code>-<时间>-<随机>,控制在 64 字符内。
// 例:yanmei-20260624153012-a1b2c3d4
func NewOutTradeNo(merchantCode string) string {
code := merchantCode
if len(code) > 16 {
code = code[:16]
}
ts := time.Now().Format("20060102150405")
suffix := strings.ReplaceAll(uuid.NewString(), "-", "")[:8]
return fmt.Sprintf("%s-%s-%s", code, ts, suffix)
}