This commit is contained in:
邹宗楠
2024-12-13 17:04:36 +08:00
parent 5fa49d0b98
commit ba9ded985a
2 changed files with 38 additions and 18 deletions

View File

@@ -68,7 +68,7 @@ func (a *API) sign(uid, timestamp string, param string) (sign string) {
return fmt.Sprintf("%x", md5.Sum([]byte(aa)))
}
func (a *API) HttpPostJson(url string, data interface{}) *TIResponse {
func (a *API) HttpPostJson(url string, data interface{}) (*TIResponse, error) {
//序列化参数
b, err := json.Marshal(&data)
if err != nil {
@@ -77,7 +77,7 @@ func (a *API) HttpPostJson(url string, data interface{}) *TIResponse {
result := TIResponse{
HttpStatusCode: 500,
}
return &result
return &result, nil
}
fullUrl := utils.GenerateGetURL(BaseUrl, url, nil)
@@ -97,14 +97,12 @@ func (a *API) HttpPostJson(url string, data interface{}) *TIResponse {
resp, err := client.Do(request)
//resp, err := http.Post(utils.GenerateGetURL(BaseUrl, url, nil), "application/json;charset=UTF-8", bytes.NewBuffer(b))
if err != nil {
return nil
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
glo
var msg = fmt.Sprintf("post json error:%+v", err)
fmt.Println(msg)
return nil, err
}
result := TIResponse{
@@ -116,11 +114,10 @@ func (a *API) HttpPostJson(url string, data interface{}) *TIResponse {
if err == nil {
result.BaseRes = &content
} else {
var msg = fmt.Sprintf("unmarshal body failed, error:%+v", err)
fmt.Println(msg)
return nil, err
}
return &result
return &result, nil
}
func StrRepeat(str string, repeatTimes int) string {