Files
sundynix-radio-be/api/v1/radio/pay.go
T
2026-03-05 16:54:25 +08:00

75 lines
1.9 KiB
Go

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)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
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)
if userId == "" || userId == "0" {
response.FailWithMsg("用户未登录", c)
return
}
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)
}