45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"quyun/app/jobs"
|
|
"quyun/providers/job"
|
|
"quyun/providers/wepay"
|
|
|
|
"github.com/go-pay/gopay"
|
|
"github.com/go-pay/gopay/wechat/v3"
|
|
"github.com/gofiber/fiber/v3"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// @provider
|
|
type pays struct {
|
|
wepay *wepay.Client
|
|
job *job.Job
|
|
}
|
|
|
|
// Callback
|
|
//
|
|
// @Router /pay/callback/:channel [post]
|
|
// @Bind channel path
|
|
func (ctl *pays) Callback(ctx fiber.Ctx, channel string) error {
|
|
log := log.WithField("method", "pays.Callback")
|
|
|
|
notify, err := ctl.wepay.ParseNotify(ctx)
|
|
if err != nil {
|
|
log.Errorf("ParseNotify error:%v", err)
|
|
return ctx.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "Failed to parse notify"})
|
|
}
|
|
|
|
if err := ctl.job.Add(&jobs.WechatPayNotify{PayNotify: notify}); err != nil {
|
|
log.Errorf("add job error:%v", err)
|
|
return ctx.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": "Failed to add job"})
|
|
}
|
|
|
|
return ctx.Status(http.StatusOK).JSON(&wechat.V3NotifyRsp{
|
|
Code: gopay.SUCCESS,
|
|
Message: "成功",
|
|
})
|
|
}
|