Merge branch 'master' of e.coding.net:rosydev/baseapi
This commit is contained in:
@@ -3,10 +3,10 @@ package jdapi
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -285,10 +285,13 @@ func (a *API) AccessAPINoPage2(apiStr string, jdParams map[string]interface{}, k
|
|||||||
if jsonResult["code"].(string) != "0" {
|
if jsonResult["code"].(string) != "0" {
|
||||||
return nil, errors.New(jsonResult["msg"].(string))
|
return nil, errors.New(jsonResult["msg"].(string))
|
||||||
}
|
}
|
||||||
if jsonResult["data"] == nil || utils.IsNil(jsonResult["data"]) {
|
if (jsonResult["data"] == nil || utils.IsNil(jsonResult["data"])) && (jsonResult["encryptData"] != nil || utils.IsNil(jsonResult["encryptData"])) {
|
||||||
return nil, errors.New("data is nil")
|
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{}
|
var data map[string]interface{}
|
||||||
if err := utils.UnmarshalUseNumber([]byte(jsonResult["data"].(string)), &data); err != nil {
|
if err := utils.UnmarshalUseNumber([]byte(jsonResult["data"].(string)), &data); err != nil {
|
||||||
return nil, platformapi.ErrResponseDataFormatWrong
|
return nil, platformapi.ErrResponseDataFormatWrong
|
||||||
@@ -311,13 +314,14 @@ func genNormalHavePageResultParser(dataKey string) (handler PageResultParser) {
|
|||||||
var retVal []interface{}
|
var retVal []interface{}
|
||||||
|
|
||||||
tempResult := data[dataKey]
|
tempResult := data[dataKey]
|
||||||
|
var result0 = make(map[string]interface{}, 0)
|
||||||
if resultStr, ok := tempResult.(string); ok {
|
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
|
return nil, 0, platformapi.ErrResponseDataFormatWrong
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = tempResult.(map[string]interface{})
|
result = result0
|
||||||
|
|
||||||
if totalCount == 0 {
|
if totalCount == 0 {
|
||||||
for _, totalCountKey := range havePageTotalCountKeys {
|
for _, totalCountKey := range havePageTotalCountKeys {
|
||||||
@@ -392,10 +396,11 @@ func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{},
|
|||||||
return nil, totalCount, err
|
return nil, totalCount, err
|
||||||
}
|
}
|
||||||
var data map[string]interface{}
|
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
|
return nil, totalCount, platformapi.ErrResponseDataFormatWrong
|
||||||
}
|
}
|
||||||
|
|
||||||
innerCode := forceInnerCode2Str(data["code"])
|
innerCode := forceInnerCode2Str(data["code"])
|
||||||
if innerCode != "0" {
|
if innerCode != "0" {
|
||||||
err2 := utils.NewErrorCode(getErrMsgFromData(data), innerCode, 1)
|
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) {
|
func JdMap2StructByJson(inObj interface{}, outObjAddr interface{}, weaklyTypedInput bool) (err error) {
|
||||||
return utils.Map2Struct(inObj, outObjAddr, true, "", JavaDateHook)
|
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
|
package jdapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"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) {
|
func TestAccessAPINoPage(t *testing.T) {
|
||||||
result, err := api.AccessAPINoPage("address/allcities", nil, []string{"yn"}, nil, nil)
|
result, err := api.AccessAPINoPage("address/allcities", nil, []string{"yn"}, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func TestPickUp(t *testing.T) {
|
|||||||
|
|
||||||
func TestOrderQuery(t *testing.T) {
|
func TestOrderQuery(t *testing.T) {
|
||||||
jdParams := map[string]interface{}{
|
jdParams := map[string]interface{}{
|
||||||
"orderId": "2225712287000273",
|
"orderId": "2225735125000294",
|
||||||
}
|
}
|
||||||
result, totalCount, err := api.OrderQuery(jdParams)
|
result, totalCount, err := api.OrderQuery(jdParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ func TestDelVipPrice(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// t.Log(utils.Format4Output(result, false))
|
t.Fatal(err)
|
||||||
|
//t.Log(utils.Format4Output(result, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
//func TestQueryOpenUseable(t *testing.T) {
|
//func TestQueryOpenUseable(t *testing.T) {
|
||||||
// result, err := api.QueryOpenUseable([]*BaseStockCenterRequest{
|
// result, err := api.QueryOpenUseable([]*BaseStockCenterRequest{
|
||||||
// &BaseStockCenterRequest{
|
// &BaseStockCenterRequest{
|
||||||
@@ -44,7 +44,7 @@ func TestDelVipPrice(t *testing.T) {
|
|||||||
// }
|
// }
|
||||||
// t.Log(utils.Format4Output(result, false))
|
// t.Log(utils.Format4Output(result, false))
|
||||||
//}
|
//}
|
||||||
//
|
|
||||||
//func TestQueryStockCenter(t *testing.T) {
|
//func TestQueryStockCenter(t *testing.T) {
|
||||||
// result, err := api.QueryStockCenter(mustExistStoreJXID, []*SkuIdEntity{
|
// result, err := api.QueryStockCenter(mustExistStoreJXID, []*SkuIdEntity{
|
||||||
// &SkuIdEntity{
|
// &SkuIdEntity{
|
||||||
|
|||||||
@@ -238,12 +238,15 @@ func (a *API) GetStoreFreight(storeId int64) ([]int64, error) {
|
|||||||
if result.Code != RequestSuccessCode {
|
if result.Code != RequestSuccessCode {
|
||||||
return nil, errors.New(result.SubMsg)
|
return nil, errors.New(result.SubMsg)
|
||||||
}
|
}
|
||||||
|
if len(result.Data.StoreFreights) == 0 {
|
||||||
tempList := make([]int64, 0)
|
return []int64{0}, err
|
||||||
for _, v := range result.Data.StoreFreights {
|
} else {
|
||||||
tempList = append(tempList, v.FreightId)
|
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)
|
a := New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token)
|
||||||
param := &warehouse_createFence_request.WarehouseCreateFenceParam{
|
param := &warehouse_createFence_request.WarehouseCreateFenceParam{
|
||||||
FenceInfo: &warehouse_createFence_request.FenceInfo{
|
FenceInfo: &warehouse_createFence_request.FenceInfo{
|
||||||
OutFenceId: "668410-2",
|
OutFenceId: "667094",
|
||||||
Shape: 1,
|
Shape: 1,
|
||||||
Circular: &warehouse_createFence_request.Circular{
|
Circular: &warehouse_createFence_request.Circular{
|
||||||
Center: &warehouse_createFence_request.Center{
|
Center: &warehouse_createFence_request.Center{
|
||||||
Longitude: 104.056976,
|
Longitude: 116.686026,
|
||||||
Latitude: 30.755311,
|
Latitude: 39.884685,
|
||||||
},
|
},
|
||||||
Radius: 100000,
|
Radius: 30000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -255,3 +255,10 @@ func TestUpdateStore(t *testing.T) {
|
|||||||
err := a.EditStore(param)
|
err := a.EditStore(param)
|
||||||
fmt.Println(err)
|
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
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/aes"
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -27,6 +29,35 @@ func NewErrorCode(errMsg, code string, level ...int) *ErrorWithCode {
|
|||||||
return retVal
|
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 {
|
func NewErrorIntCode(errMsg string, code int, level ...int) *ErrorWithCode {
|
||||||
return NewErrorCode(errMsg, Int2Str(code), level...)
|
return NewErrorCode(errMsg, Int2Str(code), level...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AESCBCEncpryt(data, aesKey, iv []byte) (encryptedData []byte, err error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
fmt.Println(c.BlockSize(), len(encryptedData))
|
||||||
cfbdec := cipher.NewCBCDecrypter(c, iv[:c.BlockSize()])
|
cfbdec := cipher.NewCBCDecrypter(c, iv[:c.BlockSize()])
|
||||||
decryptedData = make([]byte, len(encryptedData))
|
decryptedData = make([]byte, len(encryptedData))
|
||||||
cfbdec.CryptBlocks(decryptedData, encryptedData)
|
cfbdec.CryptBlocks(decryptedData, encryptedData)
|
||||||
|
|
||||||
decryptedData = PKCSUnPadding(decryptedData)
|
decryptedData = PKCSUnPadding(decryptedData)
|
||||||
return decryptedData, nil
|
return decryptedData, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user