package direct import ( "bytes" "context" "gitea.cdlsxd.cn/sdk/plugin/dctw/v1/core" "github.com/stretchr/testify/assert" "io/ioutil" "net/http" "testing" ) func TestDirect_Order(t *testing.T) { server, err := core.NewDctWServer( &core.DctWConfig{ AppId: "1", AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9", BaseUri: "http://test.openapi.1688sup.cn", }, core.WithDebug(true), ) if err != nil { t.Fatal(err) } a := &Direct{DctWServer: server} req := &Order{ Number: 1, MerchantId: "25537", OutTradeNo: "test_zltx_direct_1", ProductId: "101", AccountType: 1, RechargeAccount: "18666666666", NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify", Version: "1.0", } resp, err := a.Order(context.Background(), req) if err != nil { t.Error(err) return } if !resp.GetCode().IsSuccess() { t.Error(resp.Message) return } t.Log(resp) } func TestDirect_Query(t *testing.T) { server, err := core.NewDctWServer(&core.DctWConfig{ AppId: "1", AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9", BaseUri: "http://test.openapi.1688sup.cn", }) if err != nil { t.Fatal(err) } a := &Direct{DctWServer: server} req := &Query{ MerchantId: "25537", OutTradeNo: "test_zltx_direct_1", Version: "1.0", } resp, err := a.Query(context.Background(), req) if err != nil { t.Error(err) return } if !resp.GetCode().IsSuccess() { t.Error(resp.Message) return } t.Log(resp) assert.Equal(t, resp.Status.IsSuccess(), true, "充值是否成功") } func TestDirect_Notify(t *testing.T) { server, err := core.NewDctWServer(&core.DctWConfig{ AppId: "1", AppKey: "1e2bf7a04b8b1e6be5dc78d04e8639c9", BaseUri: "http://test.openapi.1688sup.cn", }) if err != nil { t.Fatal(err) } a := &Direct{DctWServer: server} body := []byte(`{"merchantId":23329,"outTradeNo":"202409111714224026320002","rechargeAccount":"18512869479","sign":"474ACB521DEE99551153B6CE108FD06D","status":"01"}`) headers := make(http.Header) headers.Set(core.SignKeyName, "MD5 appid=101,sign=292e21f3683219369cf68dede0d45730") headers.Set("Content-Type", core.ApplicationJSON) var httpRequest = &http.Request{ Header: headers, Body: ioutil.NopCloser(bytes.NewBuffer(body)), } resp, err := a.Notify(context.Background(), httpRequest) if err != nil { t.Error(err) return } t.Log(resp) assert.Equal(t, resp.Status.IsSuccess(), true, "充值是否成功") }