106 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package routes
 | ||
| 
 | ||
| import (
 | ||
| 	"go.uber.org/zap"
 | ||
| 
 | ||
| 	"tyapi-server/internal/infrastructure/http/handlers"
 | ||
| 	"tyapi-server/internal/shared/http"
 | ||
| 	"tyapi-server/internal/shared/middleware"
 | ||
| )
 | ||
| 
 | ||
| // CertificationRoutes 认证路由
 | ||
| type CertificationRoutes struct {
 | ||
| 	handler        *handlers.CertificationHandler
 | ||
| 	router         *http.GinRouter
 | ||
| 	logger         *zap.Logger
 | ||
| 	auth           *middleware.JWTAuthMiddleware
 | ||
| 	optional       *middleware.OptionalAuthMiddleware
 | ||
| 	dailyRateLimit *middleware.DailyRateLimitMiddleware
 | ||
| }
 | ||
| 
 | ||
| // NewCertificationRoutes 创建认证路由
 | ||
| func NewCertificationRoutes(
 | ||
| 	handler *handlers.CertificationHandler,
 | ||
| 	router *http.GinRouter,
 | ||
| 	logger *zap.Logger,
 | ||
| 	auth *middleware.JWTAuthMiddleware,
 | ||
| 	optional *middleware.OptionalAuthMiddleware,
 | ||
| 	dailyRateLimit *middleware.DailyRateLimitMiddleware,
 | ||
| ) *CertificationRoutes {
 | ||
| 	return &CertificationRoutes{
 | ||
| 		handler:        handler,
 | ||
| 		router:         router,
 | ||
| 		logger:         logger,
 | ||
| 		auth:           auth,
 | ||
| 		optional:       optional,
 | ||
| 		dailyRateLimit: dailyRateLimit,
 | ||
| 	}
 | ||
| }
 | ||
| 
 | ||
| // Register 注册认证路由
 | ||
| func (r *CertificationRoutes) Register(router *http.GinRouter) {
 | ||
| 	// 认证管理路由组
 | ||
| 	certificationGroup := router.GetEngine().Group("/api/v1/certifications")
 | ||
| 	{
 | ||
| 		// 需要认证的路由
 | ||
| 		authGroup := certificationGroup.Group("")
 | ||
| 		authGroup.Use(r.auth.Handle())
 | ||
| 		{
 | ||
| 			authGroup.GET("", r.handler.ListCertifications) // 查询认证列表(管理员)
 | ||
| 
 | ||
| 			// 1. 获取认证详情
 | ||
| 			authGroup.GET("/details", r.handler.GetCertification)
 | ||
| 
 | ||
| 			// 2. 提交企业信息(应用每日限流)
 | ||
| 			authGroup.POST("/enterprise-info", r.dailyRateLimit.Handle(), r.handler.SubmitEnterpriseInfo)
 | ||
| 
 | ||
| 			// OCR营业执照识别接口
 | ||
| 			authGroup.POST("/ocr/business-license", r.handler.RecognizeBusinessLicense)
 | ||
| 
 | ||
| 			// 3. 申请合同签署
 | ||
| 			authGroup.POST("/apply-contract", r.handler.ApplyContract)
 | ||
| 
 | ||
| 			// 前端确认是否完成认证
 | ||
| 			authGroup.POST("/confirm-auth", r.handler.ConfirmAuth)
 | ||
| 
 | ||
| 			// 前端确认是否完成签署
 | ||
| 			authGroup.POST("/confirm-sign", r.handler.ConfirmSign)
 | ||
| 
 | ||
| 		}
 | ||
| 
 | ||
| 		// 回调路由(不需要认证,但需要验证签名)
 | ||
| 		callbackGroup := certificationGroup.Group("/callbacks")
 | ||
| 		{
 | ||
| 			callbackGroup.POST("/esign", r.handler.HandleEsignCallback) // e签宝回调(统一处理企业认证和合同签署回调)
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 	r.logger.Info("认证路由注册完成")
 | ||
| }
 | ||
| 
 | ||
| // GetRoutes 获取路由信息(用于调试)
 | ||
| func (r *CertificationRoutes) GetRoutes() []RouteInfo {
 | ||
| 	return []RouteInfo{
 | ||
| 		{Method: "POST", Path: "/api/v1/certifications", Handler: "CreateCertification", Auth: true},
 | ||
| 		{Method: "GET", Path: "/api/v1/certifications/:id", Handler: "GetCertification", Auth: true},
 | ||
| 		{Method: "GET", Path: "/api/v1/certifications/user", Handler: "GetUserCertifications", Auth: true},
 | ||
| 		{Method: "GET", Path: "/api/v1/certifications", Handler: "ListCertifications", Auth: true},
 | ||
| 		{Method: "GET", Path: "/api/v1/certifications/statistics", Handler: "GetCertificationStatistics", Auth: true},
 | ||
| 		{Method: "POST", Path: "/api/v1/certifications/:id/enterprise-info", Handler: "SubmitEnterpriseInfo", Auth: true},
 | ||
| 		{Method: "POST", Path: "/api/v1/certifications/ocr/business-license", Handler: "RecognizeBusinessLicense", Auth: true},
 | ||
| 		{Method: "POST", Path: "/api/v1/certifications/apply-contract", Handler: "ApplyContract", Auth: true},
 | ||
| 		{Method: "POST", Path: "/api/v1/certifications/retry", Handler: "RetryOperation", Auth: true},
 | ||
| 		{Method: "POST", Path: "/api/v1/certifications/force-transition", Handler: "ForceTransitionStatus", Auth: true},
 | ||
| 		{Method: "GET", Path: "/api/v1/certifications/monitoring", Handler: "GetSystemMonitoring", Auth: true},
 | ||
| 		{Method: "POST", Path: "/api/v1/certifications/callbacks/esign", Handler: "HandleEsignCallback", Auth: false},
 | ||
| 	}
 | ||
| }
 | ||
| 
 | ||
| // RouteInfo 路由信息
 | ||
| type RouteInfo struct {
 | ||
| 	Method  string
 | ||
| 	Path    string
 | ||
| 	Handler string
 | ||
| 	Auth    bool
 | ||
| }
 |