- fk. Request.Close = true for weixin api.

This commit is contained in:
gazebo
2018-08-16 11:03:06 +08:00
parent 47e1b3989d
commit fa6ac348e3
8 changed files with 210 additions and 196 deletions

View File

@@ -193,29 +193,33 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R
params2["version"] = []string{"1.0"}
params2[signKey] = []string{a.signParams(params2)}
// baseapi.SugarLogger.Debug(params2.Encode())
// request, _ := http.NewRequest(http.MethodPost, mtpsAPIURL+"/"+action, strings.NewReader(params2.Encode()))
header := make(http.Header)
header.Set("Content-Type", "application/x-www-form-urlencoded")
err = platformapi.AccessPlatformAPIWithRetry(a.client, http.MethodPost, mtpsAPIURL+"/"+action, params2.Encode(), header, a.config, func(response *http.Response) (result string, err error) {
jsonResult1, err := utils.HTTPResponse2Json(response)
if err != nil {
return platformapi.ErrLevelGeneralFail, platformapi.ErrResponseDataFormatWrong
}
code := int(utils.MustInterface2Int64(jsonResult1["code"]))
retVal = &ResponseResult{
Code: code,
}
if code == ResponseCodeSuccess {
if innerData, ok := jsonResult1["data"]; ok {
retVal.Data, _ = innerData.(map[string]interface{})
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
request, _ := http.NewRequest(http.MethodPost, mtpsAPIURL+"/"+action, strings.NewReader(params2.Encode()))
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
return request
},
a.config,
func(response *http.Response) (result string, err error) {
jsonResult1, err := utils.HTTPResponse2Json(response)
if err != nil {
return platformapi.ErrLevelGeneralFail, platformapi.ErrResponseDataFormatWrong
}
return platformapi.ErrLevelSuccess, nil
}
retVal.Message = jsonResult1["message"].(string)
newErr := utils.NewErrorIntCode(retVal.Message, code)
return platformapi.ErrLevelCodeIsNotOK, newErr
})
code := int(utils.MustInterface2Int64(jsonResult1["code"]))
retVal = &ResponseResult{
Code: code,
}
if code == ResponseCodeSuccess {
if innerData, ok := jsonResult1["data"]; ok {
retVal.Data, _ = innerData.(map[string]interface{})
}
return platformapi.ErrLevelSuccess, nil
}
retVal.Message = jsonResult1["message"].(string)
newErr := utils.NewErrorIntCode(retVal.Message, code)
return platformapi.ErrLevelCodeIsNotOK, newErr
})
return retVal, err
}