168 lines
6.1 KiB
Go
168 lines
6.1 KiB
Go
package service
|
||
|
||
import (
|
||
"strconv"
|
||
"xiawan/wx/api/req"
|
||
"xiawan/wx/api/vo"
|
||
"xiawan/wx/clientsdk/baseinfo"
|
||
"xiawan/wx/srv/wxface"
|
||
|
||
"github.com/lunny/log"
|
||
)
|
||
|
||
// GetContactLabelListRequestService 获取标签列表
|
||
func GetContactLabelListRequestService(queryKey string) vo.DTO {
|
||
return checkExIdPerformNoCreateConnect(queryKey, func(iwxConnect wxface.IWXConnect, newIWXConnect bool) vo.DTO {
|
||
//取基本信息
|
||
wxAccount := iwxConnect.GetWXAccount()
|
||
loginState := wxAccount.GetLoginState()
|
||
|
||
//判断在线情况
|
||
if loginState == baseinfo.MMLoginStateNoLogin {
|
||
return vo.NewFail("该账号需要重新登录!loginState == MMLoginStateNoLogin ")
|
||
} else if !iwxConnect.CheckOnLineStatus() {
|
||
return vo.NewFail("账号离线,自动上线失败!loginState == " + strconv.Itoa(int(wxAccount.GetLoginState())))
|
||
}
|
||
//获取请求管理器
|
||
reqInvoker := iwxConnect.GetWXReqInvoker()
|
||
resp, err := reqInvoker.SendGetContactLabelListRequest(true)
|
||
if err != nil {
|
||
return vo.NewFail("GetContactLabelListRequestService!" + err.Error())
|
||
}
|
||
return vo.NewSuccessObj(resp, "")
|
||
})
|
||
}
|
||
|
||
// AddContactLabelRequestService 添加标签
|
||
func AddContactLabelRequestService(queryKey string, m req.LabelModel) vo.DTO {
|
||
return checkExIdPerformNoCreateConnect(queryKey, func(iwxConnect wxface.IWXConnect, newIWXConnect bool) vo.DTO {
|
||
//取基本信息
|
||
wxAccount := iwxConnect.GetWXAccount()
|
||
loginState := wxAccount.GetLoginState()
|
||
|
||
//判断在线情况
|
||
if loginState == baseinfo.MMLoginStateNoLogin {
|
||
return vo.NewFail("该账号需要重新登录!loginState == MMLoginStateNoLogin ")
|
||
} else if !iwxConnect.CheckOnLineStatus() {
|
||
return vo.NewFail("账号离线,自动上线失败!loginState == " + strconv.Itoa(int(wxAccount.GetLoginState())))
|
||
}
|
||
//获取请求管理器
|
||
reqInvoker := iwxConnect.GetWXReqInvoker()
|
||
if len(m.LabelNameList) == 0 {
|
||
return vo.NewFail("没有要添加的标签")
|
||
}
|
||
resp, err := reqInvoker.SendAddContactLabelRequest(m.LabelNameList, true)
|
||
if err != nil {
|
||
return vo.NewFail("AddContactLabelRequestService!" + err.Error())
|
||
}
|
||
return vo.NewSuccessObj(resp, "")
|
||
})
|
||
}
|
||
|
||
// DelContactLabelRequestService 删除标签
|
||
func DelContactLabelRequestService(queryKey string, m req.LabelModel) vo.DTO {
|
||
return checkExIdPerformNoCreateConnect(queryKey, func(iwxConnect wxface.IWXConnect, newIWXConnect bool) vo.DTO {
|
||
//取基本信息
|
||
wxAccount := iwxConnect.GetWXAccount()
|
||
loginState := wxAccount.GetLoginState()
|
||
|
||
//判断在线情况
|
||
if loginState == baseinfo.MMLoginStateNoLogin {
|
||
return vo.NewFail("该账号需要重新登录!loginState == MMLoginStateNoLogin ")
|
||
} else if !iwxConnect.CheckOnLineStatus() {
|
||
return vo.NewFail("账号离线,自动上线失败!loginState == " + strconv.Itoa(int(wxAccount.GetLoginState())))
|
||
}
|
||
//获取请求管理器
|
||
reqInvoker := iwxConnect.GetWXReqInvoker()
|
||
resp, err := reqInvoker.SendDelContactLabelRequest(m.LabelId)
|
||
if err != nil {
|
||
return vo.NewFail("SendDelContactLabelRequestService!" + err.Error())
|
||
}
|
||
return vo.NewSuccessObj(resp, "")
|
||
})
|
||
}
|
||
|
||
// ModifyLabelRequestService 修改标签
|
||
func ModifyLabelRequestService(queryKey string, m req.LabelModel) vo.DTO {
|
||
return checkExIdPerformNoCreateConnect(queryKey, func(iwxConnect wxface.IWXConnect, newIWXConnect bool) vo.DTO {
|
||
//取基本信息
|
||
wxAccount := iwxConnect.GetWXAccount()
|
||
loginState := wxAccount.GetLoginState()
|
||
|
||
//判断在线情况
|
||
if loginState == baseinfo.MMLoginStateNoLogin {
|
||
return vo.NewFail("该账号需要重新登录!loginState == MMLoginStateNoLogin ")
|
||
} else if !iwxConnect.CheckOnLineStatus() {
|
||
return vo.NewFail("账号离线,自动上线失败!loginState == " + strconv.Itoa(int(wxAccount.GetLoginState())))
|
||
}
|
||
//获取请求管理器
|
||
reqInvoker := iwxConnect.GetWXReqInvoker()
|
||
resp, err := reqInvoker.SendModifyLabelRequest(m.UserLabelList)
|
||
if err != nil {
|
||
return vo.NewFail("SendDelContactLabelRequestService!" + err.Error())
|
||
}
|
||
return vo.NewSuccessObj(resp, "")
|
||
})
|
||
}
|
||
|
||
// 获取标签下好友
|
||
func GetWXFriendListByLabelIDService(queryKey string, req req.LabelModel) vo.DTO {
|
||
return checkExIdPerformNoCreateConnect(queryKey, func(iwxConnect wxface.IWXConnect, newIWXConnect bool) vo.DTO {
|
||
//取基本信息
|
||
wxAccount := iwxConnect.GetWXAccount()
|
||
loginState := wxAccount.GetLoginState()
|
||
//判断在线情况
|
||
if loginState == baseinfo.MMLoginStateNoLogin {
|
||
return vo.NewFail("该账号需要重新登录!loginState == MMLoginStateNoLogin ")
|
||
} else if !iwxConnect.CheckOnLineStatus() {
|
||
return vo.NewFail("账号离线,自动上线失败!loginState == " + strconv.Itoa(int(wxAccount.GetLoginState())))
|
||
}
|
||
//获取请求管理器
|
||
retList := make([]string, 0)
|
||
// 遍历好友 获取对应标签的好友列表
|
||
i, _ := strconv.Atoi(req.LabelId)
|
||
//重新拉取好友列表
|
||
if len(wxAccount.FriendMap) <= 0 {
|
||
//获取请求管理器
|
||
reqInvoker := iwxConnect.GetWXReqInvoker()
|
||
var CurrentWxcontactSeq = uint32(0)
|
||
var CurrentChatRoomContactSeq = uint32(0)
|
||
for true {
|
||
resp, err := reqInvoker.SendGetContactListPageRequest(CurrentWxcontactSeq, CurrentChatRoomContactSeq)
|
||
if err != nil {
|
||
log.Error("分页请求获取联系人出现error")
|
||
break
|
||
}
|
||
if resp.BaseResponse.GetRet() != 0 {
|
||
log.Error("分页请求获取联系人出现error=0")
|
||
break
|
||
}
|
||
CurrentWxcontactSeq = resp.GetCurrentWxcontactSeq()
|
||
CurrentChatRoomContactSeq = resp.GetCurrentChatRoomContactSeq()
|
||
if len(resp.GetContactUsernameList()) <= 0 {
|
||
break
|
||
}
|
||
//批量获取联系人
|
||
response, error := reqInvoker.SendGetContactRequestForList(resp.GetContactUsernameList(), nil)
|
||
if error != nil {
|
||
log.Error("获取详情出现error")
|
||
}
|
||
if response.BaseResponse.GetRet() != 0 {
|
||
log.Error("获取详情出现error=0")
|
||
break
|
||
}
|
||
for _, v := range response.GetContactList() {
|
||
wxAccount.AddWXFriendContact(v)
|
||
}
|
||
}
|
||
|
||
}
|
||
for userName, modContact := range wxAccount.FriendMap {
|
||
if wxAccount.ContainsLabel(modContact.GetLabelIdlist(), uint32(i)) {
|
||
retList = append(retList, userName)
|
||
}
|
||
}
|
||
return vo.NewSuccessObj(retList, "")
|
||
})
|
||
}
|