Skip to content

Commit

Permalink
Fix friend update bug [BR#187: anderson916]
Browse files Browse the repository at this point in the history
  • Loading branch information
littlecodersh committed Dec 21, 2016
1 parent 3114de1 commit 99a1293
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ itchat是一个开源的微信个人号接口,使用python调用微信从未

当然,该api的使用远不止一个机器人,更多的功能等着你来发现,比如[这些][tutorial2]

该接口与公众号接口[itchatmp][itchatmp]共享类似的操作方式,学习一次掌握两个工具。

如今微信已经成为了个人社交的很大一部分,希望这个项目能够帮助你扩展你的个人的微信号、方便自己的生活。

## 安装
Expand Down Expand Up @@ -255,6 +257,7 @@ A: 有些账号是天生无法给自己的账号发送信息的,建议使用`f
[py27]: https://img.shields.io/badge/python-2.7-ff69b4.svg
[py35]: https://img.shields.io/badge/python-3.5-red.svg
[english-version]: https://github.com/littlecodersh/ItChat/blob/master/README_EN.md
[itchatmp]: https://github.com/littlecodersh/itchatmp
[document]: https://itchat.readthedocs.org/zh/latest/
[tutorial2]: http://python.jobbole.com/86532/
[robot-source-code]: https://gist.github.com/littlecodersh/ec8ddab12364323c97d4e36459174f0d
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Accessing your personal wechat account through itchat in python has never been e

A wechat robot can handle all the basic messages with only less than 30 lines of codes.

And it's similiar to itchatmp (api for wechat massive platform), learn once and get two tools.

Now Wechat is an important part of personal life, hopefully this repo can help you extend your personal wechat account's functionality and enbetter user's experience with wechat.

**Installation**
Expand Down
2 changes: 2 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Accessing your personal wechat account through itchat in python has never been e

A wechat robot can handle all the basic messages with only less than 30 lines of codes.

And it's similiar to itchatmp (api for wechat massive platform), learn once and get two tools.

Now Wechat is an important part of personal life, hopefully this repo can help you extend your personal wechat account's functionality and enbetter user's experience with wechat.

## Installation
Expand Down
2 changes: 1 addition & 1 deletion itchat/components/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def update_friend(self, userName):
update_local_friends(self, friendList)
r = [self.storageClass.search_friends(userName=f['UserName'])
for f in friendList]
return r if 1 < len(r) else r[0]
return r if len(r) != 1 else r[0]

def update_info_dict(oldInfoDict, newInfoDict):
'''
Expand Down
1 change: 0 additions & 1 deletion itchat/components/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def process_login_info(core, loginContent):
else:
core.loginInfo['fileUrl'] = core.loginInfo['syncUrl'] = core.loginInfo['url']
core.loginInfo['deviceid'] = 'e' + repr(random.random())[2:17]
core.loginInfo['msgid'] = int(time.time() * 1000)
core.loginInfo['BaseRequest'] = {}
for node in xml.dom.minidom.parseString(r.text).documentElement.childNodes:
if node.nodeName == 'skey':
Expand Down
23 changes: 9 additions & 14 deletions itchat/components/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,10 @@ def send_raw_msg(self, msgType, content, toUserName):
'Content': content,
'FromUserName': self.storageClass.userName,
'ToUserName': (toUserName if toUserName else self.storageClass.userName),
'LocalID': self.loginInfo['msgid'],
'ClientMsgId': self.loginInfo['msgid'],
'LocalID': int(time.time() * 1e4),
'ClientMsgId': int(time.time() * 1e4),
},
'Scene': 0, }
self.loginInfo['msgid'] += 1
headers = { 'ContentType': 'application/json; charset=UTF-8', 'User-Agent' : config.USER_AGENT }
r = self.s.post(url, headers=headers,
data=json.dumps(data, ensure_ascii=False).encode('utf8'))
Expand Down Expand Up @@ -253,7 +252,6 @@ def upload_file(self, fileDir, isPicture=False, isVideo=False,
r = upload_chunk_file(self, fileDir, fileSymbol, fileSize,
fileMd5, file, toUserName, chunk, chunks)
file.close()
self.loginInfo['msgid'] += 1
return ReturnValue(rawResponse=r)

def upload_chunk_file(core, fileDir, fileSymbol, fileSize,
Expand All @@ -273,7 +271,7 @@ def upload_chunk_file(core, fileDir, fileSymbol, fileSize,
'uploadmediarequest': (None, json.dumps({
'UploadType': (None, 2),
'BaseRequest': core.loginInfo['BaseRequest'],
'ClientMediaId': core.loginInfo['msgid'],
'ClientMediaId': int(time.time() * 1e4),
'TotalLen': fileSize,
'StartPos': 0,
'DataLen': fileSize,
Expand Down Expand Up @@ -311,10 +309,9 @@ def send_file(self, fileDir, toUserName=None, mediaId=None):
"<fileext>%s</fileext></appattach><extinfo></extinfo></appmsg>"%os.path.splitext(fileDir)[1].replace('.','')),
'FromUserName': self.storageClass.userName,
'ToUserName': toUserName,
'LocalID': self.loginInfo['msgid'],
'ClientMsgId': self.loginInfo['msgid'], },
'LocalID': int(time.time() * 1e4),
'ClientMsgId': int(time.time() * 1e4), },
'Scene': 0, }
self.loginInfo['msgid'] += 1
headers = {
'User-Agent': config.USER_AGENT,
'Content-Type': 'application/json;charset=UTF-8', }
Expand All @@ -340,10 +337,9 @@ def send_image(self, fileDir, toUserName=None, mediaId=None):
'MediaId': mediaId,
'FromUserName': self.storageClass.userName,
'ToUserName': toUserName,
'LocalID': self.loginInfo['msgid'],
'ClientMsgId': self.loginInfo['msgid'], },
'LocalID': int(time.time() * 1e4),
'ClientMsgId': int(time.time() * 1e4), },
'Scene': 0, }
self.loginInfo['msgid'] += 1
if fileDir[-4:] == '.gif':
url = '%s/webwxsendemoticon?fun=sys' % self.loginInfo['url']
data['Msg']['Type'] = 47
Expand Down Expand Up @@ -374,10 +370,9 @@ def send_video(self, fileDir=None, toUserName=None, mediaId=None):
'MediaId' : mediaId,
'FromUserName' : self.storageClass.userName,
'ToUserName' : toUserName,
'LocalID' : self.loginInfo['msgid'],
'ClientMsgId' : self.loginInfo['msgid'], },
'LocalID' : int(time.time() * 1e4),
'ClientMsgId' : int(time.time() * 1e4), },
'Scene': 0, }
self.loginInfo['msgid'] += 1
headers = {
'User-Agent' : config.USER_AGENT,
'Content-Type': 'application/json;charset=UTF-8', }
Expand Down
2 changes: 1 addition & 1 deletion itchat/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os, platform

VERSION = '1.2.13'
VERSION = '1.2.15'
BASE_URL = 'https://login.weixin.qq.com'
OS = platform.system() #Windows, Linux, Darwin
DIR = os.getcwd()
Expand Down

0 comments on commit 99a1293

Please sign in to comment.