master #14
|
@ -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)
|
||||||
|
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().
|
resp, err := c.httpClient.R().
|
||||||
SetFormData(map[string]string{
|
SetFormData(body).
|
||||||
"logistics_interface": data,
|
|
||||||
"data_digest": c.getDigest(data),
|
|
||||||
"msg_type": msgTypeEstimateFee,
|
|
||||||
"eccompanyid": c.EccompanyID,
|
|
||||||
}).
|
|
||||||
SetResult(&EstimateFeeRes{}).
|
|
||||||
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)
|
||||||
|
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().
|
resp, err := c.httpClient.R().
|
||||||
SetFormData(map[string]string{
|
SetFormData(body).
|
||||||
"logistics_interface": data,
|
|
||||||
"data_digest": c.getDigest(data),
|
|
||||||
"msg_type": msgTypeEstimateFee,
|
|
||||||
"eccompanyid": c.EccompanyID,
|
|
||||||
}).
|
|
||||||
SetResult(&CancelOrderRes{}).
|
|
||||||
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 {
|
r.Response.StatusCode = resp.StatusCode()
|
||||||
return nil, fmt.Errorf("jtepxress: cancel order empty response")
|
r.Response.Body = resp.Body()
|
||||||
}
|
|
||||||
// return res.ResponseItems[0], nil
|
return r
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CreateOrder(req *CreateOrderReq) (*CreateOrderItemRes, error) {
|
func (c *Client) CreateOrder(req *CreateOrderReq) (r Response) {
|
||||||
path := c.host + apiPathCreateOrder
|
path := c.host + apiPathCreateOrder
|
||||||
data := pjson.ToJSONString(req)
|
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().
|
resp, err := c.httpClient.R().
|
||||||
SetFormData(map[string]string{
|
SetFormData(body).
|
||||||
"logistics_interface": data,
|
|
||||||
"data_digest": c.getDigest(data),
|
|
||||||
"msg_type": msgTypeCreateOrder,
|
|
||||||
"eccompanyid": c.EccompanyID,
|
|
||||||
}).
|
|
||||||
SetResult(&CreateOrderRes{}).
|
|
||||||
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