From 82353bbd35a4ef94be876c9f590778c3dcde5fee Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Thu, 13 Jul 2023 11:15:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eim=E8=AF=B7=E6=B1=82=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=BB=93=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/userDoctor.go | 8 ++-- api/service/userDoctor.go | 3 ++ extend/tencentIm/base.go | 77 +++++++++++++++++++++++++++++------- 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/api/controller/userDoctor.go b/api/controller/userDoctor.go index fa8cf1b..c03f1a7 100644 --- a/api/controller/userDoctor.go +++ b/api/controller/userDoctor.go @@ -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) } diff --git a/api/service/userDoctor.go b/api/service/userDoctor.go index 67b45b5..be1427a 100644 --- a/api/service/userDoctor.go +++ b/api/service/userDoctor.go @@ -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资料 } // 修改医生数据 diff --git a/extend/tencentIm/base.go b/extend/tencentIm/base.go index e2a6f33..07d2479 100644 --- a/extend/tencentIm/base.go +++ b/extend/tencentIm/base.go @@ -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 }