银豹api,eclp库存api修改
This commit is contained in:
@@ -139,6 +139,23 @@ type SearchShopStockResult struct {
|
|||||||
PageNumber string `json:"pageNumber"`
|
PageNumber string `json:"pageNumber"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QueryStockResult struct {
|
||||||
|
RecordCount int `json:"recordCount"`
|
||||||
|
IsvSku string `json:"isvSku"`
|
||||||
|
DeptName string `json:"deptName"`
|
||||||
|
SellerGoodsSign string `json:"sellerGoodsSign"`
|
||||||
|
GoodsNo string `json:"goodsNo"`
|
||||||
|
UsableNum int `json:"usableNum"`
|
||||||
|
DeptNo string `json:"deptNo"`
|
||||||
|
WarehouseName string `json:"warehouseName"`
|
||||||
|
TotalNum int `json:"totalNum"`
|
||||||
|
StockType string `json:"stockType"`
|
||||||
|
StockStatus string `json:"stockStatus"`
|
||||||
|
GoodsLevel string `json:"goodsLevel"`
|
||||||
|
WarehouseNo string `json:"warehouseNo"`
|
||||||
|
GoodsName string `json:"goodsName"`
|
||||||
|
}
|
||||||
|
|
||||||
func New(accessToken, appKey, appSecret string, config ...*platformapi.APIConfig) *API {
|
func New(accessToken, appKey, appSecret string, config ...*platformapi.APIConfig) *API {
|
||||||
curConfig := platformapi.DefAPIConfig
|
curConfig := platformapi.DefAPIConfig
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@@ -296,7 +313,7 @@ func (a *API) SearchShopStock(goodsNo string) (searchShopStockResult *SearchShop
|
|||||||
|
|
||||||
//查询仓库商品库存
|
//查询仓库商品库存
|
||||||
//https://open.jd.com/home/home#/doc/api?apiCateId=138&apiId=3396&apiName=jingdong.eclp.stock.searchShopStock
|
//https://open.jd.com/home/home#/doc/api?apiCateId=138&apiId=3396&apiName=jingdong.eclp.stock.searchShopStock
|
||||||
func (a *API) QueryStock(goodsNo string) (searchShopStockResult *SearchShopStockResult, err error) {
|
func (a *API) QueryStock(goodsNo string) (queryStockResult []*QueryStockResult, err error) {
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"deptNo": DepartmentNo,
|
"deptNo": DepartmentNo,
|
||||||
"warehouseNo": WarehouseNo,
|
"warehouseNo": WarehouseNo,
|
||||||
@@ -307,7 +324,7 @@ func (a *API) QueryStock(goodsNo string) (searchShopStockResult *SearchShopStock
|
|||||||
}
|
}
|
||||||
result, err := a.AccessAPI("jingdong.eclp.stock.queryStock", prodURL, params)
|
result, err := a.AccessAPI("jingdong.eclp.stock.queryStock", prodURL, params)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
utils.Map2StructByJson(result["jingdong_eclp_stock_queryStock_responce"].(map[string]interface{})["querystock_result"], &searchShopStockResult, false)
|
utils.Map2StructByJson(result["jingdong_eclp_stock_queryStock_responce"].(map[string]interface{})["querystock_result"], &queryStockResult, false)
|
||||||
}
|
}
|
||||||
return searchShopStockResult, err
|
return queryStockResult, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ func TestSearchShopStock(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryStock(t *testing.T) {
|
func TestQueryStock(t *testing.T) {
|
||||||
result, err := api.QueryStock("JX10001")
|
result, err := api.QueryStock("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package yinbaoapi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -16,6 +17,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
sigKey = "sign"
|
sigKey = "sign"
|
||||||
url = "https://area27-win.pospal.cn:443/pospal-api2/openapi/v1"
|
url = "https://area27-win.pospal.cn:443/pospal-api2/openapi/v1"
|
||||||
|
statusSuccess = "success"
|
||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
@@ -58,16 +60,21 @@ func (a *API) signParam(params map[string]interface{}) (sig string) {
|
|||||||
func (a *API) AccessAPI(action string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
func (a *API) AccessAPI(action string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
params := make(map[string]interface{})
|
params := make(map[string]interface{})
|
||||||
params["appId"] = a.appID
|
params["appId"] = a.appID
|
||||||
|
params = utils.MergeMaps(params, bizParams)
|
||||||
fullURL := utils.GenerateGetURL(url, action, nil)
|
fullURL := utils.GenerateGetURL(url, action, nil)
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
func() *http.Request {
|
func() *http.Request {
|
||||||
request, _ := http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
request, _ := http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||||
signStr := a.signParam(params)
|
byteSignStr, _ := json.Marshal(params)
|
||||||
|
signStr := string(byteSignStr) + a.appKey
|
||||||
|
binSig := md5.Sum([]byte(signStr))
|
||||||
|
signStr = fmt.Sprintf("%X", binSig)
|
||||||
request.Header.Set("User-Agent", "openApi")
|
request.Header.Set("User-Agent", "openApi")
|
||||||
request.Header.Set("accept-encoding", "gzip,deflate")
|
request.Header.Set("accept-encoding", "gzip,deflate")
|
||||||
request.Header.Set("data-signature", signStr)
|
request.Header.Set("data-signature", signStr)
|
||||||
request.Header.Set("time-stamp", utils.Int64ToStr(time.Now().Unix()))
|
request.Header.Set("time-stamp", utils.Int64ToStr(time.Now().Unix()))
|
||||||
request.Header.Set("Content-Type", "application/json; charset=utf-8")
|
request.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
fmt.Println(request.Header)
|
||||||
return request
|
return request
|
||||||
},
|
},
|
||||||
a.config,
|
a.config,
|
||||||
@@ -76,9 +83,13 @@ func (a *API) AccessAPI(action string, bizParams map[string]interface{}) (retVal
|
|||||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if jsonResult1["error_response"] != nil {
|
if jsonResult1["status"] != statusSuccess {
|
||||||
errLevel = platformapi.ErrLevelGeneralFail
|
errLevel = platformapi.ErrLevelGeneralFail
|
||||||
err = utils.NewErrorCode(jsonResult1["error_response"].(map[string]interface{})["zh_desc"].(string), jsonResult1["error_response"].(map[string]interface{})["code"].(string))
|
errMsg := ""
|
||||||
|
for _, v := range jsonResult1["messages"].([]interface{}) {
|
||||||
|
errMsg += v.(string)
|
||||||
|
}
|
||||||
|
err = utils.NewErrorCode(errMsg, jsonResult1["status"].(string))
|
||||||
baseapi.SugarLogger.Debugf("jdeclp AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
baseapi.SugarLogger.Debugf("jdeclp AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||||
}
|
}
|
||||||
retVal = jsonResult1
|
retVal = jsonResult1
|
||||||
@@ -88,8 +99,7 @@ func (a *API) AccessAPI(action string, bizParams map[string]interface{}) (retVal
|
|||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddProductInfoParam struct{
|
type ProductInfo struct {
|
||||||
ProductInfo struct {
|
|
||||||
CategoryUID int `json:"categoryUid"`
|
CategoryUID int `json:"categoryUid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Barcode string `json:"barcode"`
|
Barcode string `json:"barcode"`
|
||||||
@@ -101,14 +111,26 @@ type AddProductInfoParam struct{
|
|||||||
IsCustomerDiscount int `json:"isCustomerDiscount"`
|
IsCustomerDiscount int `json:"isCustomerDiscount"`
|
||||||
SupplierUID int `json:"supplierUid"`
|
SupplierUID int `json:"supplierUid"`
|
||||||
Enable int `json:"enable"`
|
Enable int `json:"enable"`
|
||||||
} `json:"productInfo"`
|
}
|
||||||
|
|
||||||
|
type AddProductInfoParam struct {
|
||||||
|
ProductInfo *ProductInfo
|
||||||
AppID string `json:"appId"`
|
AppID string `json:"appId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//新增商品
|
//新增商品
|
||||||
//http://pospal.cn/openplatform/productapi.html#addProductInfo
|
//http://pospal.cn/openplatform/productapi.html#addProductInfo
|
||||||
func (a *API) AddProductInfo(addProductInfoParam *AddProductInfoParam) (err error) {
|
func (a *API) AddProductInfo(addProductInfoParam *AddProductInfoParam) (err error) {
|
||||||
result, err := a.AccessAPI("productOpenApi/addProductInfo", utils.Struct2FlatMap(addProductInfoParam))
|
mapP := map[string]interface{}{
|
||||||
|
"name": addProductInfoParam.ProductInfo.Name,
|
||||||
|
"barcode": addProductInfoParam.ProductInfo.Barcode,
|
||||||
|
"buyPrice": addProductInfoParam.ProductInfo.BuyPrice,
|
||||||
|
"sellPrice": addProductInfoParam.ProductInfo.SellPrice,
|
||||||
|
"stock": addProductInfoParam.ProductInfo.Stock,
|
||||||
|
}
|
||||||
|
str, _ := json.Marshal(mapP)
|
||||||
|
a.AccessAPI("productOpenApi/addProductInfo", map[string]interface{}{
|
||||||
|
"productInfo": string(str),
|
||||||
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,37 @@
|
|||||||
package yinbaoapi
|
package yinbaoapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"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("682628966212343269", "18C0E0867E467DBC26EFF5E957B02EC4")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddProductInfo(t *testing.T) {
|
||||||
|
api.AddProductInfo(&AddProductInfoParam{
|
||||||
|
ProductInfo: &ProductInfo{
|
||||||
|
Name: "测试商品",
|
||||||
|
Barcode: "12138",
|
||||||
|
BuyPrice: 5,
|
||||||
|
SellPrice: 5,
|
||||||
|
Stock: 99,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
// result, err :=
|
||||||
|
// if err != nil {
|
||||||
|
// t.Fatal(err)
|
||||||
|
// }
|
||||||
|
// t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user