This commit is contained in:
邹宗楠
2023-04-03 09:22:55 +08:00
parent 4337ab3585
commit 18572ce050
8 changed files with 60 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
"net/http"
"sort"
"strings"
@@ -77,7 +78,26 @@ func (a *API) GetToken() error {
return nil
}
// AccessAPI2 发送请求
// AccessAPI1 发送请求(支付)
func (a *API) AccessAPI1(url string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodPost, url, strings.NewReader(utils.Map2URLValues(params).Encode()))
request.Header.Set("Content-Type", "application/json")
return request
},
a.config,
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
if jsonResult1 == nil {
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
}
retVal = jsonResult1
return platformapi.ErrLevelSuccess, nil
})
return retVal, err
}
// AccessAPI2 发送请求(登录)
func (a *API) AccessAPI2(url string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
@@ -116,9 +136,12 @@ func (a *API) sign(param map[string]interface{}) string {
}
sort.Strings(paramsArr)
signParma := make([]string, 0, 0)
globals.SugarLogger.Debugf("param := %s", utils.Format4Output(param, false))
globals.SugarLogger.Debugf("paramsArr := %s", utils.Format4Output(paramsArr, false))
signParma := make([]string, len(paramsArr))
for k, v := range paramsArr {
if utils.IsNil(param[v]) {
if !utils.IsNil(param[v]) {
signParma[k] = v + "=" + fmt.Sprintf("%v", param[v])
}
}