feat: update issues
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user