fix: mp verify

This commit is contained in:
yanghao05
2025-04-23 09:36:31 +08:00
parent 7a7bd3ff6e
commit 837941b7ec
5 changed files with 40 additions and 7 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -54,11 +54,13 @@ func Provide(opts ...opt.Option) error {
auth *auth,
pays *pays,
posts *posts,
weChat *weChat,
) (contracts.HttpRoute, error) {
obj := &Routes{
auth: auth,
pays: pays,
posts: posts,
auth: auth,
pays: pays,
posts: posts,
weChat: weChat,
}
if err := obj.Prepare(); err != nil {
return nil, err
@@ -68,5 +70,12 @@ func Provide(opts ...opt.Option) error {
}, atom.GroupRoutes); err != nil {
return err
}
if err := container.Container.Provide(func() (*weChat, error) {
obj := &weChat{}
return obj, nil
}); err != nil {
return err
}
return nil
}

View File

@@ -14,10 +14,11 @@ import (
// @provider contracts.HttpRoute atom.GroupRoutes
type Routes struct {
log *log.Entry `inject:"false"`
auth *auth
pays *pays
posts *posts
log *log.Entry `inject:"false"`
auth *auth
pays *pays
posts *posts
weChat *weChat
}
func (r *Routes) Prepare() error {
@@ -74,4 +75,10 @@ func (r *Routes) Register(router fiber.Router) {
Local[*model.Users]("user"),
))
// 注册路由组: weChat
router.Get("/MP_verify_:code.txt", Func1(
r.weChat.Verify,
PathParam[string]("code"),
))
}

View File

@@ -0,0 +1,13 @@
package http
import "github.com/gofiber/fiber/v3"
// @provider
type weChat struct{}
// Verify
// @Router /MP_verify_:code.txt [get]
// @Bind code path
func (*weChat) Verify(ctx fiber.Ctx, code string) error {
return ctx.SendString(code)
}

View File

@@ -15,6 +15,10 @@ func (f *Middlewares) Auth(ctx fiber.Ctx) error {
return ctx.Next()
}
if strings.HasPrefix(ctx.Path(), "/MP_verify_") {
return ctx.Next()
}
if strings.HasPrefix(ctx.Path(), "/v1/admin/") {
token := ctx.Get("Authorization")
if token == "" {