contact.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package hook
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // 获取标签信息
  7. func (h *Hook) GetContactLabelList() (result GetContactLabelListReap, err error) {
  8. resp, err := h.Client.R().SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.WxPort + "/GetContactLabelList")
  9. if err != nil {
  10. return
  11. }
  12. if !resp.IsSuccessState() {
  13. err = fmt.Errorf("GetContactLabelList failed with status code %d", resp.StatusCode)
  14. return
  15. }
  16. return
  17. }
  18. // 获取好友和群信息
  19. func (h *Hook) GetFriendAndChatRoomList(typeStr string) (result GetFriendAndChatRoomListReap, err error) {
  20. resp, err := h.Client.R().SetBody(&GetFriendAndChatRoomListReq{
  21. Type: typeStr,
  22. }).SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.WxPort + "/GetFriendAndChatRoomList")
  23. if err != nil {
  24. return
  25. }
  26. if !resp.IsSuccessState() {
  27. err = fmt.Errorf("GetFriendAndChatRoomList failed with status code %d", resp.StatusCode)
  28. return
  29. }
  30. return
  31. }
  32. // 批量获取联系人简明信息(每次100个)
  33. func (h *Hook) BatchGetContactBriefInfo(wxids []string) (result BatchGetContactBriefInfoReap, err error) {
  34. wxidList := strings.Join(wxids, ",")
  35. resp, err := h.Client.R().SetBody(&BatchGetContactBriefInfoReq{
  36. WxidList: wxidList,
  37. }).SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.WxPort + "/BatchGetContactBriefInfo")
  38. if err != nil {
  39. return
  40. }
  41. if !resp.IsSuccessState() {
  42. err = fmt.Errorf("BatchGetChatRoomMemberWxid failed with status code %d", resp.StatusCode)
  43. return
  44. }
  45. return
  46. }
  47. // 添加新的好友
  48. func (h *Hook) AddNewFriend(v3_wxid string, v4 string, desc string, addType string, role string) (result AddNewFriendReap, err error) {
  49. resp, err := h.Client.R().SetBody(&AddNewFriendReq{
  50. V3Wxid: v3_wxid,
  51. V4: v4,
  52. Desc: desc,
  53. AddType: addType,
  54. Role: role,
  55. }).SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.WxPort + "/AddNewFriend")
  56. if err != nil {
  57. return
  58. }
  59. if !resp.IsSuccessState() {
  60. err = fmt.Errorf("AddNewFriend failed with status code %d", resp.StatusCode)
  61. return
  62. }
  63. return
  64. }