feat: 支付闭环
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package radio
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/utils/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type PayApi struct{}
|
||||
|
||||
// PrePay 预支付
|
||||
// @Tags 微信支付
|
||||
// @Summary 支付
|
||||
// @Security ApiKeyAuth
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param orderId query string true "支付"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"支付成功"}"
|
||||
// @Router /pay/prePay [get]
|
||||
func (a *PayApi) PrePay(c *gin.Context) {
|
||||
orderId := c.Query("orderId")
|
||||
userId := auth.GetUserId(c)
|
||||
res, err := payService.PrePay(orderId, userId)
|
||||
if err != nil {
|
||||
global.Logger.Error("支付失败", zap.Error(err))
|
||||
response.FailWithMsg("支付失败:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(res, c)
|
||||
}
|
||||
|
||||
// QueryPay 查询支付
|
||||
// @Tags 微信支付
|
||||
// @Summary 支付
|
||||
// @Security BasicAuth
|
||||
// @Produce application/json
|
||||
// @Param orderId query string true "支付"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"支付成功"}"
|
||||
// @Router /pay/query [get]
|
||||
func (a *PayApi) QueryPay(c *gin.Context) {
|
||||
outTradeNo := c.Query("outTradeNo")
|
||||
userId := auth.GetUserId(c)
|
||||
res, err := payService.QueryPay(outTradeNo, userId)
|
||||
if err != nil {
|
||||
global.Logger.Error("支付失败", zap.Error(err))
|
||||
response.FailWithMsg("支付失败:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(res, c)
|
||||
}
|
||||
|
||||
// PayCallback 支付回调
|
||||
// @Tags 微信支付
|
||||
// @Summary 支付回调
|
||||
func (a *PayApi) PayCallback(c *gin.Context) {
|
||||
err := payService.PayCallback(c)
|
||||
if err != nil {
|
||||
global.Logger.Error("支付回调失败", zap.Error(err))
|
||||
response.FailWithMsg("支付回调失败:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("支付回调成功", c)
|
||||
}
|
||||
Reference in New Issue
Block a user