animeic há 1 ano atrás
pai
commit
0c009b7f26
5 ficheiros alterados com 19 adições e 7 exclusões
  1. BIN
      pay/__debug_bin
  2. 5 0
      pay/assettest.log
  3. 2 2
      pay/bus/multiPay.go
  4. 5 3
      pay/bus/singleAliPay.go
  5. 7 2
      pay/bus/singleWechatPay.go

BIN
pay/__debug_bin


+ 5 - 0
pay/assettest.log

@@ -31,3 +31,8 @@
 {"level":"info","timestamp":"2023-07-06 16:51:56","message":"[初始化支付客户端]","service_name":"assettest"}
 {"level":"info","timestamp":"2023-07-06 16:52:57","message":"[初始化支付客户端]","service_name":"assettest"}
 {"level":"info","timestamp":"2023-07-06 16:53:33","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 16:55:24","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 17:05:54","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 17:07:18","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"info","timestamp":"2023-07-06 17:18:02","message":"[初始化支付客户端]","service_name":"assettest"}
+{"level":"error","timestamp":"2023-07-06 17:21:19","message":"{\"code\":\"ACQ.MERCHANT_STATUS_NOT_NORMAL\",\"msg\":\"Business Failed\",\"sub_code\":\"ACQ.MERCHANT_STATUS_NOT_NORMAL\",\"sub_msg\":\"商户协议状态非正常状态\"}","service_name":"assettest"}

+ 2 - 2
pay/bus/multiPay.go

@@ -14,10 +14,10 @@ import (
 type MultiPay struct{}
 
 func (m *MultiPay) CreateQr() *comm.NatsMsgReplyer {
-	utils.ConsoleFormat(comm.CommPayMallCreateQrApi)
+	utils.ConsoleFormat(pay.PayMultiQrApi)
 
 	return &comm.NatsMsgReplyer{
-		Subject: comm.CommPayMallCreateQrApi,
+		Subject: pay.PayMultiQrApi,
 		Entity:  func() interface{} { return &pay.OrderMsg{} },
 		Cb2: func(_ *nats.Msg, entity interface{}) (interface{}, error) {
 			m := entity.(*pay.OrderMsg)

+ 5 - 3
pay/bus/singleAliPay.go

@@ -3,10 +3,12 @@ package bus
 import (
 	"context"
 	"errors"
+	"fmt"
 	"pay/db/model"
 	"pay/log"
 	"pay/pay"
 	"pay/utils"
+	"strconv"
 
 	"github.com/go-pay/gopay"
 	"github.com/go-pay/gopay/alipay"
@@ -25,15 +27,15 @@ func NewSingleAliPay() PayInf {
 func (a *SingleAliPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (interface{}, error) {
 	// 初始化 BodyMap
 	bm := make(gopay.BodyMap)
-	parseAmount, err := utils.IntToDecimal(int32(*orderMsg.Amount))
+	amount, err := strconv.ParseFloat(fmt.Sprintf("%.2f", *orderMsg.Amount), 64)
 	if err != nil {
-		return nil, err
+		return nil, errors.New("价格parse错误!")
 	}
 	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
 	bm.Set("subject", orderMsg.Name).
 		Set("scene", "bar_code").
 		Set("out_trade_no", orderId).
-		Set("total_amount", parseAmount).
+		Set("total_amount", amount).
 		Set("timeout_express", "10m")
 
 	// 下单url

+ 7 - 2
pay/bus/singleWechatPay.go

@@ -10,6 +10,7 @@ import (
 	"pay/log"
 	"pay/pay"
 	"pay/utils"
+	"strconv"
 	"time"
 
 	"github.com/go-pay/gopay"
@@ -28,9 +29,13 @@ func (a *SingleWechatPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (int
 	fmt.Println("====================single-wechat二维码获取=====================")
 
 	// 初始化 BodyMap
-	orderId := orderMsg.Project + "_" + orderMsg.Id.Hex()
+	orderId := orderMsg.Id.Hex()
 	bm := make(gopay.BodyMap)
 	singlePayCnf := utils.GetSinglePayConfig(conf.AppConfig)
+	amount, err := strconv.ParseFloat(fmt.Sprintf("%.2f", *orderMsg.Amount), 64)
+	if err != nil {
+		return nil, errors.New("价格parse错误!")
+	}
 
 	bm.Set("appid", singlePayCnf.WechatPay.AppId).
 		Set("mchid", singlePayCnf.WechatPay.MchId).
@@ -39,7 +44,7 @@ func (a *SingleWechatPay) Pay(ctx context.Context, orderMsg *cpay.OrderMsg) (int
 		Set("time_expire", time.Now().Add(10*time.Minute).Format(time.RFC3339)).
 		Set("notify_url", singlePayCnf.WechatPay.NotifyUrl).
 		SetBodyMap("amount", func(bm gopay.BodyMap) {
-			bm.Set("total", orderMsg.Amount).
+			bm.Set("total", amount*100).
 				Set("currency", "CNY")
 		})