first commit
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package wxrouter
|
||||
|
||||
import (
|
||||
"time"
|
||||
"xiawan/wx/clientsdk"
|
||||
"xiawan/wx/clientsdk/baseinfo"
|
||||
"xiawan/wx/protobuf/wechat"
|
||||
"xiawan/wx/srv/wxcore"
|
||||
"xiawan/wx/srv/wxface"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
// WXFavSyncRouter 同步收藏响应路由
|
||||
type WXFavSyncRouter struct {
|
||||
wxcore.WXBaseRouter
|
||||
}
|
||||
|
||||
// Handle 处理conn业务的方法
|
||||
func (hbr *WXFavSyncRouter) Handle(wxResp wxface.IWXResponse) error {
|
||||
currentWXConn := wxResp.GetWXConncet()
|
||||
currentWXAccount := currentWXConn.GetWXAccount()
|
||||
currentUserInfo := currentWXAccount.GetUserInfo()
|
||||
currentReqInvoker := currentWXConn.GetWXReqInvoker()
|
||||
currentWXCache := currentWXConn.GetWXCache()
|
||||
currentTaskMgr := currentWXConn.GetWXTaskMgr()
|
||||
// currentSyncMgr := currentWXConn.GetWXSyncMgr()
|
||||
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
||||
currentSnsTransTask := taskMgr.GetSnsTransTask()
|
||||
|
||||
// 解析同步收藏响应包
|
||||
var favSyncResp wechat.FavSyncResponse
|
||||
err := clientsdk.ParseResponseData(currentUserInfo, wxResp.GetPackHeader(), &favSyncResp)
|
||||
if err != nil {
|
||||
// 请求出问题了,判断是否掉线,并重连
|
||||
time.Sleep(1 * time.Second)
|
||||
go currentWXConn.CheckOnLineStatusLogin()
|
||||
return err
|
||||
}
|
||||
|
||||
// 保存同步key下次使用
|
||||
// 解析同步收藏列表
|
||||
cmdList := favSyncResp.GetCmdList()
|
||||
tmpCount := cmdList.GetCount()
|
||||
tmpKeyBuf := favSyncResp.KeyBuf.GetBuffer()
|
||||
if len(tmpKeyBuf) <= 0 {
|
||||
currentReqInvoker.SendGetFavInfoRequest()
|
||||
return nil
|
||||
}
|
||||
|
||||
currentUserInfo.FavSyncKey = tmpKeyBuf
|
||||
|
||||
if tmpCount < 1024 {
|
||||
if !currentWXCache.IsInitFavSyncFinished() {
|
||||
// 同步完成
|
||||
currentWXCache.SetInitFavSyncFinished(true)
|
||||
}
|
||||
}
|
||||
currentReqInvoker.SendGetFavInfoRequest()
|
||||
// 如果还没开启转发收藏
|
||||
if !currentSnsTransTask.IsAutoRelay() {
|
||||
return nil
|
||||
}
|
||||
|
||||
itemList := cmdList.GetItemList()
|
||||
// 获取收藏缓存
|
||||
favInfoCache := currentWXCache.GetFavInfoCache()
|
||||
for index := uint32(0); index < tmpCount; index++ {
|
||||
tmpItem := itemList[index]
|
||||
// 判断是否是新增的收藏
|
||||
tmpCmdID := tmpItem.GetCmdId()
|
||||
if tmpCmdID != baseinfo.MMFavSyncCmdAddItem {
|
||||
return nil
|
||||
}
|
||||
// 处理新增的收藏
|
||||
addItem := &wechat.AddFavItem{}
|
||||
err := proto.Unmarshal(tmpItem.GetCmdBuf().GetData(), addItem)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 判断是否重复
|
||||
if favInfoCache.LastFavID() == addItem.GetFavId() && favInfoCache.LastFavUpdateTime() == addItem.GetUpdateTime() {
|
||||
continue
|
||||
}
|
||||
favInfoCache.SetLastFavID(addItem.GetFavId())
|
||||
favInfoCache.SetLastFavUpdateTime(addItem.GetUpdateTime())
|
||||
// 获取收藏详情
|
||||
return currentReqInvoker.SendBatchGetFavItemRequest(favInfoCache.LastFavID())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user