Integrate WeChat Official Account support and update configuration
- Added WeChat Official Account configuration options to .env.example and config.go for OAuth2 integration. - Updated main.go to initialize WeChat OAuth handler and register routes for handling OAuth requests. - Enhanced documentation to include references for WeChat Official Account functionality. - Updated route registration to accommodate the new OAuth handler for improved API structure.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
authhandler "wx_service/internal/common/auth/handler"
|
||||
qiniuhandler "wx_service/internal/common/qiniu/handler"
|
||||
oahandler "wx_service/internal/common/wechat_official/handler"
|
||||
"wx_service/internal/middleware"
|
||||
rmhandler "wx_service/internal/remove_watermark/handler"
|
||||
smokehandler "wx_service/internal/smoke/handler"
|
||||
@@ -20,6 +21,7 @@ func Register(
|
||||
videoHandler *rmhandler.VideoHandler,
|
||||
smokeHandler *smokehandler.SmokeHandler,
|
||||
uploadHandler *qiniuhandler.UploadHandler,
|
||||
oaOAuthHandler *oahandler.OAuthHandler,
|
||||
) {
|
||||
// Register 用来集中注册所有 HTTP 路由,便于工程结构更清晰:
|
||||
// - main 只负责初始化(配置/DB/依赖注入)
|
||||
@@ -29,6 +31,9 @@ func Register(
|
||||
// 登录接口:用微信 code 换取/创建用户并返回 session_key(作为后续 Bearer Token)
|
||||
api.POST("/auth/login", authHandler.LoginWithWeChat)
|
||||
|
||||
// 公众号网页授权:不需要登录(code 本身来自微信授权回调)
|
||||
registerWeChatOfficialRoutes(api, oaOAuthHandler)
|
||||
|
||||
// 需要登录的接口组:统一挂载鉴权中间件
|
||||
protected := api.Group("")
|
||||
protected.Use(middleware.AuthMiddleware(db))
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
oahandler "wx_service/internal/common/wechat_official/handler"
|
||||
)
|
||||
|
||||
func registerWeChatOfficialRoutes(api *gin.RouterGroup, oauthHandler *oahandler.OAuthHandler) {
|
||||
// 微信公众号(网页授权 OAuth2)
|
||||
oa := api.Group("/wechat/official")
|
||||
{
|
||||
oa.POST("/oauth/code2user", oauthHandler.CodeToUser)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user