You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.7 KiB
82 lines
1.7 KiB
package routers |
|
|
|
import ( |
|
"reflect" |
|
"server/common" |
|
"server/config" |
|
"server/modules/pay/allpay" |
|
"server/modules/pay/base" |
|
"server/modules/pay/middleware" |
|
"strconv" |
|
"strings" |
|
|
|
"github.com/gin-gonic/gin" |
|
"github.com/liangdas/mqant/log" |
|
) |
|
|
|
func SetUpRouter() *gin.Engine { |
|
if config.GetBase().Release { |
|
gin.SetMode(gin.ReleaseMode) |
|
// 禁用控制台颜色 |
|
gin.DisableConsoleColor() |
|
} else { |
|
gin.SetMode(gin.DebugMode) |
|
} |
|
r := gin.New() |
|
|
|
// 跨域处理 |
|
r.Use(middleware.CrosHandler()) |
|
r.Use(gin.RecoveryWithWriter(log.LogBeego(), nil)) |
|
r.GET("/", common.HealthCheck) |
|
com := r.Group("common") |
|
commonRouter(com) |
|
cb := r.Group("callback") |
|
Callback(cb) |
|
// igeek := r.Group("igeekpay") |
|
// igeekPay(igeek) |
|
// gre := r.Group("grepay") |
|
// grePay(gre) |
|
|
|
return r |
|
} |
|
|
|
func Callback(e *gin.RouterGroup) { |
|
e.POST("pay/*action", PayCallback) |
|
e.POST("withdraw/*action", WithdrawCallback) |
|
} |
|
|
|
func PayCallback(c *gin.Context) { |
|
log.Debug("PayCallback:%+v", c.Request) |
|
path := c.Request.URL.Path |
|
path = strings.ReplaceAll(path, "/callback/pay/", "") |
|
index, err := strconv.Atoi(path) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
return |
|
} |
|
b := base.NewCallbackBase(3) |
|
allpay.NewSub(b, index) |
|
if b.Sub == nil { |
|
return |
|
} |
|
b.PayCallback(c) |
|
} |
|
|
|
func WithdrawCallback(c *gin.Context) { |
|
log.Debug("WithdrawCallback:%+v", c.Request) |
|
path := c.Request.URL.Path |
|
path = strings.ReplaceAll(path, "/callback/withdraw/", "") |
|
index, err := strconv.Atoi(path) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
return |
|
} |
|
ref := reflect.ValueOf(allpay.All).Elem().Field(index) |
|
if !ref.IsValid() { |
|
log.Error("invalid index:%v", index) |
|
return |
|
} |
|
b := base.NewCallbackBase(4) |
|
ref.Call([]reflect.Value{reflect.ValueOf(b)}) |
|
b.WithdrawCallback(c) |
|
}
|
|
|