jd decode
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 {
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user