Skip to content

Commit

Permalink
Fix return value of send_msg & wrong value name of __produce_group_ch…
Browse files Browse the repository at this point in the history
…at [RB#58,59: brothertian]
  • Loading branch information
littlecodersh committed Aug 25, 2016
1 parent a4542be commit ebfe1c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ Q: 为什么我在设定了`itchat.auto_login()`的`enableCmdQR`为`True`后还

A: 这是由于没有安装可选的包`pillow`,可以使用右边的命令安装:`pip install pillow`

Q: 如何通过这个包将自己的微信号变为控制器?

A: 有两种方式:发送、接受自己UserName的消息;发送接收文件传输助手(filehelper)的消息

## Author

[LittleCoder](https://github.com/littlecodersh): 整体构架及完成Python2版本。
Expand Down
12 changes: 7 additions & 5 deletions itchat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import requests

BASE_URL = config.BASE_URL
QR_DIR = 'QR.jpg'

class client(object):
def __init__(self):
Expand Down Expand Up @@ -88,7 +89,6 @@ def get_QR(self, uuid = None, enableCmdQR = False):
if uuid == None: uuid = self.uuid
url = '%s/qrcode/%s'%(BASE_URL, uuid)
r = self.s.get(url, stream = True)
QR_DIR = 'QR.jpg'
with open(QR_DIR, 'wb') as f: f.write(r.content)
if enableCmdQR:
tools.print_cmd_qr(QR_DIR, enableCmdQR = enableCmdQR)
Expand All @@ -105,7 +105,7 @@ def check_login(self, uuid = None):
regx = r'window.code=(\d+)'
data = re.search(regx, r.text)
if data and data.group(1) == '200':
os.remove('QR.jpg')
os.remove(QR_DIR)
regx = r'window.redirect_uri="(\S+)";'
self.loginInfo['url'] = re.search(regx, r.text).group(1)
r = self.s.get(self.loginInfo['url'], allow_redirects=False)
Expand Down Expand Up @@ -392,7 +392,7 @@ def __produce_group_chat(self, msg):
if not r: return
actualUserName, content = r.groups()
try:
self.storageClass.groupDict[msg['FromUserName']][ActualUserName]
self.storageClass.groupDict[msg['FromUserName']][actualUserName]
except:
groupMemberList = self.get_batch_contract(msg['FromUserName'])['MemberList']
self.storageClass.groupDict[msg['FromUserName']] = {member['UserName']: member for member in groupMemberList}
Expand All @@ -418,6 +418,7 @@ def send_msg(self, msg = 'Test Message', toUserName = None):
}, }
headers = { 'ContentType': 'application/json; charset=UTF-8' }
r = self.s.post(url, data = json.dumps(payloads, ensure_ascii = False).encode('utf8'), headers = headers)
return r.json()['BaseResponse']['Ret'] == 0
def __upload_file(self, fileDir, isPicture = False):
if not tools.check_file(fileDir): return
url = 'https://file%s.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json'%('2' if '2' in self.loginInfo['url'] else '')
Expand Down Expand Up @@ -537,6 +538,7 @@ def create_chatroom(self, memberList, topic = ''):

r = self.s.post(url, data=json.dumps(params),headers=headers)
dic = json.loads(r.content.decode('utf8', 'replace'))
print(dic)
return dic['ChatRoomName']
def delete_member_from_chatroom(self, chatRoomName, memberList):
url = ('%s/webwxupdatechatroom?fun=delmember&pass_ticket=%s'%(
Expand All @@ -546,7 +548,7 @@ def delete_member_from_chatroom(self, chatRoomName, memberList):
'ChatRoomName': chatRoomName,
'DelMemberList': ','.join([member['UserName'] for member in memberList]), }
headers = {'content-type': 'application/json; charset=UTF-8'}
return self.s.post(url, data=json.dumps(params),headers=headers)
return self.s.post(url, data=json.dumps(params),headers=headers).json()
def add_member_into_chatroom(self, chatRoomName, memberList):
url = ('%s/webwxupdatechatroom?fun=addmember&pass_ticket=%s'%(
self.loginInfo['url'], self.loginInfo['pass_ticket']))
Expand All @@ -555,7 +557,7 @@ def add_member_into_chatroom(self, chatRoomName, memberList):
'ChatRoomName': chatRoomName,
'AddMemberList': ','.join([member['UserName'] for member in memberList]), }
headers = {'content-type': 'application/json; charset=UTF-8'}
r = self.s.post(url, data=json.dumps(params),headers=headers)
return self.s.post(url, data=json.dumps(params),headers=headers).json()

if __name__ == '__main__':
wcc = WeChatClient()
Expand Down

0 comments on commit ebfe1c7

Please sign in to comment.