Parcourir la source

邀请好友入群

develop
H Vs il y a 1 mois
Parent
révision
2d442c22b0
2 fichiers modifiés avec 53 ajouts et 3 suppressions
  1. +36
    -2
      resources/messages_resource.py
  2. +17
    -1
      wechat/gewe_chat.py

+ 36
- 2
resources/messages_resource.py Voir le fichier

@@ -635,17 +635,23 @@ def handle_xml(token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
type_value = root.find(".//appmsg/type").text
handlers = {
57: handle_xml_reference,
5: handle_xml_invite_group
}
handler = handlers.get(type_value)
if handler:
return handler(token_id,app_id, wxid,msg_data,from_wxid, to_wxid)
elif "邀请你加入了群聊" in msg_content_xml: # 邀请加入群聊
logger.warning(f"xml消息 {type_value} 邀请你加入了群聊.todo")
# elif "邀请你加入了群聊" in msg_content_xml: # 邀请加入群聊
# logger.warning(f"xml消息 {type_value} 邀请你加入了群聊.todo")
else:
print(f"xml消息 {type_value} 未解析")




def handle_xml_reference(token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
'''
引用消息
判断此类消息的逻辑:$.Data.MsgType=49 并且 解析$.Data.Content.string中的xml msg.appmsg.type=57
'''
callback_to_user=from_wxid
@@ -675,6 +681,34 @@ def handle_xml_reference(token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
gewe_chat.wxchat.save_session_messages_to_cache(hash_key, {"role": "assistant", "content": reply_content})
gewe_chat.wxchat.post_text(token_id,app_id,callback_to_user,reply_content)


def handle_xml_invite_group(token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
'''
群聊邀请
判断此类消息的逻辑:$.Data.MsgType=49
并且 解析$.Data.Content.string中的xml msg.appmsg.title=邀请你加入群聊(根据手机设置的系统语言title会有调整,不同语言关键字不同)
'''
logger.info(f'{wxid} 群聊邀请')
msg_content_xml=msg_data["Content"]["string"]
root = ET.fromstring(msg_content_xml)
title_value = root.find(".//appmsg/title").text
if '邀请你加入群聊' in title_value:
invite_url = root.find('.//url').text
ret,msg,data=gewe_chat.wxchat.agree_join_room(token_id,app_id,invite_url)
if ret==200:
logger.info(f'群聊邀请,同意加入群聊 {msg} {data}')
chatroom_id=data.get('ChatRoomId')
ret,msg,data=gewe_chat.wxchat.save_contract_list(token_id,app_id,chatroom_id,3)
logger.info(f'群聊邀请,保存到通讯录 chatroom_id {chatroom_id} {msg}')
gewe_chat.wxchat.update_group_info_to_cache(token_id,app_id,wxid,chatroom_id)
gewe_chat.wxchat.update_group_members_to_cache(token_id,app_id,wxid,chatroom_id)
else:
logger.warning(f'群聊邀请,同意加入群聊失败 {msg} {data}')




def handle_add_friend_notice(token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
'''
好友添加请求通知


+ 17
- 1
wechat/gewe_chat.py Voir le fichier

@@ -596,9 +596,25 @@ class GeWeChatCom:
}
response = requests.post(url=api_url, headers=headers, data=json.dumps(data))
response_object = response.json()
#print(response_object)
return response_object.get('ret',None),response_object.get('msg',None),response_object.get('data',None)

def agree_join_room(self,token_id,app_id,url):
'''
同意入群
'''
api_url = f"{self.base_url}/v2/api/group/agreeJoinRoom"
headers = {
'X-GEWE-TOKEN': token_id,
'Content-Type': 'application/json'
}
data = {
"appId": app_id,
"url": url,
}
response = requests.post(url=api_url, headers=headers, data=json.dumps(data))
response_object = response.json()
return response_object.get('ret',None),response_object.get('msg',None),response_object.get('data',None)
############################### 朋友圈模块 ###################################
# 在新设备登录后的1-3天内,您将无法使用朋友圈发布、点赞、评论等功能。在此期间,如果尝试进行这些操作,您将收到来自微信团队的提醒。请注意遵守相关规定。



Chargement…
Annuler
Enregistrer