From 7bcd6d2a8e80c82b2c7983317a9c3ac48eccf5ce Mon Sep 17 00:00:00 2001 From: "mr.gao" Date: Thu, 22 Jun 2017 11:46:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、获取群成员数量 2、发送图片扩展 --- wxbot.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index 837bc66..b176517 100644 --- a/wxbot.py +++ b/wxbot.py @@ -120,6 +120,20 @@ def __init__(self): self.encry_chat_room_id_list = [] # 存储群聊的EncryChatRoomId,获取群内成员头像时需要用到 self.file_index = 0 + + #获取群成员数量 + def get_group_count(self): + group_count = [] + + if len(self.group_list) == 0: + return "" + + for group in self.group_list: + group_name = group["NickName"] + group_size = len(self.group_members[group["UserName"]]) + group_count.append({'group_name': group_name, 'count': group_size}) + + return json.dumps(group_count) #在未传入bot_conf的情况下尝试载入本地配置文件,WxbotManage使用 def load_conf(self,bot_conf): @@ -378,7 +392,6 @@ def get_group_member_name(self, gid, uid): def get_contact_info(self, uid): return self.account_info['normal_member'].get(uid) - def get_group_member_info(self, uid): return self.account_info['group_member'].get(uid) @@ -1116,6 +1129,32 @@ def send_img_msg_by_uid(self, fpath, uid): except Exception,e: return False + # 发送图片扩展 + def send_img_msg_by_uid_ex(self, ftype, mid, uid): + url = self.base_uri + '/webwxsendmsgimg?fun=async&f=json' + data = { + 'BaseRequest': self.base_request, + 'Msg': { + 'Type': 3, + 'MediaId': mid, + 'FromUserName': self.my_account['UserName'], + 'ToUserName': uid, + 'LocalID': str(time.time() * 1e7), + 'ClientMsgId': str(time.time() * 1e7), }, } + if ftype == '.gif': + url = self.base_uri + '/webwxsendemoticon?fun=sys' + data['Msg']['Type'] = 47 + data['Msg']['EmojiFlag'] = 2 + try: + r = self.session.post(url, data=json.dumps(data), timeout=120) + res = json.loads(r.text) + if res['BaseResponse']['Ret'] == 0: + return True + else: + return False + except Exception,e: + return False + def get_user_id(self, name): if name == '': return None From e36476a90fdd5fd6da4bda18a855c84cb42708d0 Mon Sep 17 00:00:00 2001 From: "mr.gao" Date: Thu, 22 Jun 2017 11:51:06 +0800 Subject: [PATCH 2/2] fix return object --- wxbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index b176517..b874747 100644 --- a/wxbot.py +++ b/wxbot.py @@ -133,7 +133,7 @@ def get_group_count(self): group_size = len(self.group_members[group["UserName"]]) group_count.append({'group_name': group_name, 'count': group_size}) - return json.dumps(group_count) + return group_count #在未传入bot_conf的情况下尝试载入本地配置文件,WxbotManage使用 def load_conf(self,bot_conf):