style: rename some func
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
package app
|
||||
|
||||
// Version 版本号说明 1.0.0 代表主版本号.功能版本号.修订号
|
||||
const Version = "1.14.1"
|
||||
const Version = "1.14.2"
|
||||
|
||||
+2
-2
@@ -10,8 +10,8 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// EpaySubmit 【兼容】易支付提交
|
||||
func EpaySubmit(ctx *gin.Context) {
|
||||
// epaySubmit 【兼容】易支付提交
|
||||
func epaySubmit(ctx *gin.Context) {
|
||||
if err := ctx.Request.ParseForm(); err != nil {
|
||||
ctx.String(200, "参数解析错误:"+err.Error())
|
||||
|
||||
|
||||
+8
-8
@@ -14,8 +14,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// CreateTransaction 创建订单
|
||||
func CreateTransaction(ctx *gin.Context) {
|
||||
// createTransaction 创建订单
|
||||
func createTransaction(ctx *gin.Context) {
|
||||
_data, _ := ctx.Get("data")
|
||||
data := _data.(map[string]any)
|
||||
orderId, ok1 := data["order_id"].(string)
|
||||
@@ -29,7 +29,7 @@ func CreateTransaction(ctx *gin.Context) {
|
||||
// ---
|
||||
if !ok1 || !ok2 || !ok3 || !ok4 {
|
||||
log.Warn("参数错误", data)
|
||||
ctx.JSON(200, RespFailJson(fmt.Errorf("参数错误")))
|
||||
ctx.JSON(200, respFailJson(fmt.Errorf("参数错误")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -41,13 +41,13 @@ func CreateTransaction(ctx *gin.Context) {
|
||||
|
||||
var order, err = buildOrder(money, model.OrderApiTypeEpusdt, orderId, tradeType, redirectUrl, notifyUrl, orderId)
|
||||
if err != nil {
|
||||
ctx.JSON(200, RespFailJson(fmt.Errorf("订单创建失败:%w", err)))
|
||||
ctx.JSON(200, respFailJson(fmt.Errorf("订单创建失败:%w", err)))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 返回响应数据
|
||||
ctx.JSON(200, RespSuccJson(gin.H{
|
||||
ctx.JSON(200, respSuccJson(gin.H{
|
||||
"trade_id": order.TradeId,
|
||||
"order_id": orderId,
|
||||
"amount": money,
|
||||
@@ -116,7 +116,7 @@ func buildOrder(money float64, apiType, orderId, tradeType, redirectUrl, notifyU
|
||||
return tradeOrder, nil
|
||||
}
|
||||
|
||||
func CheckoutCounter(ctx *gin.Context) {
|
||||
func checkoutCounter(ctx *gin.Context) {
|
||||
var tradeId = ctx.Param("trade_id")
|
||||
var order, ok = model.GetTradeOrder(tradeId)
|
||||
if !ok {
|
||||
@@ -144,11 +144,11 @@ func CheckoutCounter(ctx *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func CheckStatus(ctx *gin.Context) {
|
||||
func checkStatus(ctx *gin.Context) {
|
||||
var tradeId = ctx.Param("trade_id")
|
||||
var order, ok = model.GetTradeOrder(tradeId)
|
||||
if !ok {
|
||||
ctx.JSON(200, RespFailJson(fmt.Errorf("订单不存在")))
|
||||
ctx.JSON(200, respFailJson(fmt.Errorf("订单不存在")))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
+5
-18
@@ -2,25 +2,12 @@ package web
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type Response struct {
|
||||
StatusCode int `json:"status_code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
RequestID string `json:"request_id"`
|
||||
func respFailJson(err error) gin.H {
|
||||
|
||||
return gin.H{"status_code": 400, "message": err.Error()}
|
||||
}
|
||||
|
||||
func RespFailJson(err error) gin.H {
|
||||
return gin.H{
|
||||
"status_code": 400,
|
||||
"message": err.Error(),
|
||||
}
|
||||
}
|
||||
func respSuccJson(data interface{}) gin.H {
|
||||
|
||||
func RespSuccJson(data interface{}) gin.H {
|
||||
return gin.H{
|
||||
"status_code": 200,
|
||||
"message": "success",
|
||||
"data": data,
|
||||
"request_id": "",
|
||||
}
|
||||
return gin.H{"status_code": 200, "message": "success", "data": data, "request_id": ""}
|
||||
}
|
||||
|
||||
+4
-4
@@ -36,9 +36,9 @@ func Start() {
|
||||
payRoute := r.Group("/pay")
|
||||
{
|
||||
// 收银台
|
||||
payRoute.GET("/checkout-counter/:trade_id", CheckoutCounter)
|
||||
payRoute.GET("/checkout-counter/:trade_id", checkoutCounter)
|
||||
// 状态检测
|
||||
payRoute.GET("/check-status/:trade_id", CheckStatus)
|
||||
payRoute.GET("/check-status/:trade_id", checkStatus)
|
||||
}
|
||||
|
||||
// 创建订单
|
||||
@@ -75,11 +75,11 @@ func Start() {
|
||||
|
||||
ctx.Set("data", m)
|
||||
})
|
||||
orderRoute.POST("/create-transaction", CreateTransaction)
|
||||
orderRoute.POST("/create-transaction", createTransaction)
|
||||
}
|
||||
|
||||
// 易支付兼容
|
||||
r.POST("/submit.php", EpaySubmit)
|
||||
r.POST("/submit.php", epaySubmit)
|
||||
|
||||
log.Info("WEB尝试启动 Listen: ", listen)
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user