瀏覽代碼

fix:企微刷新联系人修改

jimmyyem 1 月之前
父節點
當前提交
8bf4bad174
共有 2 個文件被更改,包括 74 次插入1 次删除
  1. 66 0
      hook/contact.go
  2. 8 1
      internal/logic/Wxhook/get_friends_and_groups_logic.go

+ 66 - 0
hook/contact.go

@@ -139,6 +139,72 @@ func (h *Hook) TriggerChatroomPush(wxWxid string) error {
 	return nil
 }
 
+// TriggerCustomerPushTask 刷新企微联系人
+func (h *Hook) TriggerCustomerPushTask(wxWxid string) error {
+	conn, err := h.connWorkPhone()
+	if err != nil {
+		err = fmt.Errorf("TriggerCustomerPushTask failed")
+		return err
+	}
+	defer func(conn *websocket.Conn) {
+		err = conn.Close()
+		if err != nil {
+			err = fmt.Errorf("TriggerCustomerPushTask failed")
+		}
+	}(conn)
+
+	message := map[string]interface{}{
+		"MsgType": "TriggerCustomerPushTask",
+		"Content": map[string]interface{}{
+			"WxId": wxWxid,
+		},
+	}
+	transportMessageJSON, err := json.Marshal(message)
+	if err != nil {
+		return err
+	}
+	// 发送 JSON 消息
+	err = conn.WriteMessage(websocket.TextMessage, transportMessageJSON)
+	if err != nil {
+		return fmt.Errorf("failed to send message: %v", err)
+	}
+
+	return nil
+}
+
+// TriggerConversationPushTask 刷新企微群组
+func (h *Hook) TriggerConversationPushTask(wxWxid string) error {
+	conn, err := h.connWorkPhone()
+	if err != nil {
+		err = fmt.Errorf("TriggerConversationPushTask failed")
+		return err
+	}
+	defer func(conn *websocket.Conn) {
+		err = conn.Close()
+		if err != nil {
+			err = fmt.Errorf("TriggerConversationPushTask failed")
+		}
+	}(conn)
+
+	message := map[string]interface{}{
+		"MsgType": "TriggerConversationPushTask",
+		"Content": map[string]interface{}{
+			"WxId": wxWxid,
+		},
+	}
+	transportMessageJSON, err := json.Marshal(message)
+	if err != nil {
+		return err
+	}
+	// 发送 JSON 消息
+	err = conn.WriteMessage(websocket.TextMessage, transportMessageJSON)
+	if err != nil {
+		return fmt.Errorf("failed to send message: %v", err)
+	}
+
+	return nil
+}
+
 func (h *Hook) AddFriendInChatRoom(ChatRoomId, wxWxid, friendId, desc string) error {
 	conn, err := h.connWorkPhone()
 	if err != nil {

+ 8 - 1
internal/logic/Wxhook/get_friends_and_groups_logic.go

@@ -221,7 +221,14 @@ func (l *GetFriendsAndGroupsLogic) GetFriendsAndGroups(req *types.IDReq) (resp *
 			l.Error("GetWechatFriendList 请求失败", err)
 			return nil, err
 		}
-		_ = hookClient.TriggerChatroomPush(wxInfo.Wxid)
+
+		if wxInfo.Ctype == 3 {
+			_ = hookClient.TriggerCustomerPushTask(wxInfo.Wxid)
+			_ = hookClient.TriggerConversationPushTask(wxInfo.Wxid)
+		} else {
+			_ = hookClient.TriggerChatroomPush(wxInfo.Wxid)
+		}
+
 		for _, friend := range result.Data {
 			friendType := 1
 			if friend.Type == 1 {