Files
wangjia fd5f56f7de feat: 微信V3 + 支付宝手机站/UA自适应 + 业务对接(签名下单/webhook) + 通用多业务
- 微信支付 V3 Native 渠道 (wechat.go):Native下单/回调AES-GCM解密验签/查单
- 支付宝:手机网站支付 wap.pay + 按 UA 自适应(PC page.pay扫码 / 手机拉App);qr_pay_mode=2 完整扫码收银台
- 业务对接:下单接口扩展(biz_system/biz_ref/return_url)+ HMAC 签名鉴权;支付成功 webhook 主动推送业务方 + 60s 重试 + BizNotifyLog
- 通用多业务:config.biz 改 map,加业务只改配置(BIZ_<SYS>_SECRET/_CALLBACK_URL)
- seedPlans:四档真实套餐 + promo_first_month(¥1) + test_liandiao(0.01),均挂 biz_code;/products 暴露 biz_code
- 删除沙箱 pay.html;对接设计文档入 docs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019UQmqWmV67sXGLrb3U1XXn
2026-07-03 22:44:34 +08:00

37 lines
985 B
Go

package util
import (
"fmt"
"math"
"strconv"
"strings"
)
// AmountToCents 把 "0.01" / "12.30" 元金额转为分(int64),便于精确比较。
func AmountToCents(s string) (int64, error) {
s = strings.TrimSpace(s)
if s == "" {
return 0, fmt.Errorf("空金额")
}
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return 0, fmt.Errorf("金额格式错误 %q: %w", s, err)
}
if f < 0 {
return 0, fmt.Errorf("金额不能为负: %q", s)
}
return int64(math.Round(f * 100)), nil
}
// CentsToAmount 把分(int64)转回 "0.01" 元字符串(微信接口用分,本服务统一用元字符串)。
func CentsToAmount(cents int64) string {
return strconv.FormatFloat(float64(cents)/100, 'f', 2, 64)
}
// AmountEqual 判断两个元金额字符串是否等值(按分比较,避免浮点/格式差异)。
func AmountEqual(a, b string) bool {
ca, err1 := AmountToCents(a)
cb, err2 := AmountToCents(b)
return err1 == nil && err2 == nil && ca == cb
}