From 805f0d2f5af6b006e1635113bd24dcb3ce77fef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 1 Dec 2020 15:51:47 +0800 Subject: [PATCH] aa --- platformapi/ejyapi/ejyapi.go | 95 +++++++++++++++++++++++++++++++ platformapi/ejyapi/ejyapi_test.go | 25 ++++++++ platformapi/jdshopapi/order.go | 3 +- 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 platformapi/ejyapi/ejyapi.go create mode 100644 platformapi/ejyapi/ejyapi_test.go diff --git a/platformapi/ejyapi/ejyapi.go b/platformapi/ejyapi/ejyapi.go new file mode 100644 index 00000000..0859e2f0 --- /dev/null +++ b/platformapi/ejyapi/ejyapi.go @@ -0,0 +1,95 @@ +package ejyapi + +import ( + "crypto/md5" + "fmt" + "net/http" + "sort" + "strings" + + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/baseapi/platformapi" + "git.rosy.net.cn/baseapi/utils" +) + +const ( + sigKey = "sign" + TestUrl = "https://dev.ejiayou.com" +) + +type API struct { + platformName string + timeStamp int64 + beforeKey string + afterKey string + client *http.Client + config *platformapi.APIConfig +} + +func New(platformName string, timeStamp int64, beforeKey, afterKey string, config ...*platformapi.APIConfig) *API { + curConfig := platformapi.DefAPIConfig + if len(config) > 0 { + curConfig = *config[0] + } + return &API{ + platformName: platformName, + timeStamp: timeStamp, + beforeKey: beforeKey, + afterKey: afterKey, + 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)) + valueList = append(valueList, fmt.Sprintf("timestamp=%d", a.timeStamp)) + valueList = append(valueList, fmt.Sprintf("beforeKey=%s", a.beforeKey)) + valueList = append(valueList, fmt.Sprintf("afterKey=%s", a.afterKey)) + sig = strings.Join(valueList, "&") + fmt.Println(sig) + binSig := md5.Sum([]byte(sig)) + sig = fmt.Sprintf("%X", binSig) + return sig +} + +func (a *API) AccessAPI(action string, url string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) { + + err = platformapi.AccessPlatformAPIWithRetry(a.client, + func() *http.Request { + request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(url, action, nil), 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_response"] != nil { + errLevel = platformapi.ErrLevelGeneralFail + err = utils.NewErrorCode(jsonResult1["error_response"].(map[string]interface{})["zh_desc"].(string), jsonResult1["error_response"].(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 +} + +func (a *API) GetStationList() (err error) { + params := make(map[string]interface{}) + params["platformName"] = a.platformName + sign := a.signParam(params) + _, err = a.AccessAPI("oreo/ejiayou_open_api/stations/v2/"+a.platformName+"/"+sign+"/"+utils.Int64ToStr(a.timeStamp), TestUrl, nil) + return err +} diff --git a/platformapi/ejyapi/ejyapi_test.go b/platformapi/ejyapi/ejyapi_test.go new file mode 100644 index 00000000..4248deed --- /dev/null +++ b/platformapi/ejyapi/ejyapi_test.go @@ -0,0 +1,25 @@ +package ejyapi + +import ( + "testing" + "time" + + "git.rosy.net.cn/baseapi" + "go.uber.org/zap" +) + +var ( + api *API + sugarLogger *zap.SugaredLogger +) + +func init() { + logger, _ := zap.NewDevelopment() + sugarLogger = logger.Sugar() + baseapi.Init(sugarLogger) + api = New("1Zbve", time.Now().Unix(), "ymsrrxlZXlmglK6Q", "MYsFZGgwwprIahzQ") +} + +func TestGetStationList(t *testing.T) { + api.GetStationList() +} diff --git a/platformapi/jdshopapi/order.go b/platformapi/jdshopapi/order.go index ae6c8408..c150db1e 100644 --- a/platformapi/jdshopapi/order.go +++ b/platformapi/jdshopapi/order.go @@ -100,6 +100,7 @@ type GetOrderResult struct { IDSopShipmenttype string `json:"idSopShipmenttype"` ScDT string `json:"scDT"` SellerDiscount string `json:"sellerDiscount"` + MenDianId string `json:"menDianId"` } //查询单个订单 @@ -110,7 +111,7 @@ func (a *API) GetOrder(orderID int64, isStatus bool) (getOrderResult *GetOrderRe params["optional_fields"] = `orderType,payType,orderTotalPrice,orderSellerPrice, orderPayment,freightPrice,orderState,orderStateRemark, orderStartTime,orderEndTime,orderRemark,consigneeInfo, - itemInfoList,pauseBizInfo,pin,idSopShipmenttype,scDT,sellerDiscount` + itemInfoList,pauseBizInfo,pin,idSopShipmenttype,scDT,sellerDiscount,menDianId` if isStatus { params["order_state"] = "WAIT_SELLER_STOCK_OUT,TRADE_CANCELED,PAUSE,WAIT_GOODS_RECEIVE_CONFIRM" }