mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-28 02:41:57 +08:00
Feat: vas alipay
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/HFO4/cloudreve/pkg/payment"
|
||||
"github.com/HFO4/cloudreve/pkg/util"
|
||||
"github.com/HFO4/cloudreve/service/vas"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/smartwalle/alipay/v3"
|
||||
)
|
||||
|
||||
// GetQuota 获取容量配额信息
|
||||
@@ -38,6 +41,17 @@ func NewOrder(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// OrderStatus 查询订单状态
|
||||
func OrderStatus(c *gin.Context) {
|
||||
var service vas.OrderService
|
||||
if err := c.ShouldBindUri(&service); err == nil {
|
||||
res := service.Status(c, CurrentUser(c))
|
||||
c.JSON(200, res)
|
||||
} else {
|
||||
c.JSON(200, ErrorResponse(err))
|
||||
}
|
||||
}
|
||||
|
||||
// GetRedeemInfo 获取兑换码信息
|
||||
func GetRedeemInfo(c *gin.Context) {
|
||||
var service vas.RedeemService
|
||||
@@ -59,3 +73,30 @@ func DoRedeem(c *gin.Context) {
|
||||
c.JSON(200, ErrorResponse(err))
|
||||
}
|
||||
}
|
||||
|
||||
// AlipayCallback 支付宝回调
|
||||
func AlipayCallback(c *gin.Context) {
|
||||
pay, err := payment.NewPaymentInstance("alipay")
|
||||
if err != nil {
|
||||
util.Log().Debug("[支付宝回调] 无法创建支付宝客户端, %s", err)
|
||||
c.Status(400)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := pay.(*payment.Alipay).Client.GetTradeNotification(c.Request)
|
||||
if err != nil {
|
||||
util.Log().Debug("[支付宝回调] 回调验证失败, %s", err)
|
||||
c.Status(403)
|
||||
return
|
||||
}
|
||||
|
||||
if res != nil && res.TradeStatus == "TRADE_SUCCESS" {
|
||||
// 支付成功
|
||||
if err := payment.OrderPaid(res.OutTradeNo); err != nil {
|
||||
util.Log().Debug("[支付宝回调] 支付处理失败, %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 确认收到通知消息
|
||||
alipay.AckNotification(c.Writer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user