- fk. Request.Close = true for weixin api.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package dadaapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -107,32 +108,36 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R
|
||||
}
|
||||
params2[signKey] = a.signParams(params2)
|
||||
params2Bytes := utils.MustMarshal(params2)
|
||||
// request, _ := http.NewRequest(http.MethodPost, a.url+"/"+action, bytes.NewReader(params2Bytes))
|
||||
header := make(http.Header)
|
||||
header.Set("Content-Type", "application/json")
|
||||
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client, http.MethodPost, a.url+"/"+action, string(params2Bytes), header, a.config, func(response *http.Response) (result string, err error) {
|
||||
jsonResult1, err := utils.HTTPResponse2Json(response)
|
||||
if err != nil {
|
||||
return platformapi.ErrLevelGeneralFail, err
|
||||
}
|
||||
code := int(utils.MustInterface2Int64(jsonResult1["code"]))
|
||||
retVal = &ResponseResult{
|
||||
Code: code,
|
||||
ErrorCode: code,
|
||||
Msg: jsonResult1["msg"].(string),
|
||||
Status: jsonResult1["status"].(string),
|
||||
}
|
||||
if code == ResponseCodeSuccess {
|
||||
retVal.Result = jsonResult1["result"]
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
}
|
||||
newErr := utils.NewErrorIntCode(retVal.Msg, code)
|
||||
if code == ResponseCodeRetryLater || code == ResponseCodeNetworkErr {
|
||||
return platformapi.ErrLevelRecoverableErr, newErr
|
||||
}
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
})
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
request, _ := http.NewRequest(http.MethodPost, a.url+"/"+action, bytes.NewReader(params2Bytes))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response) (result string, err error) {
|
||||
jsonResult1, err := utils.HTTPResponse2Json(response)
|
||||
if err != nil {
|
||||
return platformapi.ErrLevelGeneralFail, err
|
||||
}
|
||||
code := int(utils.MustInterface2Int64(jsonResult1["code"]))
|
||||
retVal = &ResponseResult{
|
||||
Code: code,
|
||||
ErrorCode: code,
|
||||
Msg: jsonResult1["msg"].(string),
|
||||
Status: jsonResult1["status"].(string),
|
||||
}
|
||||
if code == ResponseCodeSuccess {
|
||||
retVal.Result = jsonResult1["result"]
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
}
|
||||
newErr := utils.NewErrorIntCode(retVal.Msg, code)
|
||||
if code == ResponseCodeRetryLater || code == ResponseCodeNetworkErr {
|
||||
return platformapi.ErrLevelRecoverableErr, newErr
|
||||
}
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user