feat: complete wechat pay

This commit is contained in:
Rogee
2025-04-30 19:26:53 +08:00
parent 11288471d4
commit 67d6f3ec33
10 changed files with 44 additions and 21 deletions

View File

@@ -23,7 +23,7 @@ type pays struct {
// Callback
//
// @Router /pay/callback/:channel [get]
// @Router /pay/callback/:channel [post]
// @Bind channel path
func (ctl *pays) Callback(ctx fiber.Ctx, channel string) error {
log := log.WithField("method", "pays.Callback")

View File

@@ -241,7 +241,7 @@ func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
// Buy
//
// @Router /posts/:id/buy [get]
// @Router /posts/:id/buy [post]
// @Bind id path
// @Bind user local
func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPIPayParams, error) {

View File

@@ -46,7 +46,7 @@ func (r *Routes) Register(router fiber.Router) {
))
// 注册路由组: pays
router.Get("/pay/callback/:channel", Func1(
router.Post("/pay/callback/:channel", Func1(
r.pays.Callback,
PathParam[string]("channel"),
))
@@ -78,7 +78,7 @@ func (r *Routes) Register(router fiber.Router) {
Local[*model.Users]("user"),
))
router.Get("/posts/:id/buy", DataFunc2(
router.Post("/posts/:id/buy", DataFunc2(
r.posts.Buy,
PathParam[int64]("id"),
Local[*model.Users]("user"),

View File

@@ -21,7 +21,7 @@ type wechats struct {
// @Bind url query
// @Bind user local
func (ctl *wechats) GetJsSDK(ctx fiber.Ctx, url string, user *model.Users) (*wechat.JsSDK, error) {
if user.AuthToken.Data.StableExpiresAt.After(time.Now()) {
if user.AuthToken.Data.StableExpiresAt.Before(time.Now()) {
token, err := ctl.wechat.RefreshAccessToken(user.AuthToken.Data.RefreshToken)
if err != nil {
return nil, err