|
@@ -4,6 +4,8 @@ import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"pay/db/model"
|
|
|
+
|
|
|
+ "infish.cn/comm/pay"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -14,8 +16,8 @@ const (
|
|
|
)
|
|
|
|
|
|
type PayInf interface {
|
|
|
- Pay(context.Context, *model.OrderMsg) (interface{}, error)
|
|
|
- Close(context.Context, *model.OrderMsg) (bool, error)
|
|
|
+ Pay(context.Context, *pay.OrderMsg) (interface{}, error)
|
|
|
+ Close(context.Context, *pay.OrderMsg) (bool, error)
|
|
|
ReFundPay(ctx context.Context, refund *model.ReFund) (interface{}, error)
|
|
|
ReFundQuery(ctx context.Context, refund *model.ReFund) (interface{}, error)
|
|
|
}
|
|
@@ -38,335 +40,3 @@ func PayMod(payType int, category int) PayInf {
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
-
|
|
|
-// TODO 以下均已更新到对应文件中
|
|
|
-
|
|
|
-// 单商户请求二维码应答
|
|
|
-// func CreateSingleQrCodeReplyer() *comm.NatsMsgReplyer {
|
|
|
-// orderMsg := &model.OrderMsg{}
|
|
|
-// return &comm.NatsMsgReplyer{
|
|
|
-// // Subject: "single.order.qr",
|
|
|
-// Subject: "pay.single-vip.qr",
|
|
|
-// Entity: orderMsg,
|
|
|
-// Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
|
|
|
-// m := entity.(*model.OrderMsg)
|
|
|
-// pay := PayMod(*m.PayMode, SINGLE)
|
|
|
-// ctx := context.Background()
|
|
|
-// res, err := pay.Pay(ctx, m)
|
|
|
-// return res, err
|
|
|
-// },
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// // 关闭订单应答
|
|
|
-// func CreateSingleCloseOrderReplyer() *comm.NatsMsgReplyer {
|
|
|
-// orderMsg := &model.OrderMsg{}
|
|
|
-// return &comm.NatsMsgReplyer{
|
|
|
-// // Subject: "single.order.close",
|
|
|
-// Subject: "pay.single-vip.close",
|
|
|
-// Entity: orderMsg,
|
|
|
-// Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
|
|
|
-// m := entity.(*model.OrderMsg)
|
|
|
-// pay := PayMod(*m.PayMode, SINGLE)
|
|
|
-// ctx := context.Background()
|
|
|
-// flag, err := pay.Close(ctx, m)
|
|
|
-// if !flag {
|
|
|
-// return "失败", err
|
|
|
-// }
|
|
|
-
|
|
|
-// return "成功", err
|
|
|
-// },
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// // 单商户 支付成功消息放入JetStream
|
|
|
-// func PushSingleResultMessage(res *model.ResData) bool {
|
|
|
-// msg := res.Data.(*model.OrderMsg)
|
|
|
-// for _, app := range conf.AppConfig.Single.App {
|
|
|
-// if msg.ModName == app.Name {
|
|
|
-// // 放入jetstream中
|
|
|
-// err := NatsCenter.PushMessage(app.Search.StreamAndTopic, msg)
|
|
|
-// if err != nil {
|
|
|
-// log.Info("消息存放到JetStream失败", err)
|
|
|
-// return false
|
|
|
-// }
|
|
|
-// return true
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// return false
|
|
|
-// }
|
|
|
-
|
|
|
-// // 单商户 获取二维码的订单号放入JetStream中
|
|
|
-// func PushSingleOrderMessage(msg *model.OrderMsg) bool {
|
|
|
-// for _, app := range conf.AppConfig.Single.App {
|
|
|
-// if msg.ModName == app.Name {
|
|
|
-// // 放入jetstream中
|
|
|
-// err := NatsCenter.PushMessage(app.Search.StreamAndTopic, msg)
|
|
|
-// if err != nil {
|
|
|
-// log.Info("消息存放到JetStream失败", err)
|
|
|
-// return false
|
|
|
-// }
|
|
|
-// return true
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return false
|
|
|
-// }
|
|
|
-
|
|
|
-// // 单商户 支付宝微信查询是否支付成功
|
|
|
-// func SinglePayResultWatchers() []*comm.NatsStreamWather {
|
|
|
-
|
|
|
-// singlePayResultWatcher := make([]*comm.NatsStreamWather, 0, len(conf.AppConfig.Single.App))
|
|
|
-// for _, app := range conf.AppConfig.Single.App {
|
|
|
-// // 打印注册的watcher
|
|
|
-// utils.ConsoleFormat(app.Search.Topic, "stream", app.Search.Stream, app.Search.Queue)
|
|
|
-// singlePayResultWatcher = append(singlePayResultWatcher, NewSinglePayResultWatcher(app.Search.Stream, app.Search.Topic, app.Search.Queue))
|
|
|
-// }
|
|
|
-// return singlePayResultWatcher
|
|
|
-// }
|
|
|
-
|
|
|
-// func NewSinglePayResultWatcher(stream, topic, queue string) *comm.NatsStreamWather {
|
|
|
-// res := &model.OrderMsg{}
|
|
|
-
|
|
|
-// return &comm.NatsStreamWather{
|
|
|
-// Stream: stream,
|
|
|
-// Topic: topic,
|
|
|
-// Queue: queue,
|
|
|
-// AckWaitMinute: int64(1),
|
|
|
-// Entity: res,
|
|
|
-// Cb: func(msg *nats.Msg, entity interface{}) {
|
|
|
-// defer func() {
|
|
|
-// if err := recover(); err != nil {
|
|
|
-// log.Info("系统异常", err)
|
|
|
-// }
|
|
|
-// }()
|
|
|
-
|
|
|
-// orderMsg := entity.(*model.OrderMsg)
|
|
|
-
|
|
|
-// // 订单超时判断
|
|
|
-// if orderMsg.ExpireTime.Before(time.Now()) {
|
|
|
-// log.Info("===============================微信支付失败======================================")
|
|
|
-// fmt.Println("===============================微信支付失败======================================")
|
|
|
-// PushSingleResultMessage(model.TIMEOUT.SetData(orderMsg))
|
|
|
-// msg.Ack()
|
|
|
-// return
|
|
|
-// }
|
|
|
-
|
|
|
-// ctx := context.Background()
|
|
|
-// // 未支付去微信、支付宝查看,支付了则更新状态未支付
|
|
|
-// outTradeNo := orderMsg.ModName + "_" + orderMsg.Id
|
|
|
-// if *orderMsg.PayMode == ALIPAY {
|
|
|
-// bm := gopay.BodyMap{}
|
|
|
-// bm["out_trade_no"] = outTradeNo
|
|
|
-// res, err := pay.SingleAlipayClient.TradeQuery(ctx, bm)
|
|
|
-// if err != nil {
|
|
|
-// fmt.Println(err)
|
|
|
-// return
|
|
|
-// }
|
|
|
-// if res.Response.TradeStatus == "TRADE_SUCCESS" {
|
|
|
-// log.Info("===============================支付宝购买成功======================================")
|
|
|
-// fmt.Println("===============================支付宝购买成功======================================")
|
|
|
-// // 放入是成功的消息队列中
|
|
|
-// PushSingleResultMessage(model.SUCCESS.SetData(orderMsg))
|
|
|
-// } else {
|
|
|
-// log.Info("===============================支付宝购买失败======================================")
|
|
|
-// fmt.Println("===============================支付宝购买失败======================================")
|
|
|
-// // 放入是失败的消息队列中 SKU3DMember
|
|
|
-// PushSingleResultMessage(model.FAILD.SetData(orderMsg))
|
|
|
-// }
|
|
|
-
|
|
|
-// } else {
|
|
|
-// res, err := pay.SingleWechatpayClient.V3TransactionQueryOrder(ctx, wechat.OutTradeNo, outTradeNo)
|
|
|
-// if err != nil {
|
|
|
-// fmt.Println(err)
|
|
|
-// return
|
|
|
-// }
|
|
|
-// if res.Response.TradeState == "SUCCESS" {
|
|
|
-// log.Info("===============================微信购买成功======================================")
|
|
|
-// fmt.Println("===============================微信购买成功======================================")
|
|
|
-// // 放入是成功的消息队列中
|
|
|
-// PushSingleResultMessage(model.SUCCESS.SetData(orderMsg))
|
|
|
-// } else if res.Response.TradeState == "NOTPAY" {
|
|
|
-// log.Info("===============================微信还未支付======================================")
|
|
|
-// fmt.Println("===============================微信还未支付======================================")
|
|
|
-// return
|
|
|
-// } else {
|
|
|
-// // 放入是失败的消息队列中
|
|
|
-// log.Info("===============================微信支付失败======================================")
|
|
|
-// fmt.Println("===============================微信支付失败======================================")
|
|
|
-// PushSingleResultMessage(model.FAILD.SetData(orderMsg))
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// msg.Ack()
|
|
|
-// },
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// // 多商户 二维码应答
|
|
|
-// func CreateMultiQrCodeReplyer() *comm.NatsMsgReplyer {
|
|
|
-// orderMsg := &model.OrderMsg{}
|
|
|
-// return &comm.NatsMsgReplyer{
|
|
|
-// Subject: "comm.pay.multiPay.createqr",
|
|
|
-// //comm.pay.multiPay.createqr
|
|
|
-// Entity: orderMsg,
|
|
|
-// Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
|
|
|
-
|
|
|
-// m := entity.(*model.OrderMsg)
|
|
|
-// pay := PayMod(*m.PayMode, MULTI)
|
|
|
-// ctx := context.Background()
|
|
|
-// res, err := pay.Pay(ctx, m)
|
|
|
-
|
|
|
-// return res, err
|
|
|
-// },
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// // 多商户关闭订单应答
|
|
|
-// func CreateMultiCloseOrderReplyer() *comm.NatsMsgReplyer {
|
|
|
-// orderMsg := &model.OrderMsg{}
|
|
|
-// return &comm.NatsMsgReplyer{
|
|
|
-// Subject: "pay.multi-vip.close",
|
|
|
-// Entity: orderMsg,
|
|
|
-// Cb2: func(msg *nats.Msg, entity interface{}) (interface{}, error) {
|
|
|
-// m := entity.(*model.OrderMsg)
|
|
|
-// pay := PayMod(*m.PayMode, MULTI)
|
|
|
-// ctx := context.Background()
|
|
|
-// flag, err := pay.Close(ctx, m)
|
|
|
-// if !flag {
|
|
|
-// return "失败", err
|
|
|
-// }
|
|
|
-
|
|
|
-// return "成功", err
|
|
|
-// },
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// // 多商户 支付成功消息放入JetStream
|
|
|
-// func PushMultiResultMessage(res *model.ResData) bool {
|
|
|
-
|
|
|
-// msg := res.Data.(*model.OrderMsg)
|
|
|
-
|
|
|
-// for _, app := range conf.AppConfig.Multi.App {
|
|
|
-// if msg.ModName == app.Name {
|
|
|
-// // 放入jetstream中
|
|
|
-// err := NatsCenter.PushMessage(app.Result.StreamAndTopic, msg)
|
|
|
-
|
|
|
-// if err != nil {
|
|
|
-// log.Info("消息存放到JetStream失败", err)
|
|
|
-// return false
|
|
|
-// }
|
|
|
-// return true
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// return false
|
|
|
-// }
|
|
|
-
|
|
|
-// // 多商户 获取二维码的订单号放入JetStream中
|
|
|
-// func PushMultiOrderMessage(msg *model.OrderMsg) bool {
|
|
|
-// for _, app := range conf.AppConfig.Multi.App {
|
|
|
-// if msg.ModName == app.Name {
|
|
|
-// // 放入jetstream中
|
|
|
-// err := NatsCenter.PushMessage(app.Search.StreamAndTopic, msg)
|
|
|
-// if err != nil {
|
|
|
-// log.Info("消息存放到JetStream失败", err)
|
|
|
-// return false
|
|
|
-// }
|
|
|
-// return true
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return false
|
|
|
-// }
|
|
|
-
|
|
|
-// // 多商户 支付宝微信查询是否支付成功
|
|
|
-// func MultiPayResultWatchers() []*comm.NatsStreamWather {
|
|
|
-
|
|
|
-// multiPayResultWatcher := make([]*comm.NatsStreamWather, 0, len(conf.AppConfig.Multi.App))
|
|
|
-// for _, app := range conf.AppConfig.Multi.App {
|
|
|
-// // 打印注册的watcher
|
|
|
-// utils.ConsoleFormat(app.Search.Topic, "stream", app.Search.Stream, app.Search.Queue)
|
|
|
-// multiPayResultWatcher = append(multiPayResultWatcher, NewMultiPayResultWatcher(app.Search.Stream, app.Search.Topic, app.Search.Queue))
|
|
|
-// }
|
|
|
-// return multiPayResultWatcher
|
|
|
-// }
|
|
|
-
|
|
|
-// func NewMultiPayResultWatcher(stream, topic, queue string) *comm.NatsStreamWather {
|
|
|
-// res := &model.OrderMsg{}
|
|
|
-
|
|
|
-// return &comm.NatsStreamWather{
|
|
|
-// Stream: stream,
|
|
|
-// Topic: topic,
|
|
|
-// Queue: queue,
|
|
|
-// AckWaitMinute: int64(1),
|
|
|
-// Entity: res,
|
|
|
-// Cb: func(msg *nats.Msg, entity interface{}) {
|
|
|
-// defer func() {
|
|
|
-// if err := recover(); err != nil {
|
|
|
-// log.Info("系统异常", err)
|
|
|
-// }
|
|
|
-// }()
|
|
|
-
|
|
|
-// orderMsg := entity.(*model.OrderMsg)
|
|
|
-
|
|
|
-// if orderMsg.ExpireTime.Before(time.Now()) {
|
|
|
-// log.Info("===============================微信支付失败======================================")
|
|
|
-// fmt.Println("===============================微信支付失败======================================")
|
|
|
-// PushMultiResultMessage(model.TIMEOUT.SetData(orderMsg))
|
|
|
-// msg.Ack()
|
|
|
-// return
|
|
|
-// }
|
|
|
-
|
|
|
-// ctx := context.Background()
|
|
|
-// // 3.3 未支付去微信、支付宝查看,支付了则更新状态未支付
|
|
|
-// outTradeNo := orderMsg.ModName + "_" + orderMsg.Id
|
|
|
-// if *orderMsg.PayMode == ALIPAY {
|
|
|
-// bm := gopay.BodyMap{}
|
|
|
-// bm["out_trade_no"] = outTradeNo
|
|
|
-// res, err := pay.MultiAlipayClient.TradeQuery(ctx, bm)
|
|
|
-// if err != nil {
|
|
|
-// fmt.Println(err)
|
|
|
-// return
|
|
|
-// }
|
|
|
-// if res.Response.TradeStatus == "TRADE_SUCCESS" {
|
|
|
-// log.Info("===============================支付宝购买成功======================================")
|
|
|
-// fmt.Println("===============================支付宝购买成功======================================")
|
|
|
-// // 放入是成功的消息队列中
|
|
|
-// PushMultiResultMessage(model.SUCCESS.SetData(orderMsg))
|
|
|
-// } else {
|
|
|
-// log.Info("===============================支付宝购买失败======================================")
|
|
|
-// fmt.Println("===============================支付宝购买失败======================================")
|
|
|
-// // 放入是失败的消息队列中 SKU3DMember
|
|
|
-// PushMultiResultMessage(model.FAILD.SetData(orderMsg))
|
|
|
-// }
|
|
|
-
|
|
|
-// } else {
|
|
|
-// bm := gopay.BodyMap{}
|
|
|
-// bm.Set("sp_mchid", conf.AppConfig.Multi.WechatPay.MchId)
|
|
|
-// bm.Set("sub_mchid", orderMsg.SubId)
|
|
|
-// res, err := pay.MultiWechatpayClient.V3PartnerQueryOrder(ctx, wechat.OutTradeNo, outTradeNo, bm)
|
|
|
-// if err != nil {
|
|
|
-// fmt.Println(err)
|
|
|
-// return
|
|
|
-// }
|
|
|
-// if res.Response.TradeState == "SUCCESS" {
|
|
|
-// log.Info("===============================微信购买成功======================================")
|
|
|
-// fmt.Println("===============================微信购买成功======================================")
|
|
|
-// // 放入是成功的消息队列中
|
|
|
-// PushMultiResultMessage(model.SUCCESS.SetData(orderMsg))
|
|
|
-// } else if res.Response.TradeState == "NOTPAY" {
|
|
|
-// log.Info("===============================微信还未支付======================================")
|
|
|
-// fmt.Println("===============================微信还未支付======================================")
|
|
|
-// return
|
|
|
-// } else {
|
|
|
-// // 放入是失败的消息队列中
|
|
|
-// log.Info("===============================微信支付失败======================================")
|
|
|
-// fmt.Println("===============================微信支付失败======================================")
|
|
|
-// PushMultiResultMessage(model.FAILD.SetData(orderMsg))
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// msg.Ack()
|
|
|
-// },
|
|
|
-// }
|
|
|
-// }
|