first commit
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"xiawan/wx/clientsdk/baseinfo"
|
||||
pb "xiawan/wx/protobuf/wechat"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
type SubMessageCheckLoginQrCode struct {
|
||||
Type int
|
||||
TargetIp string
|
||||
UUID string
|
||||
CheckLoginResult *baseinfo.CheckLoginQrCodeResult
|
||||
}
|
||||
|
||||
type SyncMessageResponse struct {
|
||||
Type int
|
||||
TargetIp string
|
||||
UUID string
|
||||
UserName string `json:"userName"`
|
||||
LoginState uint32 `json:"loginState"`
|
||||
ModUserInfos []*pb.ModUserInfo
|
||||
ModContacts []*pb.ModContact
|
||||
AddMsgs []*pb.AddMsg
|
||||
ModUserImgs []*pb.ModUserImg
|
||||
UserInfoExts []*pb.UserInfoExt
|
||||
SnsObjects []*pb.SnsObject
|
||||
SnsActionGroups []*pb.SnsActionGroup
|
||||
FavItem *baseinfo.FavItem
|
||||
Key *pb.SKBuiltinString_
|
||||
}
|
||||
|
||||
func (sync *SyncMessageResponse) GetContacts() []*pb.ModContact {
|
||||
return sync.ModContacts
|
||||
}
|
||||
|
||||
// 根据 UserName 查询 Contacts
|
||||
func (sync *SyncMessageResponse) GetModContacts(UserName string) *pb.ModContact {
|
||||
for _, userInfo := range sync.ModContacts {
|
||||
if userInfo.UserName.GetStr() == UserName {
|
||||
return userInfo
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 根据 UserName 更新或新增 Contacts
|
||||
func (sync *SyncMessageResponse) SetModContacts(userInfo *pb.ModContact) {
|
||||
for i, u := range sync.ModContacts {
|
||||
if u.UserName.GetStr() == userInfo.UserName.GetStr() {
|
||||
sync.ModContacts[i] = userInfo
|
||||
return
|
||||
}
|
||||
}
|
||||
sync.ModContacts = append(sync.ModContacts, userInfo)
|
||||
}
|
||||
|
||||
func (sync *SyncMessageResponse) GetAddMsgs() []*pb.AddMsg {
|
||||
return sync.AddMsgs
|
||||
}
|
||||
|
||||
func (sync *SyncMessageResponse) SetMessage(data []byte, cmdId int32) {
|
||||
switch cmdId {
|
||||
case 1:
|
||||
userInfo := new(pb.ModUserInfo)
|
||||
if err := proto.Unmarshal(data, userInfo); err != nil {
|
||||
//z.Errorf(err.Error())
|
||||
return
|
||||
}
|
||||
/*fmt.Printf("登录微信:[%s] 昵称 [%s] 手机 [%s] 别名 [%s]\n",
|
||||
userInfo.UserName.GetStr(),
|
||||
userInfo.NickName.GetStr(),
|
||||
userInfo.BindMobile.GetStr(),
|
||||
userInfo.GetAlias())*/
|
||||
sync.ModUserInfos = append(sync.ModUserInfos, userInfo)
|
||||
// 限制长度
|
||||
if len(sync.ModUserInfos) > 5000 {
|
||||
sync.ModUserInfos = sync.ModUserInfos[len(sync.ModUserInfos)-5000:]
|
||||
}
|
||||
case 2:
|
||||
contact := new(pb.ModContact)
|
||||
if err := proto.Unmarshal(data, contact); err != nil {
|
||||
//z.Errorf(err.Error())
|
||||
return
|
||||
}
|
||||
sync.ModContacts = append(sync.ModContacts, contact)
|
||||
case 5:
|
||||
addMsg := new(pb.AddMsg)
|
||||
if err := proto.Unmarshal(data, addMsg); err != nil {
|
||||
//z.Println(err)
|
||||
return
|
||||
}
|
||||
sync.AddMsgs = append(sync.AddMsgs, addMsg)
|
||||
// 限制长度
|
||||
if len(sync.AddMsgs) > 5000 {
|
||||
sync.AddMsgs = sync.AddMsgs[len(sync.AddMsgs)-5000:]
|
||||
}
|
||||
case 35:
|
||||
userImg := new(pb.ModUserImg)
|
||||
if err := proto.Unmarshal(data, userImg); err != nil {
|
||||
//z.Println(err)
|
||||
return
|
||||
}
|
||||
sync.ModUserImgs = append(sync.ModUserImgs, userImg)
|
||||
// 限制长度
|
||||
if len(sync.ModUserImgs) > 5000 {
|
||||
sync.ModUserImgs = sync.ModUserImgs[len(sync.ModUserImgs)-5000:]
|
||||
}
|
||||
case 44:
|
||||
userInfoExt := new(pb.UserInfoExt)
|
||||
if err := proto.Unmarshal(data, userInfoExt); err != nil {
|
||||
//z.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
sync.UserInfoExts = append(sync.UserInfoExts, userInfoExt)
|
||||
// 限制长度
|
||||
if len(sync.UserInfoExts) > 5000 {
|
||||
sync.UserInfoExts = sync.UserInfoExts[len(sync.UserInfoExts)-5000:]
|
||||
}
|
||||
case 45:
|
||||
snsObject := new(pb.SnsObject)
|
||||
if err := proto.Unmarshal(data, snsObject); err != nil {
|
||||
//z.Println(err)
|
||||
return
|
||||
}
|
||||
sync.SnsObjects = append(sync.SnsObjects, snsObject)
|
||||
// 限制长度
|
||||
if len(sync.SnsObjects) > 5000 {
|
||||
sync.SnsObjects = sync.SnsObjects[len(sync.SnsObjects)-5000:]
|
||||
}
|
||||
case 46:
|
||||
snsActionGroup := new(pb.SnsActionGroup)
|
||||
if err := proto.Unmarshal(data, snsActionGroup); err != nil {
|
||||
//z.Println(err)
|
||||
return
|
||||
}
|
||||
sync.SnsActionGroups = append(sync.SnsActionGroups, snsActionGroup)
|
||||
// 限制长度
|
||||
if len(sync.SnsActionGroups) > 5000 {
|
||||
sync.SnsActionGroups = sync.SnsActionGroups[len(sync.SnsActionGroups)-5000:]
|
||||
}
|
||||
default:
|
||||
/*empty := new(pb.EmptyMesssage)
|
||||
_ = proto.Unmarshal(data, empty)*/
|
||||
//logger.Printf("收到未处理类型:%d 的数据:%s\n", id, empty.String())
|
||||
//保存消息
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user