package wxrouter import ( "time" "xiawan/wx/clientsdk" "xiawan/wx/db" "xiawan/wx/protobuf/wechat" "xiawan/wx/srv/wxcore" "xiawan/wx/srv/wxface" ) // WXGetProfileRouter 获取帐号信息路由 type WXGetProfileRouter struct { wxcore.WXBaseRouter } // Handle 处理conn业务的方法 func (hbr *WXGetProfileRouter) Handle(wxResp wxface.IWXResponse) error { defer wxcore.TryE("WXGetProfileRouter Handle") currentWXConn := wxResp.GetWXConncet() currentWXAccount := currentWXConn.GetWXAccount() currentUserInfo := currentWXAccount.GetUserInfo() // 解析账号Profile响应 userProfileResp := new(wechat.GetProfileResponse) err := clientsdk.ParseResponseData(currentUserInfo, wxResp.GetPackHeader(), userProfileResp) if err != nil { // 请求出问题了,判断是否掉线,并重连 time.Sleep(1 * time.Second) go currentWXConn.CheckOnLineStatusLogin() return err } // 设置昵称和头像 currentUserInfo.NickName = userProfileResp.GetUserInfo().GetNickName().GetStr() currentUserInfo.HeadURL = userProfileResp.GetUserInfoExt().GetSmallHeadImgUrl() // 设置UserProfile信息 currentWXAccount.SetUserProfile(userProfileResp) // 更新用户信息 db.UpdateUserInfoByPhone(userProfileResp.GetUserInfo()) return nil }