From ea867f72616cbdb3562503cc73ee6227dd58a3fd Mon Sep 17 00:00:00 2001 From: yanghao05 Date: Mon, 14 Apr 2025 20:53:29 +0800 Subject: [PATCH] feat: update issues --- backend/app/http/posts.go | 19 +++++++++---------- backend/providers/wepay/pay.go | 6 ++++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backend/app/http/posts.go b/backend/app/http/posts.go index fb34b15..17077e7 100644 --- a/backend/app/http/posts.go +++ b/backend/app/http/posts.go @@ -50,7 +50,7 @@ func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *Li // Buy // @Router /buy/:id [get] // @Bind id path -func (ctl *posts) Buy(ctx fiber.Ctx, id int64) (*string, error) { +func (ctl *posts) Buy(ctx fiber.Ctx, id int64) (*wepay.PrepayData, error) { var userId int64 = 1 user, err := models.Users.GetByID(ctx.Context(), userId) @@ -69,17 +69,16 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64) (*string, error) { return nil, errors.Wrap(err, "订单创建失败") } - body := ctl.wepay. - BodyMap(). - Expire(30 * time.Minute). - Description(post.Title). - OutTradeNo(order.OrderNo). - Payer(user.OpenID) - - prePayResp, err := ctl.wepay.V3TransactionJsapi(ctx.Context(), body) + prePayResp, err := ctl.wepay.V3TransactionJsapi(ctx.Context(), func(bm *wepay.BodyMap) { + bm. + Expire(30 * time.Minute). + Description(post.Title). + OutTradeNo(order.OrderNo). + Payer(user.OpenID) + }) if err != nil { log.Errorf("wepay.V3TransactionJsapi err: %v", err) return nil, errors.Wrap(err, "微信支付失败") } - return &prePayResp.Response.PrepayId, nil + return prePayResp, nil } diff --git a/backend/providers/wepay/pay.go b/backend/providers/wepay/pay.go index 81ad8a8..cef2f0c 100644 --- a/backend/providers/wepay/pay.go +++ b/backend/providers/wepay/pay.go @@ -2,6 +2,7 @@ package wepay import ( "context" + "encoding/json" "errors" "time" @@ -9,6 +10,7 @@ import ( "github.com/go-pay/gopay" "github.com/go-pay/gopay/wechat/v3" + log "github.com/sirupsen/logrus" "go.ipao.vip/atom/container" "go.ipao.vip/atom/opt" ) @@ -68,6 +70,8 @@ func (c *Client) V3TransactionJsapi(ctx context.Context, f func(*BodyMap)) (*Pre } if resp.Code != wechat.Success { + b, _ := json.Marshal(resp) + log.Errorf("WePay V3TransactionJsapi error: %s", b) return nil, errors.New(resp.Error) } @@ -77,8 +81,6 @@ func (c *Client) V3TransactionJsapi(ctx context.Context, f func(*BodyMap)) (*Pre }, nil } -func (c *Client) BodyMap() *BodyMap { return NewBodyMap(c.config) } - type BodyMap struct { bm gopay.BodyMap }