fd5f56f7de
- 微信支付 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
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/skip2/go-qrcode"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/wangjia/pay/internal/model"
|
|
"github.com/wangjia/pay/internal/util"
|
|
)
|
|
|
|
type PageHandler struct {
|
|
db *gorm.DB
|
|
webDir string
|
|
}
|
|
|
|
func NewPageHandler(db *gorm.DB, webDir string) *PageHandler {
|
|
return &PageHandler{db: db, webDir: webDir}
|
|
}
|
|
|
|
// ResultPage GET /result —— 支付结果页(return_url 落地)。
|
|
func (h *PageHandler) ResultPage(c *gin.Context) {
|
|
c.File(h.webDir + "/result.html")
|
|
}
|
|
|
|
// QRCode GET /qrcode?text=xxx —— 把任意字符串渲染成二维码 PNG(用于展示支付宝扫码码串)。
|
|
func (h *PageHandler) QRCode(c *gin.Context) {
|
|
text := c.Query("text")
|
|
if text == "" {
|
|
util.RespondError(c, http.StatusBadRequest, "bad_request", "缺少 text 参数")
|
|
return
|
|
}
|
|
png, err := qrcode.Encode(text, qrcode.Medium, 256)
|
|
if err != nil {
|
|
util.RespondError(c, http.StatusInternalServerError, "qr_failed", err.Error())
|
|
return
|
|
}
|
|
c.Data(http.StatusOK, "image/png", png)
|
|
}
|
|
|
|
// ListProducts GET /api/v1/products —— 上架套餐列表(金额来自服务端)。
|
|
func (h *PageHandler) ListProducts(c *gin.Context) {
|
|
var products []model.Product
|
|
if err := h.db.Where("active = ?", true).Order("sort asc, id asc").Find(&products).Error; err != nil {
|
|
util.RespondError(c, http.StatusInternalServerError, "list_failed", err.Error())
|
|
return
|
|
}
|
|
out := make([]gin.H, 0, len(products))
|
|
for _, p := range products {
|
|
out = append(out, gin.H{
|
|
"id": p.ID,
|
|
"name": p.Name,
|
|
"description": p.Description,
|
|
"price": p.Price,
|
|
"biz_code": p.BizCode, // 业务方按 biz_code 查 product_id
|
|
})
|
|
}
|
|
util.RespondSuccess(c, out)
|
|
}
|