From 8fff2d64a842a6a8ea2b7e5d462451702255fd7d Mon Sep 17 00:00:00 2001 From: liuwangsheng01 Date: Wed, 17 Aug 2016 10:11:58 +0800 Subject: [PATCH 01/20] add QQ group --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 0bb6a6b..0d30a0b 100644 --- a/README.md +++ b/README.md @@ -264,3 +264,9 @@ python test.py [Urinx/WeixinBot](https://github.com/Urinx/WeixinBot) 网页版微信API,包含终端版微信及微信机器人 [zixia/wechaty](https://github.com/zixia/wechaty) Wechaty is wechat for bot in Javascript(ES6). It's a Personal Account Robot Framework/Library. + +## 7 交流讨论 + +问题可以直接开 **issue** + +**QQ** 交流群: **429134510** From a95b4d056d56fc23f121b84e3484211dd341084e Mon Sep 17 00:00:00 2001 From: liuwangsheng01 Date: Wed, 17 Aug 2016 18:50:14 +0800 Subject: [PATCH 02/20] reformat code --- wxbot.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/wxbot.py b/wxbot.py index c394bb3..3ed0cc8 100644 --- a/wxbot.py +++ b/wxbot.py @@ -542,17 +542,16 @@ def handle_msg(self, r): if msg['MsgType'] == 51: # init message msg_type_id = 0 user['name'] = 'system' - elif msg['MsgType'] == 37:# 有人加好友 ,37为加好友信息? - weixinhao=msg['Content'] - weixinhao=weixinhao[weixinhao.index('fromusername='):weixinhao.index('encryptusername')] - weixinhao=weixinhao[weixinhao.index('"')+1:weixinhao.rindex('"')] - print u'[INFO] 请求加好友!' - print u' 昵称:' + msg['RecommendInfo']['NickName'] - #print u'ID:' + msg['RecommendInfo']['UserName'] - print u' 附加消息:'+msg['RecommendInfo']['Content'] - #print u'Ticket:'+msg['RecommendInfo']['Ticket'] # Ticket添加好友时要用 - print u' 微信号:'+weixinhao #未设置微信号的 腾讯会自动生成一段微信ID 但是无法通过搜索 搜索到此人 - return + elif msg['MsgType'] == 37: # friend request + pass + # content = msg['Content'] + # username = content[content.index('fromusername='): content.index('encryptusername')] + # username = username[username.index('"') + 1: username.rindex('"')] + # print u'[Friend Request]' + # print u' Nickname:' + msg['RecommendInfo']['NickName'] + # print u' 附加消息:'+msg['RecommendInfo']['Content'] + # # print u'Ticket:'+msg['RecommendInfo']['Ticket'] # Ticket添加好友时要用 + # print u' 微信号:'+username #未设置微信号的 腾讯会自动生成一段微信ID 但是无法通过搜索 搜索到此人 elif msg['FromUserName'] == self.my_account['UserName']: # Self msg_type_id = 1 user['name'] = 'self' From 88c815fa4430a89647977b4dbc331663608dde65 Mon Sep 17 00:00:00 2001 From: liuwangsheng01 Date: Wed, 17 Aug 2016 19:20:46 +0800 Subject: [PATCH 03/20] fix null pointer --- wxbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index 3ed0cc8..5ffeae7 100644 --- a/wxbot.py +++ b/wxbot.py @@ -493,7 +493,7 @@ def extract_msg_content(self, msg_type_id, msg): print ' | desc: %s' % self.search_content('des', content, 'xml') print ' | link: %s' % msg['Url'] print ' | from: %s' % self.search_content('appname', content, 'xml') - print ' | content: %s' % msg.get('content')[:20] + print ' | content: %s' % (msg.get('content')[:20] if msg.get('content') else "unknown") print ' --------------------------' elif mtype == 62: From addc6162624e474049e35f5fc9efa247d677a8bd Mon Sep 17 00:00:00 2001 From: vivre Date: Fri, 26 Aug 2016 22:15:10 +0800 Subject: [PATCH 04/20] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在hand_all_msg中调用即可 #自动通过好友申请 if msg['msg_type_id'] == 37: print json.dumps(msg,indent=4) print self.apply_useradd_requests(msg['content']['data']) #发送消息吧。。。。 --- wxbot.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/wxbot.py b/wxbot.py index 5ffeae7..35dbe5f 100644 --- a/wxbot.py +++ b/wxbot.py @@ -448,6 +448,11 @@ def extract_msg_content(self, msg_type_id, msg): if self.DEBUG: voice = self.get_voice(msg_id) print ' %s[Voice] %s' % (msg_prefix, voice) + elif mtype == 37: + msg_content['type'] = 37 + msg_content['data'] = msg['RecommendInfo'] + if self.DEBUG: + print ' %s[useradd] %s' % (msg_prefix,msg['RecommendInfo']['NickName']) elif mtype == 42: msg_content['type'] = 5 info = msg['RecommendInfo'] @@ -543,6 +548,7 @@ def handle_msg(self, r): msg_type_id = 0 user['name'] = 'system' elif msg['MsgType'] == 37: # friend request + msg_type_id = 37 pass # content = msg['Content'] # username = content[content.index('fromusername='): content.index('encryptusername')] @@ -639,6 +645,33 @@ def proc_msg(self): if check_time < 0.8: time.sleep(1 - check_time) + def apply_useradd_requests(self,RecommendInfo): + url = self.base_uri + '/webwxverifyuser?r='+str(int(time.time()))+'&lang=zh_CN' + params = { + "BaseRequest": self.base_request, + "Opcode": 3, + "VerifyUserListSize": 1, + "VerifyUserList": [ + { + "Value": RecommendInfo['UserName'], + "VerifyUserTicket": RecommendInfo['Ticket'] } + ], + "VerifyContent": "", + "SceneListCount": 1, + "SceneList": [ + 33 + ], + "skey": self.skey + } + 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 send_msg_by_uid(self, word, dst='filehelper'): url = self.base_uri + '/webwxsendmsg?pass_ticket=%s' % self.pass_ticket msg_id = str(int(time.time() * 1000)) + str(random.random())[:5].replace('.', '') @@ -667,8 +700,8 @@ def upload_media(self, fpath, is_img=False): if not os.path.exists(fpath): print '[ERROR] File not exists.' return None - url_1 = 'https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' - url_2 = 'https://file2.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' + url_1 = 'https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' + url_2 = 'https://file2.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' flen = str(os.path.getsize(fpath)) ftype = mimetypes.guess_type(fpath)[0] or 'application/octet-stream' files = { From ea1bda0becb9731ad020d0fd655d79731f19ca2c Mon Sep 17 00:00:00 2001 From: liuwangsheng01 Date: Fri, 26 Aug 2016 22:28:53 +0800 Subject: [PATCH 05/20] change url of upload_media --- wxbot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wxbot.py b/wxbot.py index 35dbe5f..8d71dd7 100644 --- a/wxbot.py +++ b/wxbot.py @@ -700,8 +700,8 @@ def upload_media(self, fpath, is_img=False): if not os.path.exists(fpath): print '[ERROR] File not exists.' return None - url_1 = 'https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' - url_2 = 'https://file2.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' + url_1 = 'https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' + url_2 = 'https://file2.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' flen = str(os.path.getsize(fpath)) ftype = mimetypes.guess_type(fpath)[0] or 'application/octet-stream' files = { From fae4cf1ec6818665c1317bf1abda736b688c425a Mon Sep 17 00:00:00 2001 From: liuwangsheng01 Date: Sat, 27 Aug 2016 00:18:56 +0800 Subject: [PATCH 06/20] change path for send file and img msg --- wxbot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wxbot.py b/wxbot.py index 8d71dd7..0658155 100644 --- a/wxbot.py +++ b/wxbot.py @@ -721,7 +721,7 @@ def upload_media(self, fpath, is_img=False): })), 'webwx_data_ticket': (None, self.session.cookies['webwx_data_ticket']), 'pass_ticket': (None, self.pass_ticket), - 'filename': (os.path.basename(os.path.join(self.temp_pwd,fpath)), open(os.path.join(self.temp_pwd,fpath), 'rb'),ftype.split('/')[1]), + 'filename': (os.path.basename(fpath), open(fpath, 'rb'),ftype.split('/')[1]), } self.file_index += 1 try: @@ -815,7 +815,7 @@ def send_msg(self, name, word, isfile=False): uid = self.get_user_id(name) if uid is not None: if isfile: - with open(os.path.join(self.temp_pwd,word), 'r') as f: + with open(word, 'r') as f: result = True for line in f.readlines(): line = line.replace('\n', '') From faf1a3039f16ce46f6c7146ac80741c22eda0833 Mon Sep 17 00:00:00 2001 From: liuwangsheng01 Date: Sat, 27 Aug 2016 13:15:09 +0800 Subject: [PATCH 07/20] exception fix --- wxbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index 0658155..69e0ea4 100644 --- a/wxbot.py +++ b/wxbot.py @@ -584,7 +584,7 @@ def handle_msg(self, r): user['name'] = HTMLParser.HTMLParser().unescape(user['name']) if self.DEBUG and msg_type_id != 0: - print '[MSG] %s:' % user['name'] + print u'[MSG] %s:' % user['name'] content = self.extract_msg_content(msg_type_id, msg) message = {'msg_type_id': msg_type_id, 'msg_id': msg['MsgId'], From d7f99d15e5a6f665746c802b1744ca3539c7b36d Mon Sep 17 00:00:00 2001 From: vivre Date: Sat, 27 Aug 2016 15:23:30 +0800 Subject: [PATCH 08/20] =?UTF-8?q?=E6=96=B0=E5=A2=9E3=E4=B8=AA=E7=BE=A4?= =?UTF-8?q?=E7=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、主动向群内好友打招呼添加好友 2、将好友加入到群聊中 3、将群用户从群中剔除,只有群管理员有权限 --- wxbot.py | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/wxbot.py b/wxbot.py index 69e0ea4..be3a15c 100644 --- a/wxbot.py +++ b/wxbot.py @@ -620,6 +620,10 @@ def proc_msg(self): r = self.sync() if r is not None: self.handle_msg(r) + elif selector == '4': # 通讯录更新 + r = self.sync() + if r is not None: + self.get_contact() elif selector == '6': # 可能是红包 r = self.sync() if r is not None: @@ -672,6 +676,98 @@ def apply_useradd_requests(self,RecommendInfo): dic = r.json() return dic['BaseResponse']['Ret'] == 0 + def add_groupuser_to_friend_by_uid(self,uid,VerifyContent): + """ + 主动向群内人员打招呼,提交添加好友请求 + uid-群内人员得uid VerifyContent-好友招呼内容 + 慎用此接口!封号后果自负!慎用此接口!封号后果自负!慎用此接口!封号后果自负! + """ + if self.is_contact(uid): + return True + url = self.base_uri + '/webwxverifyuser?r='+str(int(time.time()))+'&lang=zh_CN' + params ={ + "BaseRequest": self.base_request, + "Opcode": 2, + "VerifyUserListSize": 1, + "VerifyUserList": [ + { + "Value": uid, + "VerifyUserTicket": "" + } + ], + "VerifyContent": VerifyContent, + "SceneListCount": 1, + "SceneList": [ + 33 + ], + "skey": self.skey + } + 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 add_friend_to_group(self,uid,group_name): + """ + 将好友加入到群聊中 + """ + 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=addmember&pass_ticket=%s' % self.pass_ticket + params ={ + "AddMemberList": 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): + """ + 将群用户从群中剔除,只有群管理员有权限 + """ + uid = "" + for user in self.group_members[gid]: + if user['NickName'] == uname: + uid = user['UserName'] + if uid == "": + return False + url = self.base_uri + '/webwxupdatechatroom?fun=delmember&pass_ticket=%s' % self.pass_ticket + params ={ + "DelMemberList": 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 send_msg_by_uid(self, word, dst='filehelper'): url = self.base_uri + '/webwxsendmsg?pass_ticket=%s' % self.pass_ticket msg_id = str(int(time.time() * 1000)) + str(random.random())[:5].replace('.', '') From e954cafb832f42067466aa4c447df779f4a573e9 Mon Sep 17 00:00:00 2001 From: liuwangsheng01 Date: Thu, 29 Sep 2016 17:21:11 +0800 Subject: [PATCH 09/20] update README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d30a0b..d846902 100644 --- a/README.md +++ b/README.md @@ -41,12 +41,14 @@ Web微信协议参考资料: [qwx: WeChat Qt frontend 微信Qt前端](https://github.com/xiangzhai/qwx) +**master-dev 分支为开发版本,用于测试新特性,欢迎使用后提出建议!** + ## 1 环境与依赖 此版本只能运行于Python 2环境 。 -**wxBot** 用到了Python **requests** , **pypng** , **Pillow* 以及 **pyqrcode** 库。 +**wxBot** 用到了Python **requests** , **pypng** , **Pillow** 以及 **pyqrcode** 库。 使用之前需要所依赖的库: From c949109325b6811843523b23b47918b352d4b4a7 Mon Sep 17 00:00:00 2001 From: liuwangsheng01 Date: Tue, 11 Oct 2016 11:57:59 +0800 Subject: [PATCH 10/20] change push url and file upload url --- wxbot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wxbot.py b/wxbot.py index be3a15c..ee3128f 100644 --- a/wxbot.py +++ b/wxbot.py @@ -796,8 +796,8 @@ def upload_media(self, fpath, is_img=False): if not os.path.exists(fpath): print '[ERROR] File not exists.' return None - url_1 = 'https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' - url_2 = 'https://file2.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' + url_1 = 'https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' + url_2 = 'https://file2.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' flen = str(os.path.getsize(fpath)) ftype = mimetypes.guess_type(fpath)[0] or 'application/octet-stream' files = { @@ -1133,7 +1133,7 @@ def sync_check(self): 'synckey': self.sync_key_str, '_': int(time.time()), } - url = 'https://' + self.sync_host + '.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params) + url = 'https://' + self.sync_host + '.wx.qq.com/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params) try: r = self.session.get(url, timeout=60) r.encoding = 'utf-8' From 7db6de7b9efcec059c5fdb7476eca8ab9e7f8227 Mon Sep 17 00:00:00 2001 From: vivre Date: Wed, 12 Oct 2016 15:08:59 +0800 Subject: [PATCH 11/20] =?UTF-8?q?=E4=BF=AE=E5=A4=8D1102=EF=BC=8C0=E5=92=8C?= =?UTF-8?q?-1=EF=BC=8C-1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_sync_check函数完善,将4个服务器地址均放进去检测,得到合适的心跳服务器地址 --- wxbot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wxbot.py b/wxbot.py index ee3128f..abea7fe 100644 --- a/wxbot.py +++ b/wxbot.py @@ -1116,7 +1116,7 @@ def status_notify(self): return dic['BaseResponse']['Ret'] == 0 def test_sync_check(self): - for host in ['webpush', 'webpush2']: + for host in ['webpush.wx', 'webpush2.wx','webpush.weixin', 'webpush2.weixin2',]: self.sync_host = host retcode = self.sync_check()[0] if retcode == '0': @@ -1133,7 +1133,7 @@ def sync_check(self): 'synckey': self.sync_key_str, '_': int(time.time()), } - url = 'https://' + self.sync_host + '.wx.qq.com/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params) + url = 'https://' + self.sync_host + '.qq.com/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params) try: r = self.session.get(url, timeout=60) r.encoding = 'utf-8' From 5c74dbd47566a238f555b7a48a792a58b555d0e9 Mon Sep 17 00:00:00 2001 From: vivre Date: Wed, 12 Oct 2016 15:15:52 +0800 Subject: [PATCH 12/20] fix bug fix bug --- wxbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index abea7fe..c813dae 100644 --- a/wxbot.py +++ b/wxbot.py @@ -1116,7 +1116,7 @@ def status_notify(self): return dic['BaseResponse']['Ret'] == 0 def test_sync_check(self): - for host in ['webpush.wx', 'webpush2.wx','webpush.weixin', 'webpush2.weixin2',]: + for host in ['webpush.wx', 'webpush2.wx','webpush.weixin', 'webpush2.weixin2']: self.sync_host = host retcode = self.sync_check()[0] if retcode == '0': From b60084e4c978fa6df3ac9bc666ae57e23fa4947d Mon Sep 17 00:00:00 2001 From: vivre Date: Wed, 12 Oct 2016 15:54:24 +0800 Subject: [PATCH 13/20] fix bugs fix bugs --- wxbot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wxbot.py b/wxbot.py index c813dae..b4d6a61 100644 --- a/wxbot.py +++ b/wxbot.py @@ -1116,9 +1116,12 @@ def status_notify(self): return dic['BaseResponse']['Ret'] == 0 def test_sync_check(self): - for host in ['webpush.wx', 'webpush2.wx','webpush.weixin', 'webpush2.weixin2']: + for host in ['webpush.wx', 'webpush2.wx2','webpush.weixin', 'webpush2.weixin2']: self.sync_host = host - retcode = self.sync_check()[0] + try: + retcode = self.sync_check()[0] + except: + retcode == -1 if retcode == '0': return True return False From d8907994ae1f25d650576a5323612db2259161fb Mon Sep 17 00:00:00 2001 From: vivre Date: Wed, 12 Oct 2016 17:57:38 +0800 Subject: [PATCH 14/20] =?UTF-8?q?test=5Fsync=5Fcheck=20=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_sync_check 兼容 --- wxbot.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/wxbot.py b/wxbot.py index b4d6a61..c7413be 100644 --- a/wxbot.py +++ b/wxbot.py @@ -1116,14 +1116,15 @@ def status_notify(self): return dic['BaseResponse']['Ret'] == 0 def test_sync_check(self): - for host in ['webpush.wx', 'webpush2.wx2','webpush.weixin', 'webpush2.weixin2']: - self.sync_host = host - try: - retcode = self.sync_check()[0] - except: - retcode == -1 - if retcode == '0': - return True + for host1 in ['webpush', 'webpush2']: + for host2 in ['weixin','weixin2','wx','wx2']: + self.sync_host = host1+host2 + try: + retcode = self.sync_check()[0] + except: + retcode == -1 + if retcode == '0': + return True return False def sync_check(self): From 51c37e02b3127a91e9e789cec5a6961c5ba1568b Mon Sep 17 00:00:00 2001 From: vivre Date: Wed, 12 Oct 2016 18:01:19 +0800 Subject: [PATCH 15/20] =?UTF-8?q?=E5=85=BC=E5=AE=B9sync=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B31102=EF=BC=8C0=E5=92=8C-1=EF=BC=8C-1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 兼容sync,解决1102,0和-1,-1问题 --- wxbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index c7413be..66ca144 100644 --- a/wxbot.py +++ b/wxbot.py @@ -1116,7 +1116,7 @@ def status_notify(self): return dic['BaseResponse']['Ret'] == 0 def test_sync_check(self): - for host1 in ['webpush', 'webpush2']: + for host1 in ['webpush.', 'webpush2.']: for host2 in ['weixin','weixin2','wx','wx2']: self.sync_host = host1+host2 try: From b09cd76e2ce7b09b06d8eedf74d2ed98995e0177 Mon Sep 17 00:00:00 2001 From: vivre Date: Wed, 12 Oct 2016 19:01:20 +0800 Subject: [PATCH 16/20] fix --- wxbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index 66ca144..50f724a 100644 --- a/wxbot.py +++ b/wxbot.py @@ -1118,7 +1118,7 @@ def status_notify(self): def test_sync_check(self): for host1 in ['webpush.', 'webpush2.']: for host2 in ['weixin','weixin2','wx','wx2']: - self.sync_host = host1+host2 + self.sync_host = host1+host2 try: retcode = self.sync_check()[0] except: From 95729f4bff041674fcb627444724f2665469477f Mon Sep 17 00:00:00 2001 From: vivre Date: Thu, 13 Oct 2016 22:22:13 +0800 Subject: [PATCH 17/20] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=BE=A4=E8=81=8A=E5=90=8D=E7=A7=B0=E6=8E=A5=E5=8F=A3--set=5Fg?= =?UTF-8?q?roup=5Fname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增设置群聊名称接口--set_group_name --- wxbot.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/wxbot.py b/wxbot.py index 50f724a..7b72256 100644 --- a/wxbot.py +++ b/wxbot.py @@ -767,6 +767,24 @@ def delete_user_from_group(self,uname,gid): dic = r.json() return dic['BaseResponse']['Ret'] == 0 + def set_group_name(self,gid,gname): + """ + 设置群聊名称 + """ + url = self.base_uri + '/webwxupdatechatroom?fun=modtopic&pass_ticket=%s' % self.pass_ticket + params ={ + "NewTopic": gname, + "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 send_msg_by_uid(self, word, dst='filehelper'): url = self.base_uri + '/webwxsendmsg?pass_ticket=%s' % self.pass_ticket From efe2c02b77ae08dd3990947eece553070bc60f2b Mon Sep 17 00:00:00 2001 From: xuncl Date: Fri, 14 Oct 2016 17:58:37 +0800 Subject: [PATCH 18/20] fix a syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复之前vivre90更新的一点小疏忽 --- wxbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index 7b72256..1e6c99b 100644 --- a/wxbot.py +++ b/wxbot.py @@ -1140,7 +1140,7 @@ def test_sync_check(self): try: retcode = self.sync_check()[0] except: - retcode == -1 + retcode = -1 if retcode == '0': return True return False From bb44aca2062afef9d643e5b666fcc2d7fba5b9d8 Mon Sep 17 00:00:00 2001 From: vivre Date: Wed, 26 Oct 2016 00:20:52 +0800 Subject: [PATCH 19/20] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=97=B6=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E4=B8=8A=E4=BC=A0=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=81=20=E5=9C=A8=E8=BF=94=E5=9B=9E-1,-1?= =?UTF-8?q?=E6=97=B6=E9=99=8D=E4=BD=8E=E5=BF=83=E8=B7=B3=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=A2=91=E7=8E=87=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、更新心跳服务器获取方式,新增base_host 2、文件上传同步base_host 3、-1,-1错误的时候降低心跳获取频率 --- wxbot.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/wxbot.py b/wxbot.py index 1e6c99b..dc6a523 100644 --- a/wxbot.py +++ b/wxbot.py @@ -62,6 +62,7 @@ def __init__(self): self.DEBUG = False self.uuid = '' self.base_uri = '' + self.base_host = '' self.redirect_uri = '' self.uin = '' self.sid = '' @@ -641,6 +642,7 @@ def proc_msg(self): self.handle_msg(r) else: print '[DEBUG] sync_check:', retcode, selector + time.sleep(10) self.schedule() except: print '[ERROR] Except in proc_msg' @@ -814,8 +816,8 @@ def upload_media(self, fpath, is_img=False): if not os.path.exists(fpath): print '[ERROR] File not exists.' return None - url_1 = 'https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' - url_2 = 'https://file2.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' + url_1 = 'https://file.'+self.base_host+'/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' + url_2 = 'https://file2.'+self.base_host+'/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json' flen = str(os.path.getsize(fpath)) ftype = mimetypes.guess_type(fpath)[0] or 'application/octet-stream' files = { @@ -1057,6 +1059,8 @@ def wait4login(self): redirect_uri = param.group(1) + '&fun=new' self.redirect_uri = redirect_uri self.base_uri = redirect_uri[:redirect_uri.rfind('/')] + temp_host = self.base_uri[8:] + self.base_host = temp_host[:host2.find("/")] return code elif code == TIMEOUT: print '[ERROR] WeChat login timeout. retry in %s secs later...' % (try_later_secs,) @@ -1135,14 +1139,13 @@ def status_notify(self): def test_sync_check(self): for host1 in ['webpush.', 'webpush2.']: - for host2 in ['weixin','weixin2','wx','wx2']: - self.sync_host = host1+host2 - try: - retcode = self.sync_check()[0] - except: - retcode = -1 - if retcode == '0': - return True + self.sync_host = host1+self.base_host + try: + retcode = self.sync_check()[0] + except: + retcode = -1 + if retcode == '0': + return True return False def sync_check(self): @@ -1155,7 +1158,7 @@ def sync_check(self): 'synckey': self.sync_key_str, '_': int(time.time()), } - url = 'https://' + self.sync_host + '.qq.com/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params) + url = 'https://' + self.sync_host + '/cgi-bin/mmwebwx-bin/synccheck?' + urllib.urlencode(params) try: r = self.session.get(url, timeout=60) r.encoding = 'utf-8' From efef7ee17215a41e67778d35f46bca315200e1b6 Mon Sep 17 00:00:00 2001 From: vivre Date: Wed, 26 Oct 2016 17:11:36 +0800 Subject: [PATCH 20/20] fix bugs~~~ fix bugs~~~ --- wxbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxbot.py b/wxbot.py index dc6a523..e2c9173 100644 --- a/wxbot.py +++ b/wxbot.py @@ -1060,7 +1060,7 @@ def wait4login(self): self.redirect_uri = redirect_uri self.base_uri = redirect_uri[:redirect_uri.rfind('/')] temp_host = self.base_uri[8:] - self.base_host = temp_host[:host2.find("/")] + self.base_host = temp_host[:temp_host.find("/")] return code elif code == TIMEOUT: print '[ERROR] WeChat login timeout. retry in %s secs later...' % (try_later_secs,)