110 lines
3.4 KiB
Go
110 lines
3.4 KiB
Go
package routes
|
|
|
|
/**
|
|
* 配置路由
|
|
*/
|
|
import (
|
|
"PaymentCenter/app/constants/common"
|
|
"PaymentCenter/app/http/controllers"
|
|
"PaymentCenter/app/http/controllers/front"
|
|
"PaymentCenter/app/http/middlewares"
|
|
"PaymentCenter/app/http/trace"
|
|
"PaymentCenter/app/utils/metric"
|
|
"PaymentCenter/config"
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
|
"github.com/swaggo/gin-swagger/swaggerFiles"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/qit-team/snow-core/http/middleware"
|
|
"github.com/qit-team/snow-core/log/logger"
|
|
)
|
|
|
|
// api路由配置
|
|
func RegisterRoute(router *gin.Engine) {
|
|
//middleware: 服务错误处理 => 生成请求id => access log
|
|
router.Use(middlewares.ServerRecovery(), middleware.GenRequestId, middleware.GenContextKit, middleware.AccessLog())
|
|
|
|
if config.GetConf().PrometheusCollectEnable && config.IsEnvEqual(config.ProdEnv) {
|
|
router.Use(middlewares.CollectMetric())
|
|
metric.Init(metric.EnableRuntime(), metric.EnableProcess())
|
|
metricHandler := metric.Handler()
|
|
router.GET("/metrics", func(ctx *gin.Context) {
|
|
metricHandler.ServeHTTP(ctx.Writer, ctx.Request)
|
|
})
|
|
}
|
|
|
|
if len(config.GetConf().SkyWalkingOapServer) > 0 && config.IsEnvEqual(config.ProdEnv) {
|
|
err := trace.InitTracer(config.GetConf().ServiceName, config.GetConf().SkyWalkingOapServer)
|
|
if err != nil {
|
|
logger.Error(nil, "InitTracer", err.Error())
|
|
} else {
|
|
router.Use(middlewares.Trace())
|
|
}
|
|
}
|
|
|
|
router.Use(middlewares.Cors())
|
|
router.NoRoute(controllers.Error404)
|
|
|
|
//router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
|
|
v1 := router.Group(common.FRONT_V1)
|
|
{
|
|
//回调处理
|
|
notify := v1.Group("/notify")
|
|
{
|
|
notify.POST("/wx/:payChannelId", front.WxCallback)
|
|
notify.POST("/ali/:payChannelId", front.AliCallback)
|
|
}
|
|
|
|
pay := v1.Group("/pay", middlewares.ValidatePayRequest())
|
|
{
|
|
pay.POST("/url", front.PayUrl)
|
|
pay.POST("/query", front.QueryOrder) //查询订单
|
|
pay.POST("/refund", front.Refund)
|
|
pay.POST("/close", front.CloseOrder)
|
|
}
|
|
// 测试微信支付唤起
|
|
v1.GET("/brokerWechatUrl", front.BrokerWechatUrl)
|
|
}
|
|
|
|
// 微信获取授权相关
|
|
router.LoadHTMLGlob("./front/templates/*")
|
|
wx := v1.Group("/wx", middlewares.ValidateRequest())
|
|
{
|
|
wx.POST("/getWxAuthUrl", front.GetWxAuthUrl) // 获取授权codeUrl
|
|
wx.GET("/getWxAuth", front.GetWxAuth) // 获取openId
|
|
wx.GET("/getCode", front.GetWxCode) // 接收微信code
|
|
}
|
|
|
|
// 微信jsapi支付链接
|
|
router.GET(common.WXCodeRedirectAddress, middlewares.ValidateRequest(), front.WxJsApiPay)
|
|
|
|
v2 := router.Group(common.FRONT_V2)
|
|
{
|
|
pay := v2.Group("/pay", middlewares.ValidatePayRequest())
|
|
// V2下单,存订单信息,返回收银台地址
|
|
pay.POST("/url", front.PayUrlV2)
|
|
}
|
|
|
|
//收银台
|
|
{
|
|
// 收银台地址
|
|
router.GET(common.PayPageAddress, front.PayPage)
|
|
|
|
payPage := router.Group(common.PayPageAddress, middlewares.ValidateRequest())
|
|
// 收银台 支付渠道列表
|
|
payPage.POST("/list", front.PayChannelList)
|
|
// 获取付款链接
|
|
payPage.GET("/submit", front.GetPayLink)
|
|
|
|
//router.GET(common.PayPageAddress, middlewares.ValidateRequest(), front.PayPage)
|
|
//// 收银台 支付渠道列表
|
|
//router.POST(common.FRONT_V1+"/payPage/list", middlewares.ValidateRequest(), front.PayChannelList)
|
|
//// 获取付款链接
|
|
//v1.POST("/payPage/link", middlewares.ValidateRequest(), front.GetPayLink)
|
|
}
|
|
|
|
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
|
|
}
|