update jt express
This commit is contained in:
parent
b15d883542
commit
9e15bfc101
|
@ -10,13 +10,13 @@ import (
|
||||||
"git.selly.red/Selly-Modules/3pl/util/pjson"
|
"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
|
host := apiHostDev
|
||||||
if isProd {
|
if isProd {
|
||||||
host = apiHostProd
|
host = apiHostProd
|
||||||
}
|
}
|
||||||
c := &Client{
|
c := &Client{
|
||||||
DigestKey: degestKey,
|
DigestKey: digestKey,
|
||||||
EccompanyID: companyID,
|
EccompanyID: companyID,
|
||||||
IsProduction: isProd,
|
IsProduction: isProd,
|
||||||
Debug: debug,
|
Debug: debug,
|
||||||
|
@ -35,71 +35,79 @@ type Client struct {
|
||||||
httpClient *resty.Client
|
httpClient *resty.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) EstimateFee(req *EstimateFeeReq) (*EstimateFeeItemRes, error) {
|
func (c *Client) EstimateFee(req *EstimateFeeReq) (r Response) {
|
||||||
path := c.host + apiPathEstimateFee
|
path := c.host + apiPathEstimateFee
|
||||||
data := pjson.ToJSONString(req)
|
data := pjson.ToJSONString(req)
|
||||||
resp, err := c.httpClient.R().
|
body := map[string]string{
|
||||||
SetFormData(map[string]string{
|
|
||||||
"logistics_interface": data,
|
"logistics_interface": data,
|
||||||
"data_digest": c.getDigest(data),
|
"data_digest": c.getDigest(data),
|
||||||
"msg_type": msgTypeEstimateFee,
|
"msg_type": msgTypeEstimateFee,
|
||||||
"eccompanyid": c.EccompanyID,
|
"eccompanyid": c.EccompanyID,
|
||||||
}).
|
}
|
||||||
SetResult(&EstimateFeeRes{}).
|
r.Request.Body = pjson.ToBytes(body)
|
||||||
|
r.Request.URL = path
|
||||||
|
resp, err := c.httpClient.R().
|
||||||
|
SetFormData(body).
|
||||||
Post(path)
|
Post(path)
|
||||||
if err != nil {
|
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)
|
r.Response.StatusCode = resp.StatusCode()
|
||||||
if len(res.ResponseItems) == 0 {
|
r.Response.Body = resp.Body()
|
||||||
return nil, fmt.Errorf("jtepxress: estimate fee empty response")
|
|
||||||
}
|
return r
|
||||||
return res.ResponseItems[0], nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CancelOrder(req *CancelOrderReq) (*CancelOrderRes, error) {
|
func (c *Client) CancelOrder(req *CancelOrderReq) (r Response) {
|
||||||
path := c.host + apiPathCancelOrder
|
path := c.host + apiPathCancelOrder
|
||||||
data := pjson.ToJSONString(req)
|
data := pjson.ToJSONString(req)
|
||||||
resp, err := c.httpClient.R().
|
body := map[string]string{
|
||||||
SetFormData(map[string]string{
|
|
||||||
"logistics_interface": data,
|
"logistics_interface": data,
|
||||||
"data_digest": c.getDigest(data),
|
"data_digest": c.getDigest(data),
|
||||||
"msg_type": msgTypeEstimateFee,
|
"msg_type": msgTypeEstimateFee,
|
||||||
"eccompanyid": c.EccompanyID,
|
"eccompanyid": c.EccompanyID,
|
||||||
}).
|
}
|
||||||
SetResult(&CancelOrderRes{}).
|
r.Request.Body = pjson.ToBytes(body)
|
||||||
|
r.Request.URL = path
|
||||||
|
resp, err := c.httpClient.R().
|
||||||
|
SetFormData(body).
|
||||||
Post(path)
|
Post(path)
|
||||||
if err != nil {
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CreateOrder(req *CreateOrderReq) (*CreateOrderItemRes, error) {
|
r.Response.StatusCode = resp.StatusCode()
|
||||||
|
r.Response.Body = resp.Body()
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) CreateOrder(req *CreateOrderReq) (r Response) {
|
||||||
path := c.host + apiPathCreateOrder
|
path := c.host + apiPathCreateOrder
|
||||||
data := pjson.ToJSONString(req)
|
data := pjson.ToJSONString(req)
|
||||||
resp, err := c.httpClient.R().
|
body := map[string]string{
|
||||||
SetFormData(map[string]string{
|
|
||||||
"logistics_interface": data,
|
"logistics_interface": data,
|
||||||
"data_digest": c.getDigest(data),
|
"data_digest": c.getDigest(data),
|
||||||
"msg_type": msgTypeCreateOrder,
|
"msg_type": msgTypeCreateOrder,
|
||||||
"eccompanyid": c.EccompanyID,
|
"eccompanyid": c.EccompanyID,
|
||||||
}).
|
}
|
||||||
SetResult(&CreateOrderRes{}).
|
r.Request.Body = pjson.ToBytes(body)
|
||||||
|
r.Request.URL = path
|
||||||
|
|
||||||
|
resp, err := c.httpClient.R().
|
||||||
|
SetFormData(body).
|
||||||
Post(path)
|
Post(path)
|
||||||
if err != nil {
|
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 {
|
r.Response.StatusCode = resp.StatusCode()
|
||||||
return nil, fmt.Errorf("jtepxress: create order empty response")
|
r.Response.Body = resp.Body()
|
||||||
}
|
|
||||||
return res.ResponseItems[0], nil
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) getDigest(data string) string {
|
func (c *Client) getDigest(data string) string {
|
||||||
|
|
|
@ -9,7 +9,6 @@ type EstimateFeeLocation struct {
|
||||||
type EstimateFeeReq struct {
|
type EstimateFeeReq struct {
|
||||||
SelfAddress int `json:"selfAddress"`
|
SelfAddress int `json:"selfAddress"`
|
||||||
ProductType string `json:"producttype"`
|
ProductType string `json:"producttype"`
|
||||||
CusName string `json:"cusname"`
|
|
||||||
GoodsValue string `json:"goodsvalue"`
|
GoodsValue string `json:"goodsvalue"`
|
||||||
ItemsValue string `json:"itemsvalue"`
|
ItemsValue string `json:"itemsvalue"`
|
||||||
Weight string `json:"weight"`
|
Weight string `json:"weight"`
|
||||||
|
|
|
@ -41,3 +41,21 @@ type CancelOrderRes struct {
|
||||||
LogisticProviderID string `json:"logisticproviderid"`
|
LogisticProviderID string `json:"logisticproviderid"`
|
||||||
ResponseItems []*CreateOrderItemRes `json:"responseitems"`
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue