From bee41b8bc4ba144ba269c18bd9a4e527affe8b30 Mon Sep 17 00:00:00 2001 From: timerzz Date: Thu, 25 Jul 2024 13:30:34 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E4=BD=BF=E7=94=A8SetDial=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- article-service.go | 9 ++++----- article-service_test.go | 2 +- bid-consign.go | 5 ++++- bid-consign_test.go | 16 ++++++++++++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/article-service.go b/article-service.go index 8c4a48f..2c947c9 100644 --- a/article-service.go +++ b/article-service.go @@ -2,10 +2,12 @@ package dw_sdk import ( "fmt" + "time" + "github.com/bytedance/sonic" "github.com/gofiber/fiber/v3/client" "github.com/pkg/errors" - "time" + "github.com/valyala/fasthttp/fasthttpproxy" ) //商品服务API @@ -27,10 +29,7 @@ func NewArticleServiceClient(cfg Config) ArticleServiceClient { return sonic.Unmarshal(data, v) }).SetBaseURL(GetUrl(cfg.Public.Env)).Debug() if cfg.Proxy != nil { - err := cli.SetProxyURL(fmt.Sprintf("http://%s:%s@%s:%s", cfg.Proxy.User, cfg.Proxy.Pass, cfg.Proxy.Host, cfg.Proxy.Port)) - if err != nil { - fmt.Println(err) - } + cli.SetDial(fasthttpproxy.FasthttpHTTPDialer(fmt.Sprintf("%s:%s@%s:%s", cfg.Proxy.User, cfg.Proxy.Pass, cfg.Proxy.Host, cfg.Proxy.Port))) } return &ArticleServiceClientImpl{ cli: cli, diff --git a/article-service_test.go b/article-service_test.go index 9e49497..e102783 100644 --- a/article-service_test.go +++ b/article-service_test.go @@ -21,7 +21,7 @@ func TestNewArticleServiceClient(t *testing.T) { Pass: "zhhg1997", }, }) - resp, err := cli.BatchArticleNumber([]string{"cq067"}) + resp, err := cli.BatchArticleNumber([]string{"C4250-IMNLJ"}) if err != nil { t.Fatal(err) } diff --git a/bid-consign.go b/bid-consign.go index f245818..e67a86a 100644 --- a/bid-consign.go +++ b/bid-consign.go @@ -2,9 +2,12 @@ package dw_sdk import ( "fmt" + "github.com/bytedance/sonic" "github.com/gofiber/fiber/v3/client" "github.com/pkg/errors" + "github.com/valyala/fasthttp/fasthttpproxy" + "time" ) @@ -32,7 +35,7 @@ func NewConsignBidClient(cfg Config) BidClient { }) if cfg.Proxy != nil { - _ = cli.SetProxyURL(fmt.Sprintf("http://%s:%s@%s:%s", cfg.Proxy.User, cfg.Proxy.Pass, cfg.Proxy.Host, cfg.Proxy.Port)) + cli.SetDial(fasthttpproxy.FasthttpHTTPDialer(fmt.Sprintf("%s:%s@%s:%s", cfg.Proxy.User, cfg.Proxy.Pass, cfg.Proxy.Host, cfg.Proxy.Port))) } return &ConsignBidClientImpl{ cli: cli, diff --git a/bid-consign_test.go b/bid-consign_test.go index f0b90f4..0692f63 100644 --- a/bid-consign_test.go +++ b/bid-consign_test.go @@ -12,8 +12,20 @@ var testConfig = Config{ } func TestNewBidConsignClient(t *testing.T) { - cli := NewConsignBidClient(testConfig) - resp, err := cli.LowestPrice(123) + cli := NewConsignBidClient(Config{ + Public: PublicConfig{ + Key: "92a2afa02627410fae9e3331cc850224", + Secret: "73b5bf12bc5e4b4690f444b32b934dc0feb1e42977514333a76f263592ee37f4", + Env: "online", + }, + Proxy: &ProxyConfig{ + Host: "jd.timerzz.com", + Port: "8090", + User: "timerzz", + Pass: "zhhg1997", + }, + }) + resp, err := cli.LowestPrice(626512954) if err != nil { t.Fatal(err) }