diff --git a/plugins/union_pay_redpack/internal/transform.go b/plugins/union_pay_redpack/internal/transform.go index 8b22177..8f466de 100644 --- a/plugins/union_pay_redpack/internal/transform.go +++ b/plugins/union_pay_redpack/internal/transform.go @@ -85,9 +85,9 @@ func orderResp(request *proto.OrderRequest, resp po.OrderResp) *proto.OrderRespo func (c *Config) queryReq(in *proto.QueryRequest, chNlId string) (*po.QueryReq, error) { type OrderExtra struct { - TransSeq string `json:"transSeq"` // 当前交易号 - TransDtTm string `json:"transDtTm"` // 交易日期时间 - OrigTransSeq string `json:"origTransSeq"` // 原交易日期时间 + TransSeq string `json:"transSeq"` // 当前交易号 + TransDtTm string `json:"transDtTm"` // 交易日期时间 + OrigTransDtTm string `json:"origTransDtTm"` // 原交易日期时间 } var e OrderExtra err := json.Unmarshal(in.Order.Extra, &e) @@ -102,8 +102,8 @@ func (c *Config) queryReq(in *proto.QueryRequest, chNlId string) (*po.QueryReq, ChNlId: chNlId, TransSeq: e.TransSeq, // 当前交易号 TransDtTm: e.TransDtTm, // 交易日期时间 - OrigTransDtTm: in.Order.OrderNo, // 原交易流水号 - OrigTransSeq: e.OrigTransSeq, // 原交易日期时间 + OrigTransDtTm: e.OrigTransDtTm, // 原交易流水号 + OrigTransSeq: in.Order.OrderNo, // 原交易流水号 AcctEntityTp: vo.AcctEntityTp, Mobile: mobile, }, nil diff --git a/plugins/union_pay_redpack/internal/union_pay_redpack_test.go b/plugins/union_pay_redpack/internal/union_pay_redpack_test.go index 2768478..191fdc0 100644 --- a/plugins/union_pay_redpack/internal/union_pay_redpack_test.go +++ b/plugins/union_pay_redpack/internal/union_pay_redpack_test.go @@ -7,6 +7,7 @@ import ( "gitea.cdlsxd.cn/sdk/plugin/proto" "github.com/stretchr/testify/assert" "testing" + "time" ) func config() []byte { @@ -36,14 +37,30 @@ func TestConfig(t *testing.T) { var server = &UnionPayCpnService{} func TestOrder(t *testing.T) { + type UnionPayOrderExtra struct { + TransDtTm string `json:"transDtTm"` // 交易日期时间 YYYYMMddHHmmss + ValidEndDtTm string `json:"validEndDtTm"` // 有效截止时间 yyyymmddhhmmss-按条件必填 + TransDigest string `json:"transDigest"` // 交易摘要,最大200位,赠送积分说明,用于在云闪付APP内向用户展示获取说明-必填 + } + now := time.Now() + a := now.Add(time.Hour * 24) + orderExtra := UnionPayOrderExtra{ + TransDtTm: now.Format("20060102150405"), + ValidEndDtTm: a.Format("20060102150405"), + TransDigest: "测试红包", + } + orderExtraBytes, err := json.Marshal(orderExtra) + if err != nil { + t.Fatalf("orderExtra json marshal failed: %+v", err) + } request := &proto.OrderRequest{ Config: config(), Order: &proto.OrderRequest_Order{ - OrderNo: "202409141047181834200102", - Account: "18512869479", + OrderNo: "202409141047181834200108", + Account: "18666173766", Quantity: 1, Amount: 1, - Extra: []byte(`{"transDtTm":"20240914151102","validEndDtTm":"20241031235959","transDigest":"测试红包"}`), + Extra: orderExtraBytes, }, Product: &proto.OrderRequest_Product{ ProductNo: "", @@ -57,19 +74,35 @@ func TestOrder(t *testing.T) { t.Errorf("Order() error = %v", err) return } - fmt.Printf("%+v", got) + fmt.Printf("request order:%+v \n", request.Order) + fmt.Printf("request product:%+v \n", request.Product) + fmt.Printf("got:%+v \n", got) assert.Equal(t, int(proto.Status_ING), int(got.Result.Status)) }) } func TestQuery(t *testing.T) { + type UnionPayQueryExtra struct { + TransSeq string `json:"transSeq"` // 当前交易号 + TransDtTm string `json:"transDtTm"` // 交易日期时间-YYYYMMddHHmmss + OrigTransDtTm string `json:"origTransDtTm"` // 原交易日期时间 + } + extra := UnionPayQueryExtra{ + TransSeq: fmt.Sprintf("%d", time.Now().UnixNano()), + TransDtTm: time.Now().Format("20060102150405"), + OrigTransDtTm: "20240918102040", + } + extraBytes, err := json.Marshal(extra) + if err != nil { + t.Fatalf("orderExtra json marshal failed: %+v", err) + } request := &proto.QueryRequest{ Config: config(), Order: &proto.QueryRequest_Order{ - OrderNo: "24082210051220960113", // 原交易号 + OrderNo: "202409141047181834200108", // 原交易号 TradeNo: "", - Account: "13975287758", - Extra: []byte(`{"transSeq":"v3-1","transDtTm":"20230710165534","origTransSeq":"20240822"}`), + Account: "18666173766", + Extra: extraBytes, }, } t.Run("TestQuery", func(t *testing.T) {