feat: add callback
This commit is contained in:
50
backend/app/http/pays.go
Normal file
50
backend/app/http/pays.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"quyun/providers/wepay"
|
||||
|
||||
"github.com/go-pay/gopay"
|
||||
"github.com/go-pay/gopay/wechat/v3"
|
||||
"github.com/go-pay/util/js"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
type pays struct {
|
||||
wepay *wepay.Client
|
||||
}
|
||||
|
||||
// Callback
|
||||
// @Router /pay/callback [get]
|
||||
func (ctl *pays) Callback(ctx fiber.Ctx) error {
|
||||
body := ctx.Body()
|
||||
si := &wechat.SignInfo{
|
||||
HeaderTimestamp: ctx.Get(wechat.HeaderTimestamp),
|
||||
HeaderNonce: ctx.Get(wechat.HeaderNonce),
|
||||
HeaderSignature: ctx.Get(wechat.HeaderSignature),
|
||||
HeaderSerial: ctx.Get(wechat.HeaderSerial),
|
||||
SignBody: string(body),
|
||||
}
|
||||
notifyReq := &wechat.V3NotifyReq{SignInfo: si}
|
||||
if err := js.UnmarshalBytes(body, notifyReq); err != nil {
|
||||
return ctx.Status(http.StatusBadRequest).JSON(fiber.Map{"error": fmt.Sprintf("json unmarshal error:%v", err)})
|
||||
}
|
||||
|
||||
// 获取微信平台证书
|
||||
certMap := ctl.wepay.WxPublicKeyMap()
|
||||
|
||||
// 验证异步通知的签名
|
||||
err := notifyReq.VerifySignByPKMap(certMap)
|
||||
if err != nil {
|
||||
return ctx.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "Invalid signature"})
|
||||
}
|
||||
|
||||
// TODO: add process order job
|
||||
|
||||
return ctx.Status(http.StatusOK).JSON(&wechat.V3NotifyRsp{
|
||||
Code: gopay.SUCCESS,
|
||||
Message: "成功",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user