新增im请求返回结构体
This commit is contained in:
parent
a5522bcb63
commit
82353bbd35
@ -184,13 +184,13 @@ func (r *UserDoctor) GetUserDoctorPendingPage(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
getUserDoctorPageResponses := userDoctorResponse.GetUserDoctorPendingPageResponse(userDoctor)
|
||||
res := userDoctorResponse.GetUserDoctorPendingPageResponse(userDoctor)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = userDoctorRequest.GetUserDoctorPage.Page
|
||||
result["page_size"] = userDoctorRequest.GetUserDoctorPage.PageSize
|
||||
result["page"] = userDoctorRequest.GetUserDoctorPendingPage.Page
|
||||
result["page_size"] = userDoctorRequest.GetUserDoctorPendingPage.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = getUserDoctorPageResponses
|
||||
result["data"] = res
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
|
||||
@ -783,6 +783,8 @@ func (r *UserDoctorService) AddUserDoctor(userId string, a requests.AddUserDocto
|
||||
}
|
||||
}
|
||||
|
||||
// 创建im账户
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
@ -1129,6 +1131,7 @@ func (r *UserDoctorService) PutUserDoctorPending(doctorId int64, req requests.Pu
|
||||
return false, errors.New("审核失败")
|
||||
}
|
||||
|
||||
// 更新医生im资料
|
||||
}
|
||||
|
||||
// 修改医生数据
|
||||
|
||||
@ -13,6 +13,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// 请求返回值
|
||||
type responseData struct {
|
||||
ActionStatus string `json:"actionStatus"` // 请求处理的结果,“OK” 表示处理成功,“FAIL” 表示失败
|
||||
ErrorCode int `json:"errorCode"` // 错误码,0表示成功,非0表示失败
|
||||
ErrorInfo string `json:"errorInfo"` // 详细错误信息
|
||||
}
|
||||
|
||||
// GetUserSign 获取签名
|
||||
func GetUserSign(userId string) (string, error) {
|
||||
if userId == "" {
|
||||
@ -51,9 +58,55 @@ func getRequestUrlParams(userId string) (bool, string) {
|
||||
return true, queryString
|
||||
}
|
||||
|
||||
//
|
||||
// // 统一请求
|
||||
// func postRequest(url string, requestBody []byte) (map[string]interface{}, error) {
|
||||
// responseMap := make(map[string]interface{})
|
||||
//
|
||||
// // 发起 POST 请求
|
||||
// resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody))
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// defer func(Body io.ReadCloser) {
|
||||
// _ = Body.Close()
|
||||
// }(resp.Body)
|
||||
//
|
||||
// body, err := io.ReadAll(resp.Body)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// err = json.Unmarshal([]byte(string(body)), &responseMap)
|
||||
// if err != nil {
|
||||
// // json解析失败
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// if responseMap == nil {
|
||||
// return nil, errors.New("请求im失败")
|
||||
// }
|
||||
//
|
||||
// if _, ok := responseMap["ErrorCode"]; ok {
|
||||
// errorCode := responseMap["ErrorCode"].(int)
|
||||
// if errorCode != 0 {
|
||||
// if errorInfo, ok := responseMap["ErrorInfo"].(string); ok {
|
||||
// return nil, errors.New(errorInfo)
|
||||
// } else {
|
||||
// return nil, errors.New("请求im失败")
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// return nil, errors.New("请求im失败")
|
||||
// }
|
||||
//
|
||||
// return responseMap, nil
|
||||
// }
|
||||
|
||||
// 统一请求
|
||||
func postRequest(url string, requestBody []byte) (map[string]interface{}, error) {
|
||||
responseMap := make(map[string]interface{})
|
||||
func postRequest(url string, requestBody []byte) (*responseData, error) {
|
||||
var responseData responseData
|
||||
|
||||
// 发起 POST 请求
|
||||
resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody))
|
||||
@ -70,25 +123,19 @@ func postRequest(url string, requestBody []byte) (map[string]interface{}, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(string(body)), &responseMap)
|
||||
err = json.Unmarshal(body, &responseData)
|
||||
if err != nil {
|
||||
// json解析失败
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if responseMap == nil {
|
||||
return nil, errors.New("请求im失败")
|
||||
}
|
||||
|
||||
if errorCode, ok := responseMap["ErrorCode"].(int); ok {
|
||||
if errorCode != 0 {
|
||||
if errorInfo, ok := responseMap["ErrorInfo"].(string); ok {
|
||||
return nil, errors.New(errorInfo)
|
||||
} else {
|
||||
return nil, errors.New("请求im失败")
|
||||
}
|
||||
if responseData.ErrorCode != 0 {
|
||||
if responseData.ErrorInfo != "" {
|
||||
return nil, errors.New(responseData.ErrorInfo)
|
||||
} else {
|
||||
return nil, errors.New("请求im失败")
|
||||
}
|
||||
}
|
||||
|
||||
return responseMap, nil
|
||||
return &responseData, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user