54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
// Package tencentIm im资料
|
|
package tencentIm
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"hospital-open-api/config"
|
|
)
|
|
|
|
// ProfileItem 资料对象数组
|
|
type ProfileItem struct {
|
|
Tag string `json:"Tag"`
|
|
Value string `json:"Value"`
|
|
}
|
|
|
|
// PortraitSetRequest 请求格式
|
|
type PortraitSetRequest struct {
|
|
FromAccount string `json:"From_Account"`
|
|
ProfileItems []ProfileItem `json:"ProfileItem"`
|
|
}
|
|
|
|
// SetProfile 设置账户资料
|
|
func SetProfile(userId string, profileItem []ProfileItem) (bool, error) {
|
|
if len(profileItem) == 0 {
|
|
return false, errors.New("未设置资料")
|
|
}
|
|
|
|
// 构建请求数据
|
|
requestData := &PortraitSetRequest{
|
|
FromAccount: userId,
|
|
ProfileItems: profileItem,
|
|
}
|
|
|
|
// 将请求数据转换为 JSON
|
|
requestBody, err := json.Marshal(requestData)
|
|
if err != nil {
|
|
return false, errors.New("设置im资料失败")
|
|
}
|
|
|
|
// 构建请求 URL
|
|
res, result := getRequestUrlParams("administrator")
|
|
if res != true {
|
|
return false, errors.New(result)
|
|
}
|
|
url := config.C.Im.ImBaseUrl + "v4/profile/portrait_set?" + result
|
|
|
|
_, err = postRequest(url, requestBody)
|
|
if err != nil {
|
|
return false, errors.New(err.Error())
|
|
}
|
|
|
|
return true, nil
|
|
}
|