diff --git a/platformapi/jdapi/jdapi_test.go b/platformapi/jdapi/jdapi_test.go index 3b4e96f3..45c6c561 100644 --- a/platformapi/jdapi/jdapi_test.go +++ b/platformapi/jdapi/jdapi_test.go @@ -29,10 +29,12 @@ func init() { // 天天果园 //api = New("c45e6510-00ba-4be2-977e-bcb9c9792cc7", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26") // 京东果园 - api = New("b1138139-9610-4b80-9a63-a63da4773885", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26") + //api = New("b1138139-9610-4b80-9a63-a63da4773885", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26") // 果切 //api = New("0e12f461-2e6b-49ca-bce6-935c6672362d", "f2ed33075faf4773a47e065acd79532b", "aed14cbbecac4456843570e90c5f46ec") + // 京东超市 381564 + api = New("f99d25b8-33a6-4251-a97c-5e24b80b0005", "d2d1e2e3213d4320bc2712a684307831", "1750f5b9848d4a6492c1c20b487074da") //prod zs // api = New("6f8d3290-0120-4ad7-8b53-943c67c84f3f", "789279b9ae814ba091ac52815566b54d", "5d668cd227644637bb0fd73ed8118ec8") // const cookieValue = "YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHCT3RM3CQG7IJIPUQ3THS5UIUYWMKINM7ETUOQB7OBPOPZVCT3ZJY55243TDVXLO25PP4UYSPTTPMNQ7HPMWOJKJ3BJWGVHD243MXH7NZWW264TKN5UOCJBSSSOKD2QQII" diff --git a/platformapi/jdapi/sku_test.go b/platformapi/jdapi/sku_test.go index 78e94dbf..5e0a4bf9 100644 --- a/platformapi/jdapi/sku_test.go +++ b/platformapi/jdapi/sku_test.go @@ -1,5 +1,7 @@ package jdapi +import "testing" + // //import ( // "fmt" @@ -20,15 +22,16 @@ package jdapi // baseapi.SugarLogger.Debug(utils.Format4Output(result, false), err) //} // -//func TestQueryCategoriesByOrgCode(t *testing.T) { -// result, err := api.QueryCategoriesByOrgCode() -// if err != nil { -// t.Fatal(err) -// } -// if len(result) == 0 { -// t.Fatal("QueryCategoriesByOrgCode category list is empty!") -// } -//} +func TestQueryCategoriesByOrgCode(t *testing.T) { + result, err := api.QueryCategoriesByOrgCode() + if err != nil { + t.Fatal(err) + } + if len(result) == 0 { + t.Fatal("QueryCategoriesByOrgCode category list is empty!") + } +} + // //func TestQueryChildCategoriesForOP(t *testing.T) { // result, err := api.QueryChildCategoriesForOP(0) diff --git a/platformapi/jdapi/store_page_test.go b/platformapi/jdapi/store_page_test.go index 6068568e..3c0b4ae4 100644 --- a/platformapi/jdapi/store_page_test.go +++ b/platformapi/jdapi/store_page_test.go @@ -1,6 +1,7 @@ package jdapi import ( + "fmt" "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/utils" "testing" @@ -97,6 +98,12 @@ func TestGetCorporationInfo2(t *testing.T) { baseapi.SugarLogger.Debug(utils.Format4Output(imgList, false)) } +func TestC(t *testing.T) { + a := 58 + a = a | 56 + fmt.Println(a) +} + //func TestGetStoreList(t *testing.T) { // result, err := api.GetStoreList("104.054195", "30.581782") // if err != nil { diff --git a/platformapi/uuptapi/uupt_model.go b/platformapi/uuptapi/uupt_model.go index 84e6500d..57a381ca 100644 --- a/platformapi/uuptapi/uupt_model.go +++ b/platformapi/uuptapi/uupt_model.go @@ -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=开启加急配送) } //计算订单价格返回体 diff --git a/platformapi/uuptapi/uupt_test.go b/platformapi/uuptapi/uupt_test.go index 81e1159a..9d50b923 100644 --- a/platformapi/uuptapi/uupt_test.go +++ b/platformapi/uuptapi/uupt_test.go @@ -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) } diff --git a/platformapi/uuptapi/uuptapi.go b/platformapi/uuptapi/uuptapi.go index f5047d6f..43011599 100644 --- a/platformapi/uuptapi/uuptapi.go +++ b/platformapi/uuptapi/uuptapi.go @@ -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 } //数据解析 diff --git a/platformapi/uuptapi/waybill.go b/platformapi/uuptapi/waybill.go index 5901a924..c0c8fa99 100644 --- a/platformapi/uuptapi/waybill.go +++ b/platformapi/uuptapi/waybill.go @@ -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 }