- fk. Request.Close = true for weixin api.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user