From b15d883542e62c4785a9a047023ede083426dbef Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 13 Sep 2023 17:42:06 +0700 Subject: [PATCH 1/8] add jt express --- go.mod | 2 + go.sum | 4 + partnerapi/jtexpress/const.go | 20 +++++ partnerapi/jtexpress/jtexpress.go | 111 +++++++++++++++++++++++++ partnerapi/jtexpress/model_request.go | 75 +++++++++++++++++ partnerapi/jtexpress/model_response.go | 43 ++++++++++ 6 files changed, 255 insertions(+) create mode 100644 partnerapi/jtexpress/const.go create mode 100644 partnerapi/jtexpress/jtexpress.go create mode 100644 partnerapi/jtexpress/model_request.go create mode 100644 partnerapi/jtexpress/model_response.go diff --git a/go.mod b/go.mod index 7c32cb8..cfef896 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/elastic/go-licenser v0.4.1 // indirect github.com/elastic/go-sysinfo v1.1.1 // indirect github.com/elastic/go-windows v1.0.1 // indirect + github.com/go-resty/resty/v2 v2.7.0 // indirect github.com/golang/snappy v0.0.3 // indirect github.com/jcchavezs/porto v0.4.0 // indirect github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect @@ -34,6 +35,7 @@ require ( golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect golang.org/x/mod v0.5.1 // indirect + golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect golang.org/x/sys v0.0.0-20211102192858-4dd72447c267 // indirect golang.org/x/tools v0.1.7 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect diff --git a/go.sum b/go.sum index dbbf8f5..05ef62d 100644 --- a/go.sum +++ b/go.sum @@ -17,6 +17,8 @@ github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6 github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU= github.com/elastic/go-windows v1.0.1 h1:AlYZOldA+UJ0/2nBuqWdo90GFCgG9xuyw9SYzGUtJm0= github.com/elastic/go-windows v1.0.1/go.mod h1:FoVvqWSun28vaDQPbj2Elfc0JahhPB7WQEGa3c814Ss= +github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY= +github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -142,6 +144,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/partnerapi/jtexpress/const.go b/partnerapi/jtexpress/const.go new file mode 100644 index 0000000..84d467f --- /dev/null +++ b/partnerapi/jtexpress/const.go @@ -0,0 +1,20 @@ +package jtexpress + +const ( + apiHostProd = "" + apiHostDev = "https://test.jtexpress.vn" + + apiPathEstimateFee = "/yuenan-interface-web/jtpos/inquiry!freight.action" + apiPathCreateOrder = "/yuenan-interface-web/order/orderAction!createOrder.action" + apiPathCancelOrder = "/yuenan-interface-web/order/orderAction!createOrder.action" + apiPathTrackingOrder = "" +) + +const ( + statusSuccess = "true" +) + +const ( + msgTypeEstimateFee = "FREIGHTQUERY" + msgTypeCreateOrder = "ORDERCREATE" +) diff --git a/partnerapi/jtexpress/jtexpress.go b/partnerapi/jtexpress/jtexpress.go new file mode 100644 index 0000000..2c9cbbb --- /dev/null +++ b/partnerapi/jtexpress/jtexpress.go @@ -0,0 +1,111 @@ +package jtexpress + +import ( + "crypto/md5" + "fmt" + "io" + + "github.com/go-resty/resty/v2" + + "git.selly.red/Selly-Modules/3pl/util/pjson" +) + +func New(degestKey, companyID string, isProd, debug bool) *Client { + host := apiHostDev + if isProd { + host = apiHostProd + } + c := &Client{ + DigestKey: degestKey, + EccompanyID: companyID, + IsProduction: isProd, + Debug: debug, + host: host, + httpClient: resty.New().SetDebug(debug), + } + return c +} + +type Client struct { + DigestKey string + EccompanyID string + IsProduction bool + Debug bool + host string + httpClient *resty.Client +} + +func (c *Client) EstimateFee(req *EstimateFeeReq) (*EstimateFeeItemRes, error) { + path := c.host + apiPathEstimateFee + data := pjson.ToJSONString(req) + resp, err := c.httpClient.R(). + SetFormData(map[string]string{ + "logistics_interface": data, + "data_digest": c.getDigest(data), + "msg_type": msgTypeEstimateFee, + "eccompanyid": c.EccompanyID, + }). + SetResult(&EstimateFeeRes{}). + Post(path) + if err != nil { + return nil, fmt.Errorf("jtepxress: request %s, err %v", path, err) + } + res := resp.Result().(*EstimateFeeRes) + if len(res.ResponseItems) == 0 { + return nil, fmt.Errorf("jtepxress: estimate fee empty response") + } + return res.ResponseItems[0], nil +} + +func (c *Client) CancelOrder(req *CancelOrderReq) (*CancelOrderRes, error) { + path := c.host + apiPathCancelOrder + data := pjson.ToJSONString(req) + resp, err := c.httpClient.R(). + SetFormData(map[string]string{ + "logistics_interface": data, + "data_digest": c.getDigest(data), + "msg_type": msgTypeEstimateFee, + "eccompanyid": c.EccompanyID, + }). + SetResult(&CancelOrderRes{}). + Post(path) + if err != nil { + return nil, fmt.Errorf("jtepxress: request %s, err %v", path, err) + } + res := resp.Result().(*CancelOrderRes) + if len(res.ResponseItems) == 0 { + return nil, fmt.Errorf("jtepxress: cancel order empty response") + } + // return res.ResponseItems[0], nil + return nil, err +} + +func (c *Client) CreateOrder(req *CreateOrderReq) (*CreateOrderItemRes, error) { + path := c.host + apiPathCreateOrder + data := pjson.ToJSONString(req) + resp, err := c.httpClient.R(). + SetFormData(map[string]string{ + "logistics_interface": data, + "data_digest": c.getDigest(data), + "msg_type": msgTypeCreateOrder, + "eccompanyid": c.EccompanyID, + }). + SetResult(&CreateOrderRes{}). + Post(path) + if err != nil { + return nil, fmt.Errorf("jtepxress: request %s, err %v", path, err) + } + res := resp.Result().(*CreateOrderRes) + if len(res.ResponseItems) == 0 { + return nil, fmt.Errorf("jtepxress: create order empty response") + } + return res.ResponseItems[0], nil +} + +func (c *Client) getDigest(data string) string { + s := data + c.DigestKey + h := md5.New() + + io.WriteString(h, s) + return fmt.Sprintf("%x", h.Sum(nil)) +} diff --git a/partnerapi/jtexpress/model_request.go b/partnerapi/jtexpress/model_request.go new file mode 100644 index 0000000..daddc0d --- /dev/null +++ b/partnerapi/jtexpress/model_request.go @@ -0,0 +1,75 @@ +package jtexpress + +type EstimateFeeLocation struct { + Prov string `json:"prov"` + City string `json:"city"` + Area string `json:"area"` +} + +type EstimateFeeReq struct { + SelfAddress int `json:"selfAddress"` + ProductType string `json:"producttype"` + CusName string `json:"cusname"` + GoodsValue string `json:"goodsvalue"` + ItemsValue string `json:"itemsvalue"` + Weight string `json:"weight"` + Sender EstimateFeeLocation `json:"sender"` + Receiver EstimateFeeLocation `json:"receiver"` + Decs string `json:"decs"` + FeeType string `json:"feetype"` +} + +type CreateOrderReq struct { + Customerid string `json:"customerid"` + Txlogisticid string `json:"txlogisticid"` + Ordertype int `json:"ordertype"` + Servicetype int `json:"servicetype"` + SelfAddress int `json:"selfAddress"` + Special string `json:"special"` + Partsign string `json:"partsign"` + Sender CreateOrderLocation `json:"sender"` + Receiver CreateOrderLocation `json:"receiver"` + Createordertime string `json:"createordertime"` + Sendstarttime string `json:"sendstarttime"` + Sendendtime string `json:"sendendtime"` + Paytype string `json:"paytype"` + Itemsvalue string `json:"itemsvalue"` + Goodsvalue string `json:"goodsvalue"` + IsInsured string `json:"isInsured"` + Items []OrderItem `json:"items"` + Weight string `json:"weight"` + Volume string `json:"volume"` + Remark string `json:"remark"` +} + +type CreateOrderLocation struct { + Name string `json:"name"` + Phone string `json:"phone"` + Mobile string `json:"mobile"` + Prov string `json:"prov"` + City string `json:"city"` + Area string `json:"area"` + Address string `json:"address"` +} + +type OrderItem struct { + Itemname string `json:"itemname"` + EnglishName string `json:"englishName"` + Number string `json:"number"` + Itemvalue string `json:"itemvalue"` + Desc string `json:"desc"` +} + +type CancelOrderReq struct { + Eccompanyid string `json:"eccompanyid"` + Customerid string `json:"customerid"` + Logisticproviderid string `json:"logisticproviderid"` + Fieldlist []CancelOrderFieldList `json:"fieldlist"` +} + +type CancelOrderFieldList struct { + Txlogisticid string `json:"txlogisticid"` + Fieldname string `json:"fieldname"` + Fieldvalue string `json:"fieldvalue"` + Remark string `json:"remark"` +} diff --git a/partnerapi/jtexpress/model_response.go b/partnerapi/jtexpress/model_response.go new file mode 100644 index 0000000..04b359a --- /dev/null +++ b/partnerapi/jtexpress/model_response.go @@ -0,0 +1,43 @@ +package jtexpress + +type EstimateFeeItemRes struct { + ProductType string `json:"producttype"` + Price string `json:"price"` + CodFee string `json:"codfee"` + InsuranceFee string `json:"insurancefee"` + DiscountFee string `json:"discountFee"` + Success string `json:"success"` + Reason string `json:"reason"` +} + +type EstimateFeeRes struct { + LogisticProviderID string `json:"logisticproviderid"` + ResponseItems []*EstimateFeeItemRes `json:"responseitems"` +} + +type CreateOrderRes struct { + LogisticProviderID string `json:"logisticproviderid"` + ResponseItems []*CreateOrderItemRes `json:"responseitems"` +} + +type CreateOrderItemRes struct { + Billcode string `json:"billcode"` + CodFee string `json:"codFee"` + Code string `json:"code"` + DiscountFee string `json:"discountFee"` + DispatchSite string `json:"dispatchSite"` + InquiryFee string `json:"inquiryFee"` + Insurancefee string `json:"insurancefee"` + Reason string `json:"reason"` + Reportnewurl string `json:"reportnewurl"` + Reporturl string `json:"reporturl"` + ReporturlJT string `json:"reporturlJT"` + Success string `json:"success"` + Transport string `json:"transport"` + Txlogisticid string `json:"txlogisticid"` +} + +type CancelOrderRes struct { + LogisticProviderID string `json:"logisticproviderid"` + ResponseItems []*CreateOrderItemRes `json:"responseitems"` +} -- 2.34.1 From 9e15bfc101c8de6b6533296e182681da98d0612e Mon Sep 17 00:00:00 2001 From: Sinh Date: Thu, 14 Sep 2023 14:07:34 +0700 Subject: [PATCH 2/8] update jt express --- partnerapi/jtexpress/jtexpress.go | 98 ++++++++++++++------------ partnerapi/jtexpress/model_request.go | 1 - partnerapi/jtexpress/model_response.go | 18 +++++ 3 files changed, 71 insertions(+), 46 deletions(-) diff --git a/partnerapi/jtexpress/jtexpress.go b/partnerapi/jtexpress/jtexpress.go index 2c9cbbb..cc32ccf 100644 --- a/partnerapi/jtexpress/jtexpress.go +++ b/partnerapi/jtexpress/jtexpress.go @@ -10,13 +10,13 @@ import ( "git.selly.red/Selly-Modules/3pl/util/pjson" ) -func New(degestKey, companyID string, isProd, debug bool) *Client { +func New(digestKey, companyID string, isProd, debug bool) *Client { host := apiHostDev if isProd { host = apiHostProd } c := &Client{ - DigestKey: degestKey, + DigestKey: digestKey, EccompanyID: companyID, IsProduction: isProd, Debug: debug, @@ -35,71 +35,79 @@ type Client struct { httpClient *resty.Client } -func (c *Client) EstimateFee(req *EstimateFeeReq) (*EstimateFeeItemRes, error) { +func (c *Client) EstimateFee(req *EstimateFeeReq) (r Response) { path := c.host + apiPathEstimateFee data := pjson.ToJSONString(req) + body := map[string]string{ + "logistics_interface": data, + "data_digest": c.getDigest(data), + "msg_type": msgTypeEstimateFee, + "eccompanyid": c.EccompanyID, + } + r.Request.Body = pjson.ToBytes(body) + r.Request.URL = path resp, err := c.httpClient.R(). - SetFormData(map[string]string{ - "logistics_interface": data, - "data_digest": c.getDigest(data), - "msg_type": msgTypeEstimateFee, - "eccompanyid": c.EccompanyID, - }). - SetResult(&EstimateFeeRes{}). + SetFormData(body). Post(path) if err != nil { - return nil, fmt.Errorf("jtepxress: request %s, err %v", path, err) + r.Error = fmt.Errorf("jtepxress: request %s, err %v", path, err) + return r } - res := resp.Result().(*EstimateFeeRes) - if len(res.ResponseItems) == 0 { - return nil, fmt.Errorf("jtepxress: estimate fee empty response") - } - return res.ResponseItems[0], nil + r.Response.StatusCode = resp.StatusCode() + r.Response.Body = resp.Body() + + return r } -func (c *Client) CancelOrder(req *CancelOrderReq) (*CancelOrderRes, error) { +func (c *Client) CancelOrder(req *CancelOrderReq) (r Response) { path := c.host + apiPathCancelOrder data := pjson.ToJSONString(req) + body := map[string]string{ + "logistics_interface": data, + "data_digest": c.getDigest(data), + "msg_type": msgTypeEstimateFee, + "eccompanyid": c.EccompanyID, + } + r.Request.Body = pjson.ToBytes(body) + r.Request.URL = path resp, err := c.httpClient.R(). - SetFormData(map[string]string{ - "logistics_interface": data, - "data_digest": c.getDigest(data), - "msg_type": msgTypeEstimateFee, - "eccompanyid": c.EccompanyID, - }). - SetResult(&CancelOrderRes{}). + SetFormData(body). Post(path) if err != nil { - return nil, fmt.Errorf("jtepxress: request %s, err %v", path, err) + r.Error = fmt.Errorf("jtepxress: request %s, err %v", path, err) + return r } - res := resp.Result().(*CancelOrderRes) - if len(res.ResponseItems) == 0 { - return nil, fmt.Errorf("jtepxress: cancel order empty response") - } - // return res.ResponseItems[0], nil - return nil, err + + r.Response.StatusCode = resp.StatusCode() + r.Response.Body = resp.Body() + + return r } -func (c *Client) CreateOrder(req *CreateOrderReq) (*CreateOrderItemRes, error) { +func (c *Client) CreateOrder(req *CreateOrderReq) (r Response) { path := c.host + apiPathCreateOrder data := pjson.ToJSONString(req) + body := map[string]string{ + "logistics_interface": data, + "data_digest": c.getDigest(data), + "msg_type": msgTypeCreateOrder, + "eccompanyid": c.EccompanyID, + } + r.Request.Body = pjson.ToBytes(body) + r.Request.URL = path + resp, err := c.httpClient.R(). - SetFormData(map[string]string{ - "logistics_interface": data, - "data_digest": c.getDigest(data), - "msg_type": msgTypeCreateOrder, - "eccompanyid": c.EccompanyID, - }). - SetResult(&CreateOrderRes{}). + SetFormData(body). Post(path) if err != nil { - return nil, fmt.Errorf("jtepxress: request %s, err %v", path, err) + r.Error = fmt.Errorf("jtepxress: request %s, err %v", path, err) + return r } - res := resp.Result().(*CreateOrderRes) - if len(res.ResponseItems) == 0 { - return nil, fmt.Errorf("jtepxress: create order empty response") - } - return res.ResponseItems[0], nil + + r.Response.StatusCode = resp.StatusCode() + r.Response.Body = resp.Body() + + return r } func (c *Client) getDigest(data string) string { diff --git a/partnerapi/jtexpress/model_request.go b/partnerapi/jtexpress/model_request.go index daddc0d..788c33d 100644 --- a/partnerapi/jtexpress/model_request.go +++ b/partnerapi/jtexpress/model_request.go @@ -9,7 +9,6 @@ type EstimateFeeLocation struct { type EstimateFeeReq struct { SelfAddress int `json:"selfAddress"` ProductType string `json:"producttype"` - CusName string `json:"cusname"` GoodsValue string `json:"goodsvalue"` ItemsValue string `json:"itemsvalue"` Weight string `json:"weight"` diff --git a/partnerapi/jtexpress/model_response.go b/partnerapi/jtexpress/model_response.go index 04b359a..7ce3718 100644 --- a/partnerapi/jtexpress/model_response.go +++ b/partnerapi/jtexpress/model_response.go @@ -41,3 +41,21 @@ type CancelOrderRes struct { LogisticProviderID string `json:"logisticproviderid"` ResponseItems []*CreateOrderItemRes `json:"responseitems"` } + +type Response struct { + Request RequestInfo + Response ResponseInfo + Error error +} + +type ResponseInfo struct { + StatusCode int + Body []byte +} + +type RequestInfo struct { + Method string + URL string + Headers map[string]string + Body []byte +} -- 2.34.1 From a929e523247e53ff58dd7e9f08f3989eb33cd00e Mon Sep 17 00:00:00 2001 From: Sinh Date: Thu, 14 Sep 2023 15:23:50 +0700 Subject: [PATCH 3/8] fix jtexpress digest --- partnerapi/jtexpress/jtexpress.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/partnerapi/jtexpress/jtexpress.go b/partnerapi/jtexpress/jtexpress.go index cc32ccf..4ff00f2 100644 --- a/partnerapi/jtexpress/jtexpress.go +++ b/partnerapi/jtexpress/jtexpress.go @@ -7,6 +7,7 @@ import ( "github.com/go-resty/resty/v2" + "git.selly.red/Selly-Modules/3pl/util/base64" "git.selly.red/Selly-Modules/3pl/util/pjson" ) @@ -115,5 +116,5 @@ func (c *Client) getDigest(data string) string { h := md5.New() io.WriteString(h, s) - return fmt.Sprintf("%x", h.Sum(nil)) + return base64.Encode([]byte(fmt.Sprintf("%x", h.Sum(nil)))) } -- 2.34.1 From 5257cd21bc766efcd89d4b730314ba08993b4018 Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 6 Oct 2023 09:25:43 +0700 Subject: [PATCH 4/8] change host jtexpress --- partnerapi/jtexpress/const.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/partnerapi/jtexpress/const.go b/partnerapi/jtexpress/const.go index 84d467f..6a7e3e0 100644 --- a/partnerapi/jtexpress/const.go +++ b/partnerapi/jtexpress/const.go @@ -1,8 +1,8 @@ package jtexpress const ( - apiHostProd = "" - apiHostDev = "https://test.jtexpress.vn" + apiHostProd = "https://ylstandard.jtexpress.vn" + apiHostDev = "https://demo-ylstandard.jtexpress.vn" apiPathEstimateFee = "/yuenan-interface-web/jtpos/inquiry!freight.action" apiPathCreateOrder = "/yuenan-interface-web/order/orderAction!createOrder.action" -- 2.34.1 From 844b01604ab665a10556846959674c492bdc06ac Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 13 Oct 2023 10:42:03 +0700 Subject: [PATCH 5/8] jtexpress update create order --- partnerapi/jtexpress/model_request.go | 1 + 1 file changed, 1 insertion(+) diff --git a/partnerapi/jtexpress/model_request.go b/partnerapi/jtexpress/model_request.go index 788c33d..65a59a9 100644 --- a/partnerapi/jtexpress/model_request.go +++ b/partnerapi/jtexpress/model_request.go @@ -19,6 +19,7 @@ type EstimateFeeReq struct { } type CreateOrderReq struct { + Eccompanyid string `json:"eccompanyid"` Customerid string `json:"customerid"` Txlogisticid string `json:"txlogisticid"` Ordertype int `json:"ordertype"` -- 2.34.1 From 6bf4914aded98163f968de0a64aacb45c2fbac1a Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 13 Oct 2023 11:36:13 +0700 Subject: [PATCH 6/8] change body form data --- partnerapi/jtexpress/jtexpress.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/partnerapi/jtexpress/jtexpress.go b/partnerapi/jtexpress/jtexpress.go index 4ff00f2..34457c2 100644 --- a/partnerapi/jtexpress/jtexpress.go +++ b/partnerapi/jtexpress/jtexpress.go @@ -48,7 +48,7 @@ func (c *Client) EstimateFee(req *EstimateFeeReq) (r Response) { r.Request.Body = pjson.ToBytes(body) r.Request.URL = path resp, err := c.httpClient.R(). - SetFormData(body). + SetMultipartFormData(body). Post(path) if err != nil { r.Error = fmt.Errorf("jtepxress: request %s, err %v", path, err) @@ -72,7 +72,7 @@ func (c *Client) CancelOrder(req *CancelOrderReq) (r Response) { r.Request.Body = pjson.ToBytes(body) r.Request.URL = path resp, err := c.httpClient.R(). - SetFormData(body). + SetMultipartFormData(body). Post(path) if err != nil { r.Error = fmt.Errorf("jtepxress: request %s, err %v", path, err) @@ -98,7 +98,7 @@ func (c *Client) CreateOrder(req *CreateOrderReq) (r Response) { r.Request.URL = path resp, err := c.httpClient.R(). - SetFormData(body). + SetMultipartFormData(body). Post(path) if err != nil { r.Error = fmt.Errorf("jtepxress: request %s, err %v", path, err) -- 2.34.1 From 89d2f1c8fb2519dca1bb1268191feb730b25ee0a Mon Sep 17 00:00:00 2001 From: Sinh Date: Fri, 13 Oct 2023 14:12:22 +0700 Subject: [PATCH 7/8] fix cancel j&t --- partnerapi/jtexpress/const.go | 1 + partnerapi/jtexpress/jtexpress.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/partnerapi/jtexpress/const.go b/partnerapi/jtexpress/const.go index 6a7e3e0..641bf78 100644 --- a/partnerapi/jtexpress/const.go +++ b/partnerapi/jtexpress/const.go @@ -17,4 +17,5 @@ const ( const ( msgTypeEstimateFee = "FREIGHTQUERY" msgTypeCreateOrder = "ORDERCREATE" + msgTypeCancelOrder = "UPDATE" ) diff --git a/partnerapi/jtexpress/jtexpress.go b/partnerapi/jtexpress/jtexpress.go index 34457c2..9823981 100644 --- a/partnerapi/jtexpress/jtexpress.go +++ b/partnerapi/jtexpress/jtexpress.go @@ -66,7 +66,7 @@ func (c *Client) CancelOrder(req *CancelOrderReq) (r Response) { body := map[string]string{ "logistics_interface": data, "data_digest": c.getDigest(data), - "msg_type": msgTypeEstimateFee, + "msg_type": msgTypeCancelOrder, "eccompanyid": c.EccompanyID, } r.Request.Body = pjson.ToBytes(body) -- 2.34.1 From 83201d37af89624bab62a43728f2a7bf60b51499 Mon Sep 17 00:00:00 2001 From: Sinh Date: Mon, 23 Oct 2023 15:42:55 +0700 Subject: [PATCH 8/8] update jtexpress --- partnerapi/jtexpress/model_request.go | 1 + 1 file changed, 1 insertion(+) diff --git a/partnerapi/jtexpress/model_request.go b/partnerapi/jtexpress/model_request.go index 65a59a9..60608ac 100644 --- a/partnerapi/jtexpress/model_request.go +++ b/partnerapi/jtexpress/model_request.go @@ -7,6 +7,7 @@ type EstimateFeeLocation struct { } type EstimateFeeReq struct { + Cusname string `json:"cusname"` // = customerid SelfAddress int `json:"selfAddress"` ProductType string `json:"producttype"` GoodsValue string `json:"goodsvalue"` -- 2.34.1