package wxrouter import ( "strings" "time" "xiawan/wx/clientsdk" "xiawan/wx/db" "xiawan/wx/protobuf/wechat" "xiawan/wx/srv/wxcore" "xiawan/wx/srv/wxface" ) // WXBatchGetContactBriefInfoReqRouter 批量获取联系人信息 type WXBatchGetContactBriefInfoReqRouter struct { wxcore.WXBaseRouter } // Handle 处理conn业务的方法 func (wxbgcbirr *WXBatchGetContactBriefInfoReqRouter) Handle(wxResp wxface.IWXResponse) error { currentWXConn := wxResp.GetWXConncet() currentWXAccount := currentWXConn.GetWXAccount() currentWXCache := currentWXConn.GetWXCache() currentUserInfo := currentWXAccount.GetUserInfo() currentReqInvoker := currentWXConn.GetWXReqInvoker() uuid := currentWXAccount.GetUserInfo().UUID // 解析批量获取联系人信息响应包 var briefInfoResp wechat.BatchGetContactBriefInfoResp err := clientsdk.ParseResponseData(currentUserInfo, wxResp.GetPackHeader(), &briefInfoResp) if err != nil { // 请求出问题了,判断是否掉线,并重连 time.Sleep(1 * time.Second) go currentWXConn.CheckOnLineStatusLogin() return err } // fmt.Println("批量获取联系人信息响应包:") tmpContactList := briefInfoResp.GetContactList() tmpCount := len(tmpContactList) for index := 0; index < tmpCount; index++ { tmpContactBriefInfo := tmpContactList[index] userName := tmpContactBriefInfo.GetUsername() tmpModContact := tmpContactBriefInfo.GetContact() nickName := tmpModContact.GetNickName().GetStr() // 公众号 hasExternalInfo := false if len(tmpModContact.GetCustomizedInfo().GetExternalInfo()) > 0 { hasExternalInfo = true } if strings.HasPrefix(userName, "gh_") || hasExternalInfo { if len(nickName) <= 0 { continue } // currentWXAccount.AddWXGhContact(tmpModContact) continue } // 群 if strings.HasSuffix(userName, "@chatroom") { // currentWXAccount.AddWXGroup(tmpModContact) db.SaveOrUpdateContact(tmpModContact, uuid) continue } // 好友 // currentWXAccount.AddWXFriendContact(tmpModContact) if !isSystemWXID(userName) { db.SaveOrUpdateContact(tmpModContact, uuid) } } // 获取剩余20个微信ID列表 nextWxidList := currentWXCache.GetNextInitContactWxidList(20) if len(nextWxidList) > 0 { currentReqInvoker.SendBatchGetContactBriefInfoReq(nextWxidList) } else { // 初始化完成 db.UpdateInitContactStatus(uuid, 1) // if !currentWXCache.IsInitContactFinished() { // currentWXCache.SetInitContactFinished(true) // } } return nil } func isSystemWXID(userName string) bool { if userName == "qqmail" || userName == "qmessage" || userName == "mphelper" || userName == "filehelper" || userName == "weixin" || userName == "floatbottle" || userName == "fmessage" || userName == "medianote" { return true } return false }