Merge branch 'master' of e.coding.net:rosydev/baseapi
This commit is contained in:
@@ -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 {
|
||||
@@ -392,10 +396,11 @@ func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{},
|
||||
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)
|
||||
@@ -459,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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package jdapi
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestPickUp(t *testing.T) {
|
||||
|
||||
func TestOrderQuery(t *testing.T) {
|
||||
jdParams := map[string]interface{}{
|
||||
"orderId": "2225712287000273",
|
||||
"orderId": "2225735125000294",
|
||||
}
|
||||
result, totalCount, err := api.OrderQuery(jdParams)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,10 +28,10 @@ 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) {
|
||||
// result, err := api.QueryOpenUseable([]*BaseStockCenterRequest{
|
||||
// &BaseStockCenterRequest{
|
||||
@@ -44,7 +44,7 @@ func TestDelVipPrice(t *testing.T) {
|
||||
// }
|
||||
// t.Log(utils.Format4Output(result, false))
|
||||
//}
|
||||
//
|
||||
|
||||
//func TestQueryStockCenter(t *testing.T) {
|
||||
// result, err := api.QueryStockCenter(mustExistStoreJXID, []*SkuIdEntity{
|
||||
// &SkuIdEntity{
|
||||
|
||||
@@ -238,12 +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
|
||||
}
|
||||
|
||||
// 获取门店绑定的运费模板
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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...)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user