From 0cf285cc8cb5f4a0003736c6e7a7bc73ec476a28 Mon Sep 17 00:00:00 2001 From: chong Date: Mon, 2 Jan 2017 17:55:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0invite=5Ffriend=5Fto=5Fgroup?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=BA=94=E5=AF=B9=E7=94=B1=E4=BA=8E?= =?UTF-8?q?=E7=BE=A4=E4=BA=BA=E6=95=B0=E8=BF=87=E5=A4=9A=E9=80=A0=E6=88=90?= =?UTF-8?q?=E7=9A=84=E6=97=A0=E6=B3=95=E7=9B=B4=E6=8E=A5=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=B0=E7=BE=A4=E3=80=81add=5Ffriend=5Fto?= =?UTF-8?q?=5Fgroup=E6=96=B9=E6=B3=95=E8=B0=83=E7=94=A8=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wxbot.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/wxbot.py b/wxbot.py index 3f7ab70..74ea073 100644 --- a/wxbot.py +++ b/wxbot.py @@ -874,6 +874,38 @@ class WXBot: dic = r.json() return dic['BaseResponse']['Ret'] == 0 + def invite_friend_to_group(self,uid,group_name): + """ + 将好友加入到群中。对人数多的群,需要调用此方法。 + 拉人时,可以先尝试使用add_friend_to_group方法,当调用失败(Ret=1)时,再尝试调用此方法。 + """ + gid = '' + # 通过群名获取群id,群没保存到通讯录中的话无法添加哦 + for group in self.group_list: + if group['NickName'] == group_name: + gid = group['UserName'] + if gid == '': + return False + # 通过群id判断uid是否在群中 + for user in self.group_members[gid]: + if user['UserName'] == uid: + # 已经在群里面了,不用加了 + return True + url = self.base_uri + '/webwxupdatechatroom?fun=invitemember&pass_ticket=%s' % self.pass_ticket + params = { + "InviteMemberList": uid, + "ChatRoomName": gid, + "BaseRequest": self.base_request + } + headers = {'content-type': 'application/json; charset=UTF-8'} + data = json.dumps(params, ensure_ascii=False).encode('utf8') + try: + r = self.session.post(url, data=data, headers=headers) + except (ConnectionError, ReadTimeout): + return False + dic = r.json() + return dic['BaseResponse']['Ret'] == 0 + def delete_user_from_group(self,uname,gid): """ 将群用户从群中剔除,只有群管理员有权限