添加文件: ymt_v3_2/example_test.go

This commit is contained in:
renzhiyuan 2026-07-21 15:18:58 +08:00
parent f9dac6552e
commit 19741c1aca
1 changed files with 104 additions and 0 deletions

104
ymt_v3_2/example_test.go Normal file
View File

@ -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)
}