This commit is contained in:
邹宗楠
2023-01-13 17:25:09 +08:00
parent eec044c49c
commit a134b95fd0
7 changed files with 56 additions and 39 deletions

View File

@@ -95,7 +95,7 @@ type BaseRespInfo struct {
//计算订单价格请求体
type GetOrderPriceReq struct {
//必填
BaseReqInfo *BaseReqInfo
//BaseReqInfo *BaseReqInfo
OriginID string `json:"origin_id"` //第三方对接平台订单id
FromAddress string `json:"from_address"` //发货地址
ToAddress string `json:"to_address"` //收货人地址
@@ -106,18 +106,18 @@ type GetOrderPriceReq struct {
FromLat string `json:"from_lat"` //发货地址坐标纬度(坐标系为百度地图坐标系)
FromLng string `json:"from_lng"` //发货地址坐标经度(坐标系为百度地图坐标系)
//非必填
FromUserNote string `json:"from_usernote"` //发货详细地址具体门牌号或门店名称
ToUserNote string `json:"to_usernote"` //收货人详细地址具体门牌号
CountyName string `json:"county_name"` //订单所在县级地名称(如金水区就填“金水区”)
SubscribeTime string `json:"subscribe_time"` //预约时间2015-06-18 12:00:00没有可以传空字符串
SubscribeType string `json:"subscribe_type"` //预约类型 0实时订单 1预约取件时间
GoodsType string `json:"goods_type"` //物品类型:(美食、鲜花、蛋糕、手机、钥匙、文件、其他)仅支持指定类型不包含按其他发布
CouponID string `json:"coupon_id"` //优惠券ID(如果传入-1就不用优惠券否则系统自动匹配)
CouponType string `json:"coupon_type"` //优惠券类型 默认空 个人优惠券 1=企业优惠券(必须企业帐号才可以使用)
GoodsWeight int `json:"goods_weight"` //物品重量单位KG按城市标准进行超重计费
ShopID float64 `json:"shop_id"` //门店编号(门店列表可查看门店编号)
GoodsPrice int `json:"goods_price"` //商品保价价格1-10000按照一定费率收取保价费用
UrgentOrder string `json:"urgent_order"` //加急配送默认不开启0=正常配送 1=开启加急配送)
//FromUserNote string `json:"from_usernote"` //发货详细地址具体门牌号或门店名称
//ToUserNote string `json:"to_usernote"` //收货人详细地址具体门牌号
//CountyName string `json:"county_name"` //订单所在县级地名称(如金水区就填“金水区”)
//SubscribeTime string `json:"subscribe_time"` //预约时间2015-06-18 12:00:00没有可以传空字符串
//SubscribeType string `json:"subscribe_type"` //预约类型 0实时订单 1预约取件时间
//GoodsType string `json:"goods_type"` //物品类型:(美食、鲜花、蛋糕、手机、钥匙、文件、其他)仅支持指定类型不包含按其他发布
//CouponID string `json:"coupon_id"` //优惠券ID(如果传入-1就不用优惠券否则系统自动匹配)
//CouponType string `json:"coupon_type"` //优惠券类型 默认空 个人优惠券 1=企业优惠券(必须企业帐号才可以使用)
//GoodsWeight int `json:"goods_weight"` //物品重量单位KG按城市标准进行超重计费
//ShopID int64 `json:"shop_id"` //门店编号(门店列表可查看门店编号)
//GoodsPrice int `json:"goods_price"` //商品保价价格1-10000按照一定费率收取保价费用
//UrgentOrder string `json:"urgent_order"` //加急配送默认不开启0=正常配送 1=开启加急配送)
}
//计算订单价格返回体

View File

@@ -42,8 +42,7 @@ func init() {
//
//计算运单价格
func TestGetWaybillPrice(t *testing.T) {
needPayMoney, priceToken, err := api.GetOrderPrice(&GetOrderPriceReq{
param := &GetOrderPriceReq{
OriginID: "T00001",
FromAddress: "郑州国际会展中心",
ToAddress: "商务外环路17号",
@@ -53,7 +52,9 @@ func TestGetWaybillPrice(t *testing.T) {
ToLng: "113.736445",
FromLat: "34.778494",
FromLng: "113.736858",
})
}
price := utils.Struct2Map(param, "", false)
needPayMoney, priceToken, err := api.GetOrderPrice(price)
fmt.Println(needPayMoney, priceToken, err)
}

View File

@@ -27,8 +27,8 @@ const (
func (a *API) MakeUURequestHead() map[string]interface{} {
requestParam := make(map[string]interface{}, 5)
requestParam["sign"] = a.sign
requestParam["timestamp"] = a.timestamp
requestParam["nonce_str"] = a.noncestr
requestParam["timestamp"] = utils.Int64ToStr(time.Now().Unix())
requestParam["nonce_str"] = randStr()
requestParam["openid"] = a.openid
requestParam["appid"] = a.appid
return requestParam
@@ -54,7 +54,18 @@ func (a *API) signParam(params map[string]interface{}) (sign string) {
keyValues := make([]string, 0)
for k, v := range params {
if k != signKey {
if temp := fmt.Sprint(v); temp != "" {
temp := fmt.Sprint(v)
if k == "goods_weight" && temp == "0" {
continue
}
if k == "shop_id" && temp == "0" {
continue
}
if k == "goods_price" && temp == "0" {
continue
}
if temp != "" {
keyValues = append(keyValues, k+"="+temp)
}
}
@@ -67,8 +78,6 @@ func (a *API) signParam(params map[string]interface{}) (sign string) {
}
func (a *API) AccessAPI(baseUrl, actionApi, method string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
bizParams["timestamp"] = utils.Int64ToStr(time.Now().Unix() * 1000)
bizParams["nonce_str"] = randStr()
bizParams["sign"] = a.signParam(bizParams)
//序列化
data, err := json.Marshal(bizParams)
@@ -86,7 +95,7 @@ func (a *API) AccessAPI(baseUrl, actionApi, method string, bizParams map[string]
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(baseUrl, actionApi, bizParams), nil)
}
//request.Header.Set("Content-Type", "form-data")
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Content-Type", "multipart/form-data")
return request
}
//数据解析

View File

@@ -6,14 +6,9 @@ import (
)
//计算订单价格
func (a *API) GetOrderPrice(req *GetOrderPriceReq) (needPayMoney, priceToken string, err error) {
func (a *API) GetOrderPrice(req map[string]interface{}) (needPayMoney, priceToken string, err error) {
preOrder := a.MakeUURequestHead()
bytes, err := json.Marshal(req)
if err != nil {
return "", "", err
}
preOrder["param"] = string(bytes)
resp, err := a.AccessAPI(BaseURL, "getorderprice.ashx", RequestPost, preOrder)
resp, err := a.AccessAPI(BaseURL, "getorderprice.ashx", RequestPost, utils.MergeMaps(preOrder, req))
if err != nil {
return "", "", err
}