Skip to content

Commit

Permalink
自动响应好友请求
Browse files Browse the repository at this point in the history
 在hand_all_msg中调用即可
 #自动通过好友申请
        if msg['msg_type_id'] == 37:
            print json.dumps(msg,indent=4)
            print self.apply_useradd_requests(msg['content']['data'])
            #发送消息吧。。。。
  • Loading branch information
vivre90 authored Aug 26, 2016
1 parent 88c815f commit addc616
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions wxbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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')]
Expand Down Expand Up @@ -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('.', '')
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit addc616

Please sign in to comment.