diff --git a/backend/app/http/posts.go b/backend/app/http/posts.go index 8fa0264..13bf360 100644 --- a/backend/app/http/posts.go +++ b/backend/app/http/posts.go @@ -269,7 +269,8 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI Expire(30 * time.Minute). Description(post.Title). OutTradeNo(order.OrderNo). - Payer(user.OpenID) + Payer(user.OpenID). + CNYAmount(post.Price * int64(post.Discount) / 100) }) if err != nil { log.Errorf("wepay.V3TransactionJsapi err: %v", err) diff --git a/backend/providers/wepay/pay.go b/backend/providers/wepay/pay.go index 115833a..bf63a7e 100644 --- a/backend/providers/wepay/pay.go +++ b/backend/providers/wepay/pay.go @@ -185,12 +185,18 @@ func (b *BodyMap) OutTradeNo(outTradeNo string) *BodyMap { } // Amount -func (b *BodyMap) Amount(total int, currency string) *BodyMap { +func (b *BodyMap) Amount(total int64, currency CURRENCY) *BodyMap { return b.SetBodyMap("amount", func(bm gopay.BodyMap) { - bm.Set("total", total).Set("currency", currency) + bm. + Set("total", total). + Set("currency", currency.String()) }) } +func (b *BodyMap) CNYAmount(total int64) *BodyMap { + return b.Amount(total, CNY) +} + // Payer func (b *BodyMap) Payer(spOpenId string) *BodyMap { return b.SetBodyMap("payer", func(bm gopay.BodyMap) { @@ -202,3 +208,15 @@ func (b *BodyMap) Payer(spOpenId string) *BodyMap { func (b *BodyMap) SubMchId(subMchId string) *BodyMap { return b.Set("sub_mchid", subMchId) } + +type CURRENCY string + +func (c CURRENCY) String() string { + return string(c) +} + +const ( + CNY CURRENCY = "CNY" + USD CURRENCY = "USD" + EUR CURRENCY = "EUR" +)