|
@@ -31,8 +31,30 @@ import (
|
|
|
func APIPost[T_REQ APIReqData, T_RSP APIRspData](req APIReq[T_REQ], apiPort APIURL) (rsp *APIRsp[T_RSP], err error) {
|
|
func APIPost[T_REQ APIReqData, T_RSP APIRspData](req APIReq[T_REQ], apiPort APIURL) (rsp *APIRsp[T_RSP], err error) {
|
|
|
apiUrl := config.SerCfg.AsignCfg.Url + string(apiPort)
|
|
apiUrl := config.SerCfg.AsignCfg.Url + string(apiPort)
|
|
|
|
|
|
|
|
|
|
+ // 排序key
|
|
|
|
|
+ // var b []byte
|
|
|
|
|
+ var sortedData string
|
|
|
|
|
+ if len(req.Datas) == 0 {
|
|
|
|
|
+ sortedData = SortMapByKey(structs.Map(req.Data))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sortedData := "["
|
|
|
|
|
+ for i, item := range req.Datas {
|
|
|
|
|
+ if i > 0 {
|
|
|
|
|
+ sortedData += ","
|
|
|
|
|
+ }
|
|
|
|
|
+ sortedData += SortMapByKey(structs.Map(item))
|
|
|
|
|
+ }
|
|
|
|
|
+ sortedData += "]"
|
|
|
|
|
+ }
|
|
|
|
|
+ logger.GetLogger().Debugf("sortedData: %s", sortedData)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ logger.GetLogger().Errorf("处理入参排序失败:" + err.Error())
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 调用接口
|
|
|
var rspBody []byte
|
|
var rspBody []byte
|
|
|
- rspBody, err = httpPost(apiUrl, req.Data)
|
|
|
|
|
|
|
+ rspBody, err = httpPost(apiUrl, sortedData)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -48,39 +70,13 @@ func APIPost[T_REQ APIReqData, T_RSP APIRspData](req APIReq[T_REQ], apiPort APIU
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func httpPost(apiUrl string, bizData ...interface{}) (rspBody []byte, err error) {
|
|
|
|
|
- logger.GetLogger().Debugf("bizData: %v", bizData)
|
|
|
|
|
- logger.GetLogger().Debugf("len(bizData): %d", len(bizData))
|
|
|
|
|
-
|
|
|
|
|
|
|
+func httpPost(apiUrl string, sortedData string) (rspBody []byte, err error) {
|
|
|
appId := config.SerCfg.AsignCfg.AppId
|
|
appId := config.SerCfg.AsignCfg.AppId
|
|
|
privateKey := fmt.Sprintf("-----BEGIN PRIVATE KEY-----\n%s\n-----END PRIVATE KEY-----", config.SerCfg.AsignCfg.PrivateKey)
|
|
privateKey := fmt.Sprintf("-----BEGIN PRIVATE KEY-----\n%s\n-----END PRIVATE KEY-----", config.SerCfg.AsignCfg.PrivateKey)
|
|
|
|
|
|
|
|
// fuck asign dev.
|
|
// fuck asign dev.
|
|
|
timestamp := strconv.Itoa(int(time.Now().UnixMilli() + 10000*60))
|
|
timestamp := strconv.Itoa(int(time.Now().UnixMilli() + 10000*60))
|
|
|
|
|
|
|
|
- // 排序key
|
|
|
|
|
- // var b []byte
|
|
|
|
|
- var sortedData string
|
|
|
|
|
- if len(bizData) == 1 {
|
|
|
|
|
- // b, err = encoder.Encode(bizData[0], encoder.SortMapKeys)
|
|
|
|
|
- sortedData = SortMapByKey(structs.Map(bizData[0]))
|
|
|
|
|
- } else {
|
|
|
|
|
- // b, err = encoder.Encode(bizData, encoder.SortMapKeys)
|
|
|
|
|
- sortedData := "["
|
|
|
|
|
- for i, item := range bizData {
|
|
|
|
|
- if i > 0 {
|
|
|
|
|
- sortedData += ","
|
|
|
|
|
- }
|
|
|
|
|
- sortedData += SortMapByKey(structs.Map(item))
|
|
|
|
|
- }
|
|
|
|
|
- sortedData += "]"
|
|
|
|
|
- }
|
|
|
|
|
- logger.GetLogger().Debugf("sortedData: %s", sortedData)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- logger.GetLogger().Errorf("处理入参排序失败:" + err.Error())
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- // sortedData := string(b)
|
|
|
|
|
// 签名
|
|
// 签名
|
|
|
signature, err := getSignature(sortedData, appId, timestamp, privateKey)
|
|
signature, err := getSignature(sortedData, appId, timestamp, privateKey)
|
|
|
if err != nil {
|
|
if err != nil {
|