From 32679b215f5404579efde5a97ed0d56a32c5c63a Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 26 Oct 2022 10:19:08 +0800 Subject: [PATCH 1/3] 1 --- platformapi/jdapi/jdapi.go | 1 + platformapi/tiktok_shop/tiktok_api/store.go | 1 - platformapi/tiktok_shop/tiktok_api/store_test.go | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index b0ffa7d4..2f9fa6ac 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -379,6 +379,7 @@ func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{}, localJdParams[KeyPageNo] = curPage localJdParams[KeyPageSize] = pageSize jsonResult, err := a.AccessAPI(apiStr, localJdParams) + if err != nil { return nil, totalCount, err } diff --git a/platformapi/tiktok_shop/tiktok_api/store.go b/platformapi/tiktok_shop/tiktok_api/store.go index b15984a4..d00b1918 100644 --- a/platformapi/tiktok_shop/tiktok_api/store.go +++ b/platformapi/tiktok_shop/tiktok_api/store.go @@ -238,7 +238,6 @@ func (a *API) GetStoreFreight(storeId int64) ([]int64, error) { if result.Code != RequestSuccessCode { return nil, errors.New(result.SubMsg) } - tempList := make([]int64, 0) for _, v := range result.Data.StoreFreights { tempList = append(tempList, v.FreightId) diff --git a/platformapi/tiktok_shop/tiktok_api/store_test.go b/platformapi/tiktok_shop/tiktok_api/store_test.go index 8500662e..4ad0558c 100644 --- a/platformapi/tiktok_shop/tiktok_api/store_test.go +++ b/platformapi/tiktok_shop/tiktok_api/store_test.go @@ -150,14 +150,14 @@ func TestCreateFence(t *testing.T) { a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token) param := &warehouse_createFence_request.WarehouseCreateFenceParam{ FenceInfo: &warehouse_createFence_request.FenceInfo{ - OutFenceId: "668410-2", + OutFenceId: "667094", Shape: 1, Circular: &warehouse_createFence_request.Circular{ Center: &warehouse_createFence_request.Center{ - Longitude: 104.056976, - Latitude: 30.755311, + Longitude: 116.686026, + Latitude: 39.884685, }, - Radius: 100000, + Radius: 30000, }, }, } From c37c869c33e7a49090e516e50ea4bcaabba388e8 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 26 Oct 2022 14:33:29 +0800 Subject: [PATCH 2/3] jd decode --- platformapi/jdapi/jdapi.go | 36 ++++++++++++++++------ platformapi/jdapi/jdapi_test.go | 16 +++++++++- platformapi/jdapi/order_test.go | 2 +- platformapi/jdapi/store_sku_test.go | 46 ++++++++++++++--------------- utils/errorwithcode.go | 31 +++++++++++++++++++ utils/utils_crypt.go | 3 ++ 6 files changed, 100 insertions(+), 34 deletions(-) diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index 72ff3345..da8297d5 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -3,10 +3,10 @@ package jdapi import ( "bytes" "crypto/md5" + "encoding/base64" "encoding/json" "errors" "fmt" - "git.rosy.net.cn/jx-callback/globals" "net/http" "reflect" "sort" @@ -285,10 +285,13 @@ func (a *API) AccessAPINoPage2(apiStr string, jdParams map[string]interface{}, k if jsonResult["code"].(string) != "0" { return nil, errors.New(jsonResult["msg"].(string)) } - if jsonResult["data"] == nil || utils.IsNil(jsonResult["data"]) { - return nil, errors.New("data is nil") + if (jsonResult["data"] == nil || utils.IsNil(jsonResult["data"])) && (jsonResult["encryptData"] != nil || utils.IsNil(jsonResult["encryptData"])) { + decodeData, err := JDDecodeToData(a.appSecret, jsonResult["encryptData"].(string)) + if err != nil { + return nil, err + } + jsonResult["data"] = decodeData } - globals.SugarLogger.Debugf("====AccessAPINoPage2============%s", utils.Format4Output(jsonResult, false)) var data map[string]interface{} if err := utils.UnmarshalUseNumber([]byte(jsonResult["data"].(string)), &data); err != nil { return nil, platformapi.ErrResponseDataFormatWrong @@ -311,13 +314,14 @@ func genNormalHavePageResultParser(dataKey string) (handler PageResultParser) { var retVal []interface{} tempResult := data[dataKey] + var result0 = make(map[string]interface{}, 0) if resultStr, ok := tempResult.(string); ok { - if err := utils.UnmarshalUseNumber([]byte(resultStr), &tempResult); err != nil { + if err := utils.UnmarshalUseNumber([]byte(resultStr), &result0); err != nil { return nil, 0, platformapi.ErrResponseDataFormatWrong } } - result = tempResult.(map[string]interface{}) + result = result0 if totalCount == 0 { for _, totalCountKey := range havePageTotalCountKeys { @@ -388,15 +392,15 @@ func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{}, localJdParams[KeyPageNo] = curPage localJdParams[KeyPageSize] = pageSize jsonResult, err := a.AccessAPI(apiStr, localJdParams) - if err != nil { return nil, totalCount, err } var data map[string]interface{} - if err := utils.UnmarshalUseNumber([]byte(jsonResult["data"].(string)), &data); err != nil { + encryptData, err := JDDecodeToData(a.appSecret, jsonResult["encryptData"].(string)) + + if err := utils.UnmarshalUseNumber([]byte(encryptData), &data); err != nil { return nil, totalCount, platformapi.ErrResponseDataFormatWrong } - innerCode := forceInnerCode2Str(data["code"]) if innerCode != "0" { err2 := utils.NewErrorCode(getErrMsgFromData(data), innerCode, 1) @@ -460,3 +464,17 @@ func JavaDateHook(fromType reflect.Type, toType reflect.Type, data interface{}) func JdMap2StructByJson(inObj interface{}, outObjAddr interface{}, weaklyTypedInput bool) (err error) { return utils.Map2Struct(inObj, outObjAddr, true, "", JavaDateHook) } + +func JDDecodeToData(appSecret, data string) (string, error) { + key := appSecret[:16] + iv := appSecret[16:32] + sDec, err := base64.StdEncoding.DecodeString(data) + if err != nil { + return "", err + } + resp, err := utils.AESCBCDecpryt(sDec, []byte(key), []byte(iv)) + if err != nil { + return "", err + } + return string(resp), nil +} diff --git a/platformapi/jdapi/jdapi_test.go b/platformapi/jdapi/jdapi_test.go index 73e51955..316c7c22 100644 --- a/platformapi/jdapi/jdapi_test.go +++ b/platformapi/jdapi/jdapi_test.go @@ -1,6 +1,8 @@ package jdapi import ( + "encoding/base64" + "fmt" "net/http" "testing" @@ -23,7 +25,7 @@ func init() { // sandbox // api = New("594ab45a-9a73-4a43-82b0-a64cbd55d883", "06692746f7224695ad4788ce340bc854", "d6b42a35a7414a5490d811654d745c84") // prod - api = New("73e2e9f6-b21e-4dcd-8c92-71e4e100b07e", "21b627c23ea04c69b64b48d0b361213e", "51cd27a748e64c829b4b7f83f4844610") + api = New("73e2e9f6-b21e-4dcd-8c92-71e4e100b07e", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4") // 天天果园 //api = New("c45e6510-00ba-4be2-977e-bcb9c9792cc7", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26") // 京东果园 @@ -57,6 +59,18 @@ func TestAccessAPI(t *testing.T) { } } +func TestGet(t *testing.T) { + key := "0bcbe9d6e6124cf2" + iv := "aef2856a540f1326" + decryDetail := "8FvHJcQmVojAIU61SNaS1ermHN2UVWknueRHFSNf2q5EbxNNmznoTYpRu7ySc/8CuU+QGZ9UIBMCyTuFafY3PuszEokEKc8M1Qfv/+o15h5bIU8LXfwRKOCm3JYzZtTOvJVU0hk/USvtDgraToszFl2hQZjZN5gGH1af0X8vopo=" + sDec, err := base64.StdEncoding.DecodeString(decryDetail) + data, err := utils.AESCBCDecpryt(sDec, []byte(key), []byte(iv)) + localJdParams := make(map[string]interface{}) + ans, err := utils.Unmarshal2Map(data[:len(sDec)], localJdParams) + fmt.Println(ans["billId"]) + fmt.Println(err) +} + func TestAccessAPINoPage(t *testing.T) { result, err := api.AccessAPINoPage("address/allcities", nil, []string{"yn"}, nil, nil) if err != nil { diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index bb2d7a84..2a1acbe9 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -30,7 +30,7 @@ func TestPickUp(t *testing.T) { func TestOrderQuery(t *testing.T) { jdParams := map[string]interface{}{ - "orderId": "813344594000041", + "orderId": "2225735125000294", } result, totalCount, err := api.OrderQuery(jdParams) if err != nil { diff --git a/platformapi/jdapi/store_sku_test.go b/platformapi/jdapi/store_sku_test.go index c1738515..19c06dca 100644 --- a/platformapi/jdapi/store_sku_test.go +++ b/platformapi/jdapi/store_sku_test.go @@ -31,30 +31,30 @@ func TestDelVipPrice(t *testing.T) { // t.Log(utils.Format4Output(result, false)) } -func TestQueryOpenUseable(t *testing.T) { - result, err := api.QueryOpenUseable([]*BaseStockCenterRequest{ - &BaseStockCenterRequest{ - StationNo: mustExistStoreID, - SkuId: mustExistSkuID, - }, - }) - if err != nil { - t.Fatal(err) - } - t.Log(utils.Format4Output(result, false)) -} +//func TestQueryOpenUseable(t *testing.T) { +// result, err := api.QueryOpenUseable([]*BaseStockCenterRequest{ +// &BaseStockCenterRequest{ +// StationNo: mustExistStoreID, +// SkuId: mustExistSkuID, +// }, +// }) +// if err != nil { +// t.Fatal(err) +// } +// t.Log(utils.Format4Output(result, false)) +//} -func TestQueryStockCenter(t *testing.T) { - result, err := api.QueryStockCenter(mustExistStoreJXID, []*SkuIdEntity{ - &SkuIdEntity{ - OutSkuId: mustExistSkuJXID, - }, - }, "test") - if err != nil { - t.Fatal(err) - } - t.Log(utils.Format4Output(result, false)) -} +//func TestQueryStockCenter(t *testing.T) { +// result, err := api.QueryStockCenter(mustExistStoreJXID, []*SkuIdEntity{ +// &SkuIdEntity{ +// OutSkuId: mustExistSkuJXID, +// }, +// }, "test") +// if err != nil { +// t.Fatal(err) +// } +// t.Log(utils.Format4Output(result, false)) +//} func TestBatchUpdateVendibility(t *testing.T) { result, err := api.BatchUpdateVendibility("", "100130", "", []*StockVendibility{ diff --git a/utils/errorwithcode.go b/utils/errorwithcode.go index 27f26d77..784f917a 100644 --- a/utils/errorwithcode.go +++ b/utils/errorwithcode.go @@ -1,6 +1,8 @@ package utils import ( + "crypto/aes" + "encoding/base64" "fmt" "strconv" "strings" @@ -27,6 +29,35 @@ func NewErrorCode(errMsg, code string, level ...int) *ErrorWithCode { return retVal } +func DecryptDESECB(d, key []byte) string { + data, err := base64.StdEncoding.DecodeString(string(d)) + if err != nil { + return "" + } + block, err := aes.NewCipher(key) + if err != nil { + return "" + } + bs := block.BlockSize() + if len(data)%bs != 0 { + return "" + } + out := make([]byte, len(data)) + dst := out + for len(data) > 0 { + block.Decrypt(dst, data[:bs]) + data = data[bs:] + dst = dst[bs:] + } + out = PKCS5UnPadding(out) + return string(out) +} +func PKCS5UnPadding(origData []byte) []byte { + length := len(origData) + unpadding := int(origData[length-1]) + return origData[:(length - unpadding)] +} + func NewErrorIntCode(errMsg string, code int, level ...int) *ErrorWithCode { return NewErrorCode(errMsg, Int2Str(code), level...) } diff --git a/utils/utils_crypt.go b/utils/utils_crypt.go index 01053d73..3892a67d 100644 --- a/utils/utils_crypt.go +++ b/utils/utils_crypt.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/aes" "crypto/cipher" + "fmt" ) func AESCBCEncpryt(data, aesKey, iv []byte) (encryptedData []byte, err error) { @@ -23,9 +24,11 @@ func AESCBCDecpryt(encryptedData, aesKey, iv []byte) (decryptedData []byte, err if err != nil { return nil, err } + fmt.Println(c.BlockSize(), len(encryptedData)) cfbdec := cipher.NewCBCDecrypter(c, iv[:c.BlockSize()]) decryptedData = make([]byte, len(encryptedData)) cfbdec.CryptBlocks(decryptedData, encryptedData) + decryptedData = PKCSUnPadding(decryptedData) return decryptedData, nil } From fce03afdc2c7f1183c571038fe88f5de524bd268 Mon Sep 17 00:00:00 2001 From: richboo111 Date: Wed, 26 Oct 2022 18:16:56 +0800 Subject: [PATCH 3/3] 1 --- platformapi/jdapi/store_sku_test.go | 3 ++- platformapi/tiktok_shop/tiktok_api/store.go | 12 ++++++++---- platformapi/tiktok_shop/tiktok_api/store_test.go | 7 +++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/platformapi/jdapi/store_sku_test.go b/platformapi/jdapi/store_sku_test.go index 19c06dca..5b5c1945 100644 --- a/platformapi/jdapi/store_sku_test.go +++ b/platformapi/jdapi/store_sku_test.go @@ -28,7 +28,8 @@ func TestDelVipPrice(t *testing.T) { if err != nil { t.Fatal(err) } - // t.Log(utils.Format4Output(result, false)) + t.Fatal(err) + //t.Log(utils.Format4Output(result, false)) } //func TestQueryOpenUseable(t *testing.T) { diff --git a/platformapi/tiktok_shop/tiktok_api/store.go b/platformapi/tiktok_shop/tiktok_api/store.go index d00b1918..e603aa27 100644 --- a/platformapi/tiktok_shop/tiktok_api/store.go +++ b/platformapi/tiktok_shop/tiktok_api/store.go @@ -238,11 +238,15 @@ func (a *API) GetStoreFreight(storeId int64) ([]int64, error) { if result.Code != RequestSuccessCode { return nil, errors.New(result.SubMsg) } - tempList := make([]int64, 0) - for _, v := range result.Data.StoreFreights { - tempList = append(tempList, v.FreightId) + if len(result.Data.StoreFreights) == 0 { + return []int64{0}, err + } else { + tempList := make([]int64, 0) + for _, v := range result.Data.StoreFreights { + tempList = append(tempList, v.FreightId) + } + return tempList, err } - return tempList, err } // 获取门店绑定的运费模板 diff --git a/platformapi/tiktok_shop/tiktok_api/store_test.go b/platformapi/tiktok_shop/tiktok_api/store_test.go index 4ad0558c..564aca29 100644 --- a/platformapi/tiktok_shop/tiktok_api/store_test.go +++ b/platformapi/tiktok_shop/tiktok_api/store_test.go @@ -255,3 +255,10 @@ func TestUpdateStore(t *testing.T) { err := a.EditStore(param) fmt.Println(err) } +func TestGetStoreBindFreight(t *testing.T) { + accesstoken := `{"access_token":"47690a84-3cc2-4958-abf9-41cc7fca5f82","expires_in":1666862533,"scope":"SCOPE","shop_id":"","shop_name":"小时达开放平台对接专用店","refresh_token":"66ea2395-07c7-409d-84ae-93ac1e600b74","authority_id":""}` + a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", accesstoken) + resp, err := a.GetStoreFreight(668619) + fmt.Println(resp) + fmt.Println(err) +}