- fk. Request.Close = true for weixin api.
This commit is contained in:
@@ -143,27 +143,33 @@ func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal
|
||||
params["timestamp"] = utils.GetCurTimeStr()
|
||||
sign := a.signParams(params)
|
||||
params[signKey] = sign
|
||||
// request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(prodURL, apiStr, params), nil)
|
||||
//request.Close = true //todo 为了性能考虑
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client, http.MethodGet, utils.GenerateGetURL(prodURL, apiStr, params), "", nil, a.config, func(response *http.Response) (errLevel string, err error) {
|
||||
jsonResult1, err := utils.HTTPResponse2Json(response)
|
||||
if err != nil {
|
||||
return platformapi.ErrLevelGeneralFail, platformapi.ErrResponseDataFormatWrong
|
||||
}
|
||||
code := jsonResult1["code"].(string)
|
||||
if code == ResponseCodeSuccess {
|
||||
retVal = jsonResult1
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
}
|
||||
newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code)
|
||||
if _, ok := exceedLimitCodes[code]; ok {
|
||||
return platformapi.ErrLevelExceedLimit, newErr
|
||||
} else if _, ok := canRetryCodes[code]; ok {
|
||||
return platformapi.ErrLevelRecoverableErr, newErr
|
||||
} else {
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
}
|
||||
})
|
||||
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(prodURL, apiStr, params), nil)
|
||||
// request.Close = true //todo 为了性能考虑还是不要关闭
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response) (errLevel string, err error) {
|
||||
jsonResult1, err := utils.HTTPResponse2Json(response)
|
||||
if err != nil {
|
||||
return platformapi.ErrLevelGeneralFail, platformapi.ErrResponseDataFormatWrong
|
||||
}
|
||||
code := jsonResult1["code"].(string)
|
||||
if code == ResponseCodeSuccess {
|
||||
retVal = jsonResult1
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
}
|
||||
newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code)
|
||||
if _, ok := exceedLimitCodes[code]; ok {
|
||||
return platformapi.ErrLevelExceedLimit, newErr
|
||||
} else if _, ok := canRetryCodes[code]; ok {
|
||||
return platformapi.ErrLevelRecoverableErr, newErr
|
||||
} else {
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
}
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user