京东商城订单数据
This commit is contained in:
@@ -151,7 +151,7 @@ func TestBatchWalkingDistance(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAA(t *testing.T) {
|
||||
result, err := autonaviAPI.GetCoordinateAreaInfo(106.56318, 29.62689)
|
||||
result, err := autonaviAPI.GetCoordinateAreaInfo(121.237244, 31.052816)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
113
platformapi/jcqapi/jcqapi.go
Normal file
113
platformapi/jcqapi/jcqapi.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package jcqapi
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
sigKey = "signature"
|
||||
|
||||
httpURL = "jcq-hb-yd-001-httpsrv-nlb-FI.jvessel-open-hb.jdcloud.com:8080"
|
||||
|
||||
TopicCreateOrder = "open_message_pop_order_create_E1D746D42474D5F1F1A10CECE75D99F6"
|
||||
ConsumerGroupIdCreateOrder = "open_message_573819178445"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
platformapi.APICookie
|
||||
|
||||
accessKey string
|
||||
secretKey string
|
||||
client *http.Client
|
||||
config *platformapi.APIConfig
|
||||
}
|
||||
|
||||
func New(accessKey, secretKey string, config ...*platformapi.APIConfig) *API {
|
||||
curConfig := platformapi.DefAPIConfig
|
||||
if len(config) > 0 {
|
||||
curConfig = *config[0]
|
||||
}
|
||||
return &API{
|
||||
accessKey: accessKey,
|
||||
secretKey: secretKey,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
config: &curConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) signParam(params map[string]interface{}) (sig string) {
|
||||
var valueList []string
|
||||
for k, v := range params {
|
||||
if k != sigKey {
|
||||
if str := fmt.Sprint(v); str != "" {
|
||||
valueList = append(valueList, fmt.Sprintf("%s=%s", k, str))
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(sort.StringSlice(valueList))
|
||||
sig = strings.Join(valueList, "&")
|
||||
key := []byte(a.secretKey)
|
||||
mac := hmac.New(sha1.New, key)
|
||||
mac.Write([]byte(sig))
|
||||
sEnc := base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||
return sEnc
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI(action string, url string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||
params := make(map[string]interface{})
|
||||
params["accessKey"] = a.accessKey
|
||||
params["dateTime"] = time.Now()
|
||||
params = utils.MergeMaps(params, bizParams)
|
||||
signStr := a.signParam(params)
|
||||
params["signature"] = signStr
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(url, action, params), nil)
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||
if jsonResult1 == nil {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
if err == nil {
|
||||
if jsonResult1["error"] != nil {
|
||||
errLevel = platformapi.ErrLevelGeneralFail
|
||||
err = utils.NewErrorCode(jsonResult1["error"].(map[string]interface{})["message"].(string), jsonResult1["error"].(map[string]interface{})["code"].(string))
|
||||
baseapi.SugarLogger.Debugf("jdeclp AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||
}
|
||||
retVal = jsonResult1
|
||||
}
|
||||
return errLevel, err
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
type ConsumeInfoResult struct {
|
||||
RequestID string `json:"requestId"`
|
||||
Result string `json:"result"`
|
||||
}
|
||||
|
||||
//消费信息
|
||||
//https://docs.jdcloud.com/cn/message-queue/consume-message
|
||||
func (a *API) ConsumeInfo(topic, consumerGroupId string) (consumeInfoResult *ConsumeInfoResult, err error) {
|
||||
result, err := a.AccessAPI("v1/messages", httpURL, map[string]interface{}{
|
||||
"topic": topic,
|
||||
"consumerGroupId": consumerGroupId,
|
||||
})
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result, &consumeInfoResult, false)
|
||||
}
|
||||
return consumeInfoResult, err
|
||||
}
|
||||
2
platformapi/jcqapi/jcqapi_test.go
Normal file
2
platformapi/jcqapi/jcqapi_test.go
Normal file
@@ -0,0 +1,2 @@
|
||||
package jcqapi
|
||||
|
||||
@@ -23,9 +23,9 @@ func init() {
|
||||
// sandbox
|
||||
// api = New("594ab45a-9a73-4a43-82b0-a64cbd55d883", "06692746f7224695ad4788ce340bc854", "d6b42a35a7414a5490d811654d745c84")
|
||||
// prod
|
||||
// api = New("77e703b7-7997-441b-a12a-2e522efb117a", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4")
|
||||
api = New("77e703b7-7997-441b-a12a-2e522efb117a", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4")
|
||||
// 天天果园
|
||||
api = New("c45e6510-00ba-4be2-977e-bcb9c9792cc7", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26")
|
||||
// api = New("c45e6510-00ba-4be2-977e-bcb9c9792cc7", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26")
|
||||
|
||||
// const cookieValue = "YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHCT3RM3CQG7IJIPUQ3THS5UIUYWMKINM7ETUOQB7OBPOPZVCT3ZJY55243TDVXLO25PP4UYSPTTPMNQ7HPMWOJKJ3BJWGVHD243MXH7NZWW264TKN5UOCJBSSSOKD2QQII"
|
||||
const cookieValue = "YYJV3NHVBPHLD36FWP6F3EM5PTXJ2XZQS7U4HWRIDPP4IWGUKUIB4XG5N26CZRDLDF7PKOXBPD6BNTUAJLETLZOIWMCVFI3K6MYZIY4QBIXIMXYDJNUKFGJVQTN5356SAD6WPCIHWNQAG7DDMF7L7S3SHD6O37OTAHUCKU6ALXATYTGMHNFLM4XRLVSFUQAJR77M4URSZRKVO55243TDVXLO25PP4UYSPTTPMNRUFXDNP4WPE566Q6V4AH32F7HT"
|
||||
|
||||
@@ -158,7 +158,7 @@ func TestAddShopCategory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDelShopCategory(t *testing.T) {
|
||||
err := api.DelShopCategory(4784689)
|
||||
err := api.DelShopCategory(5259045)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -37,12 +37,19 @@ func (a *API) GetDeliveryCompany() (result interface{}, err error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
type GetOrderResult struct {
|
||||
}
|
||||
|
||||
//查询单个订单
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=55&apiId=4247&apiName=jingdong.pop.order.get
|
||||
func (a *API) GetOrder(orderID int64) (err error) {
|
||||
_, err = a.AccessAPI("jingdong.pop.order.get", prodURL, map[string]interface{}{
|
||||
"order_id": orderID,
|
||||
"optional_fields": "orderType,payType,orderTotalPrice,orderSellerPrice,orderPayment,freightPrice",
|
||||
"order_id": orderID,
|
||||
"optional_fields": `orderType,payType,orderTotalPrice,orderSellerPrice,
|
||||
orderPayment,freightPrice,orderState,orderStateRemark,
|
||||
orderStartTime,orderEndTime,orderRemark,consigneeInfo,
|
||||
itemInfoList,pauseBizInfo`,
|
||||
"order_state": "WAIT_SELLER_STOCK_OUT,PAUSE",
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestGetProvince(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCity(t *testing.T) {
|
||||
result, err := api.GetCity(5)
|
||||
result, err := api.GetCity(2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func TestGetCity(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCounty(t *testing.T) {
|
||||
result, err := api.GetCounty(199)
|
||||
result, err := api.GetCounty(2834)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user