feat: update issues

This commit is contained in:
yanghao05
2025-04-14 20:53:29 +08:00
parent 69e3dd1070
commit ea867f7261
2 changed files with 13 additions and 12 deletions

View File

@@ -50,7 +50,7 @@ func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
// Buy // Buy
// @Router /buy/:id [get] // @Router /buy/:id [get]
// @Bind id path // @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 var userId int64 = 1
user, err := models.Users.GetByID(ctx.Context(), userId) 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, "订单创建失败") return nil, errors.Wrap(err, "订单创建失败")
} }
body := ctl.wepay. prePayResp, err := ctl.wepay.V3TransactionJsapi(ctx.Context(), func(bm *wepay.BodyMap) {
BodyMap(). bm.
Expire(30 * time.Minute). Expire(30 * time.Minute).
Description(post.Title). Description(post.Title).
OutTradeNo(order.OrderNo). OutTradeNo(order.OrderNo).
Payer(user.OpenID) Payer(user.OpenID)
})
prePayResp, err := ctl.wepay.V3TransactionJsapi(ctx.Context(), body)
if err != nil { if err != nil {
log.Errorf("wepay.V3TransactionJsapi err: %v", err) log.Errorf("wepay.V3TransactionJsapi err: %v", err)
return nil, errors.Wrap(err, "微信支付失败") return nil, errors.Wrap(err, "微信支付失败")
} }
return &prePayResp.Response.PrepayId, nil return prePayResp, nil
} }

View File

@@ -2,6 +2,7 @@ package wepay
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"time" "time"
@@ -9,6 +10,7 @@ import (
"github.com/go-pay/gopay" "github.com/go-pay/gopay"
"github.com/go-pay/gopay/wechat/v3" "github.com/go-pay/gopay/wechat/v3"
log "github.com/sirupsen/logrus"
"go.ipao.vip/atom/container" "go.ipao.vip/atom/container"
"go.ipao.vip/atom/opt" "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 { if resp.Code != wechat.Success {
b, _ := json.Marshal(resp)
log.Errorf("WePay V3TransactionJsapi error: %s", b)
return nil, errors.New(resp.Error) return nil, errors.New(resp.Error)
} }
@@ -77,8 +81,6 @@ func (c *Client) V3TransactionJsapi(ctx context.Context, f func(*BodyMap)) (*Pre
}, nil }, nil
} }
func (c *Client) BodyMap() *BodyMap { return NewBodyMap(c.config) }
type BodyMap struct { type BodyMap struct {
bm gopay.BodyMap bm gopay.BodyMap
} }