物料下单测试,微信发票
This commit is contained in:
@@ -26,16 +26,16 @@ const (
|
||||
|
||||
// CustomerCode2 = "028K588716"
|
||||
|
||||
state = "1212"
|
||||
orderType10 = "10" //订单号类型(10:代表ECLP订单号, 20:代表商家订单号)
|
||||
orderType20 = "20"
|
||||
state = "1212"
|
||||
orderType10 = "10" //订单号类型(10:代表ECLP订单号, 20:代表商家订单号)
|
||||
orderType20 = "20"
|
||||
SalePlatformSource = "6"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
accessToken string
|
||||
appKey string
|
||||
appSecret string
|
||||
redirectUri string
|
||||
client *http.Client
|
||||
config *platformapi.APIConfig
|
||||
}
|
||||
@@ -131,7 +131,7 @@ type SearchShopStockResult struct {
|
||||
PageNumber string `json:"pageNumber"`
|
||||
}
|
||||
|
||||
func New(accessToken, appKey, appSecret, redirectUri string, config ...*platformapi.APIConfig) *API {
|
||||
func New(accessToken, appKey, appSecret string, config ...*platformapi.APIConfig) *API {
|
||||
curConfig := platformapi.DefAPIConfig
|
||||
if len(config) > 0 {
|
||||
curConfig = *config[0]
|
||||
@@ -140,7 +140,6 @@ func New(accessToken, appKey, appSecret, redirectUri string, config ...*platform
|
||||
accessToken: accessToken,
|
||||
appKey: appKey,
|
||||
appSecret: appSecret,
|
||||
redirectUri: redirectUri,
|
||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||
config: &curConfig,
|
||||
}
|
||||
@@ -177,10 +176,12 @@ func (a *API) AccessAPI(action string, url string, bizParams map[string]interfac
|
||||
params["access_token"] = a.accessToken
|
||||
params["app_key"] = a.appKey
|
||||
params["timestamp"] = utils.Time2Str(time.Now())
|
||||
params["method"] = action
|
||||
params["v"] = "2.0"
|
||||
params = utils.MergeMaps(params, bizParams)
|
||||
signStr := a.signParam(params)
|
||||
params["sign"] = signStr
|
||||
fullURL = utils.GenerateGetURL(url, "method="+action, nil)
|
||||
fullURL = utils.GenerateGetURL(url, "", nil)
|
||||
}
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
@@ -210,22 +211,22 @@ func (a *API) AccessAPI(action string, url string, bizParams map[string]interfac
|
||||
|
||||
//获取销售平台信息
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=138&apiId=947&apiName=jingdong.eclp.master.querySpSource
|
||||
func (a *API) QuerySpSource() (querySpSourceResult *QuerySpSourceResult, err error) {
|
||||
func (a *API) QuerySpSource() (querySpSourceResult []*QuerySpSourceResult, err error) {
|
||||
result, err := a.AccessAPI("jingdong.eclp.master.querySpSource", prodURL, nil)
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result, &querySpSourceResult, false)
|
||||
utils.Map2StructByJson(result["jingdong_eclp_master_querySpSource_responce"].(map[string]interface{})["queryspsource_result"], &querySpSourceResult, false)
|
||||
}
|
||||
return querySpSourceResult, err
|
||||
}
|
||||
|
||||
//销售出库单下发
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=138&apiId=928&apiName=jingdong.eclp.order.addOrder
|
||||
func (a *API) AddOrder(addOrderParam *AddOrderParam) (addOrderResult *AddOrderResult, err error) {
|
||||
func (a *API) AddOrder(addOrderParam *AddOrderParam) (eclpSoNo string, err error) {
|
||||
result, err := a.AccessAPI("jingdong.eclp.order.addOrder", prodURL, utils.Struct2FlatMap(addOrderParam))
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result, &addOrderResult, false)
|
||||
return result["eclpSoNo"].(string), err
|
||||
}
|
||||
return addOrderResult, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
//销售出库单取消
|
||||
@@ -278,32 +279,33 @@ func (a *API) SearchShopStock(searchShopStockParam *SearchShopStockParam) (searc
|
||||
|
||||
//获取tokenCode
|
||||
//https://oauth.jd.com/oauth/authorize?response_type=code&client_id=YOUR_APP_KEY&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&state=YOUR_CUSTOM_CODE
|
||||
func (a *API) GetTokenInfo() (code string, err error) {
|
||||
result, err := a.AccessAPI("authorize", prodURL2, map[string]interface{}{
|
||||
"response_type": "code",
|
||||
"client_id": a.appKey,
|
||||
"redirect_uri": a.redirectUri,
|
||||
"state": state,
|
||||
})
|
||||
if err == nil {
|
||||
code = result["code"].(string)
|
||||
}
|
||||
return code, err
|
||||
}
|
||||
//https://oauth.jd.com/oauth/authorize?response_type=code&client_id=YOUR_APP_KEY&redirect_uri=urn:ietf:wg:oauth:2.0:oob&state=1212
|
||||
// func (a *API) GetTokenInfo() (code string, err error) {
|
||||
// result, err := a.AccessAPI("authorize", prodURL2, map[string]interface{}{
|
||||
// "response_type": "code",
|
||||
// "client_id": a.appKey,
|
||||
// "redirect_uri": a.redirectUri,
|
||||
// "state": state,
|
||||
// })
|
||||
// if err == nil {
|
||||
// code = result["code"].(string)
|
||||
// }
|
||||
// return code, err
|
||||
// }
|
||||
|
||||
//获取token
|
||||
//https://oauth.jd.com/oauth/token?grant_type=authorization_code&client_id=YOUR_APP_KEY&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&code=GET_CODE&state=YOUR_CUSTOM_CODE&client_secret= YOUR_APP_SECRET
|
||||
func (a *API) GetToken() (token string, err error) {
|
||||
code, err := a.GetTokenInfo()
|
||||
result, err := a.AccessAPI("token", prodURL2, map[string]interface{}{
|
||||
"grant_type": "authorization_code",
|
||||
"client_id": a.appKey,
|
||||
"redirect_uri": a.redirectUri,
|
||||
"code": code,
|
||||
"state": state,
|
||||
})
|
||||
if err == nil {
|
||||
token = result["token"].(string)
|
||||
}
|
||||
return token, err
|
||||
}
|
||||
// func (a *API) GetToken() (token string, err error) {
|
||||
// code, err := a.GetTokenInfo()
|
||||
// result, err := a.AccessAPI("token", prodURL2, map[string]interface{}{
|
||||
// "grant_type": "authorization_code",
|
||||
// "client_id": a.appKey,
|
||||
// "redirect_uri": a.redirectUri,
|
||||
// "code": code,
|
||||
// "state": state,
|
||||
// })
|
||||
// if err == nil {
|
||||
// token = result["token"].(string)
|
||||
// }
|
||||
// return token, err
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user