From 19741c1aca2fb5805f0258269a9bb7899f9cf231 Mon Sep 17 00:00:00 2001 From: renzhiyuan <465386466@qq.com> Date: Tue, 21 Jul 2026 15:18:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6:=20ymt=5Fv?= =?UTF-8?q?3=5F2/example=5Ftest.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ymt_v3_2/example_test.go | 104 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 ymt_v3_2/example_test.go diff --git a/ymt_v3_2/example_test.go b/ymt_v3_2/example_test.go new file mode 100644 index 0000000..c0754e7 --- /dev/null +++ b/ymt_v3_2/example_test.go @@ -0,0 +1,104 @@ +package ymt_v3_2_test + +import ( + "context" + "fmt" + "testing" + "time" + + "ymt_v3_2" +) + +const ( + testAppID = "xxx" + testPrivateKey = `-----BEGIN PRIVATE KEY----- +xxx +-----END PRIVATE KEY-----` + testPublicKey = `-----BEGIN PUBLIC KEY----- +xxx +-----END PUBLIC KEY-----` + testAESKey = "xxxx" + testActivityNo = "xxxx" +) + +func newTestClient() *ymt_v3_2.Client { + return ymt_v3_2.NewClient( + ymt_v3_2.WithBaseURL("https://gateway.dev.cdlsxd.cn"), + ymt_v3_2.WithAppID(testAppID), + ymt_v3_2.WithPrivateKeyPEM(testPrivateKey), + ymt_v3_2.WithPublicKeyPEM(testPublicKey), + ymt_v3_2.WithAESKey(testAESKey), + ymt_v3_2.WithTimeout(10*time.Second), + ) +} + +func TestGetKey(t *testing.T) { + client := newTestClient() + ctx := context.Background() + req := &ymt_v3_2.GetKeyRequest{ + OutBizNo: fmt.Sprintf("test_%d", time.Now().UnixNano()), + ActivityNo: testActivityNo, + Account: "18666666666", + NotifyURL: "https://notify.example.com/openapi", + } + resp, err := client.GetKey(ctx, req) + if err != nil { + t.Fatalf("GetKey failed: %v", err) + } + t.Logf("GetKey response: %+v", resp) +} + +func TestQueryKey(t *testing.T) { + client := newTestClient() + ctx := context.Background() + req := &ymt_v3_2.QueryKeyRequest{ + OutBizNo: "order_001", + } + resp, err := client.QueryKey(ctx, req) + if err != nil { + t.Fatalf("QueryKey failed: %v", err) + } + t.Logf("QueryKey response: %+v", resp) +} + +func TestDiscardKey(t *testing.T) { + client := newTestClient() + ctx := context.Background() + req := &ymt_v3_2.DiscardKeyRequest{ + TradeNo: "7251449503000383488", + } + resp, err := client.DiscardKey(ctx, req) + if err != nil { + t.Fatalf("DiscardKey failed: %v", err) + } + t.Logf("DiscardKey response: %+v", resp) +} + +func TestBatchOrder(t *testing.T) { + client := newTestClient() + ctx := context.Background() + req := &ymt_v3_2.BatchOrderRequest{ + OutBizNo: fmt.Sprintf("batch_%d", time.Now().UnixNano()), + ActivityNo: testActivityNo, + Number: 10, + NotifyURL: "https://notify.example.com/openapi", + } + resp, err := client.BatchOrder(ctx, req) + if err != nil { + t.Fatalf("BatchOrder failed: %v", err) + } + t.Logf("BatchOrder response: %+v", resp) +} + +func TestBatchQuery(t *testing.T) { + client := newTestClient() + ctx := context.Background() + req := &ymt_v3_2.BatchQueryRequest{ + OutBizNo: "batch_001", + } + resp, err := client.BatchQuery(ctx, req) + if err != nil { + t.Fatalf("BatchQuery failed: %v", err) + } + t.Logf("BatchQuery response: %+v", resp) +} \ No newline at end of file