✨ 初始化项目
This commit is contained in:
106
profile/api.go
Normal file
106
profile/api.go
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* @Author: Echo
|
||||
* @Author:1711788888@qq.com
|
||||
* @Date: 2021/5/27 20:44
|
||||
* @Desc: 资料管理
|
||||
*/
|
||||
|
||||
package profile
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/tencent-im/internal/core"
|
||||
"git.echol.cn/loser/tencent-im/internal/enum"
|
||||
"git.echol.cn/loser/tencent-im/internal/types"
|
||||
)
|
||||
|
||||
const (
|
||||
service = "profile"
|
||||
commandSetProfile = "portrait_set"
|
||||
commandGetProfiles = "portrait_get"
|
||||
)
|
||||
|
||||
type API interface {
|
||||
// SetProfile 设置资料
|
||||
// 支持 标配资料字段 和 自定义资料字段 的设置
|
||||
// 点击查看详细文档:
|
||||
// https://cloud.tencent.com/document/product/269/1640
|
||||
SetProfile(profile *Profile) (err error)
|
||||
|
||||
// GetProfiles 拉取资料
|
||||
// 支持拉取好友和非好友的资料字段。
|
||||
// 支持拉取 标配资料字段 和 自定义资料字段。
|
||||
// 建议每次拉取的用户数不超过100,避免因回包数据量太大导致回包失败。
|
||||
// 请确保请求中的所有帐号都已导入即时通信 IM,如果请求中含有未导入即时通信 IM 的帐号,即时通信 IM 后台将会提示错误。
|
||||
// 点击查看详细文档:
|
||||
// https://cloud.tencent.com/document/product/269/1639
|
||||
GetProfiles(userIds []string, attrs []string) (profiles []*Profile, err error)
|
||||
}
|
||||
|
||||
type api struct {
|
||||
client core.Client
|
||||
}
|
||||
|
||||
func NewAPI(client core.Client) API {
|
||||
return &api{client: client}
|
||||
}
|
||||
|
||||
// SetProfile 设置资料
|
||||
// 支持 标配资料字段 和 自定义资料字段 的设置
|
||||
// 点击查看详细文档:
|
||||
// https://cloud.tencent.com/document/product/269/1640
|
||||
func (a *api) SetProfile(profile *Profile) (err error) {
|
||||
if err = profile.CheckError(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
userId := profile.GetUserId()
|
||||
|
||||
attrs := profile.GetAttrs()
|
||||
|
||||
if len(attrs) == 0 {
|
||||
err = core.NewError(enum.InvalidParamsCode, "the attributes is not set")
|
||||
return
|
||||
}
|
||||
|
||||
req := &setProfileReq{UserId: userId, Attrs: make([]*types.TagPair, 0, len(attrs))}
|
||||
|
||||
for tag, value := range attrs {
|
||||
req.Attrs = append(req.Attrs, &types.TagPair{
|
||||
Tag: tag,
|
||||
Value: value,
|
||||
})
|
||||
}
|
||||
|
||||
if err = a.client.Post(service, commandSetProfile, req, &types.ActionBaseResp{}); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetProfiles 拉取资料
|
||||
// 支持拉取好友和非好友的资料字段。
|
||||
// 支持拉取 标配资料字段 和 自定义资料字段。
|
||||
// 建议每次拉取的用户数不超过100,避免因回包数据量太大导致回包失败。
|
||||
// 请确保请求中的所有帐号都已导入即时通信 IM,如果请求中含有未导入即时通信 IM 的帐号,即时通信 IM 后台将会提示错误。
|
||||
// 点击查看详细文档:
|
||||
// https://cloud.tencent.com/document/product/269/1639
|
||||
func (a *api) GetProfiles(userIds []string, attrs []string) (profiles []*Profile, err error) {
|
||||
req := &getProfileReq{UserIds: userIds, TagList: attrs}
|
||||
resp := &getProfileResp{}
|
||||
|
||||
if err = a.client.Post(service, commandGetProfiles, req, resp); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, account := range resp.UserProfiles {
|
||||
p := NewProfile(account.UserId)
|
||||
p.SetError(account.ResultCode, account.ResultInfo)
|
||||
for _, item := range account.Profile {
|
||||
p.SetAttr(item.Tag, item.Value)
|
||||
}
|
||||
profiles = append(profiles, p)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
54
profile/enum.go
Normal file
54
profile/enum.go
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* @Author: Echo
|
||||
* @Author:1711788888@qq.com
|
||||
* @Date: 2021/9/7 14:03
|
||||
* @Desc: TODO
|
||||
*/
|
||||
|
||||
package profile
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/tencent-im/internal/enum"
|
||||
"git.echol.cn/loser/tencent-im/internal/types"
|
||||
)
|
||||
|
||||
type (
|
||||
// GenderType 性别类型
|
||||
GenderType = types.GenderType
|
||||
|
||||
// AllowType 加好友验证方式
|
||||
AllowType = types.AllowType
|
||||
|
||||
// AdminForbidType 管理员禁止加好友标识类型
|
||||
AdminForbidType = types.AdminForbidType
|
||||
)
|
||||
|
||||
const (
|
||||
// 性别类型
|
||||
GenderTypeUnknown = enum.GenderTypeUnknown // 没设置性别
|
||||
GenderTypeFemale = enum.GenderTypeFemale // 女性
|
||||
GenderTypeMale = enum.GenderTypeMale // 男性
|
||||
|
||||
// 加好友验证方式
|
||||
AllowTypeNeedConfirm = enum.AllowTypeNeedConfirm // 需要经过自己确认对方才能添加自己为好友
|
||||
AllowTypeAllowAny = enum.AllowTypeAllowAny // 允许任何人添加自己为好友
|
||||
AllowTypeDenyAny = enum.AllowTypeDenyAny // 不允许任何人添加自己为好友
|
||||
|
||||
// 管理员禁止加好友标识类型
|
||||
AdminForbidTypeNone = enum.AdminForbidTypeNone // 默认值,允许加好友
|
||||
AdminForbidTypeSendOut = enum.AdminForbidTypeSendOut // 禁止该用户发起加好友请求
|
||||
|
||||
// 标准资料字段
|
||||
StandardAttrNickname = enum.StandardAttrNickname // 昵称
|
||||
StandardAttrGender = enum.StandardAttrGender // 性别
|
||||
StandardAttrBirthday = enum.StandardAttrBirthday // 生日
|
||||
StandardAttrLocation = enum.StandardAttrLocation // 所在地
|
||||
StandardAttrSignature = enum.StandardAttrSignature // 个性签名
|
||||
StandardAttrAllowType = enum.StandardAttrAllowType // 加好友验证方式
|
||||
StandardAttrLanguage = enum.StandardAttrLanguage // 语言
|
||||
StandardAttrAvatar = enum.StandardAttrAvatar // 头像URL
|
||||
StandardAttrMsgSettings = enum.StandardAttrMsgSettings // 消息设置
|
||||
StandardAttrAdminForbidType = enum.StandardAttrAdminForbidType // 管理员禁止加好友标识
|
||||
StandardAttrLevel = enum.StandardAttrLevel // 等级
|
||||
StandardAttrRole = enum.StandardAttrRole // 角色
|
||||
)
|
39
profile/profile.go
Normal file
39
profile/profile.go
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @Author: Echo
|
||||
* @Email:1711788888@qq.com
|
||||
* @Date: 2021/8/28 11:23 上午
|
||||
* @Desc: TODO
|
||||
*/
|
||||
|
||||
package profile
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/tencent-im/internal/core"
|
||||
"git.echol.cn/loser/tencent-im/internal/entity"
|
||||
"git.echol.cn/loser/tencent-im/internal/enum"
|
||||
)
|
||||
|
||||
type Profile struct {
|
||||
entity.User
|
||||
}
|
||||
|
||||
func NewProfile(userId ...string) *Profile {
|
||||
p := &Profile{}
|
||||
if len(userId) > 0 {
|
||||
p.SetUserId(userId[0])
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// CheckError 检测错误
|
||||
func (p *Profile) CheckError() (err error) {
|
||||
if userId := p.GetUserId(); userId == "" {
|
||||
return core.NewError(enum.InvalidParamsCode, "the userid is not set")
|
||||
}
|
||||
|
||||
if err = p.GetError(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
39
profile/types.go
Normal file
39
profile/types.go
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @Author: Echo
|
||||
* @Author:1711788888@qq.com
|
||||
* @Date: 2021/5/29 17:38
|
||||
* @Desc: 资料管理结构体定义
|
||||
*/
|
||||
|
||||
package profile
|
||||
|
||||
import "git.echol.cn/loser/tencent-im/internal/types"
|
||||
|
||||
type (
|
||||
// 设置资料(请求)
|
||||
setProfileReq struct {
|
||||
UserId string `json:"From_Account"` // (必填)需要设置该 UserID 的资料
|
||||
Attrs []*types.TagPair `json:"ProfileItem"` // (必填)待设置的用户的资料对象数组
|
||||
}
|
||||
|
||||
// 获取资料(请求)
|
||||
getProfileReq struct {
|
||||
UserIds []string `json:"To_Account"` // (必填)需要拉取这些UserID的资料
|
||||
TagList []string `json:"TagList"` // (必填)指定要拉取的资料字段的 Tag,支持的字段有
|
||||
}
|
||||
|
||||
// 获取资料(响应)
|
||||
getProfileResp struct {
|
||||
types.ActionBaseResp
|
||||
ErrorDisplay string `json:"ErrorDisplay"` // 详细的客户端展示信息
|
||||
UserProfiles []UserProfile `json:"UserProfileItem"` // 用户资料结构化信息
|
||||
}
|
||||
|
||||
// UserProfile 用户资料
|
||||
UserProfile struct {
|
||||
UserId string `json:"To_Account"` // 用户的UserID
|
||||
Profile []types.TagPair `json:"ProfileItem"` // 用户的资料对象数组
|
||||
ResultCode int `json:"ResultCode"` // 处理结果,0表示成功,非0表示失败
|
||||
ResultInfo string `json:"ResultInfo"` // 错误描述信息,成功时该字段为空
|
||||
}
|
||||
)
|
Reference in New Issue
Block a user