Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: littlecodersh/ItChat
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: luvletter2333/ItChat
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Feb 28, 2021

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9c49b4a View commit details
  2. update version to 1.4.0

    luvletter2333 committed Feb 28, 2021
    Copy the full SHA
    8050361 View commit details
  3. Copy the full SHA
    e4a2221 View commit details
  4. Copy the full SHA
    a546adb View commit details
Showing with 50 additions and 13 deletions.
  1. +3 −0 .gitignore
  2. +10 −0 README.md
  3. +28 −11 itchat/components/login.py
  4. +4 −1 itchat/config.py
  5. +5 −1 itchat/utils.py
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -9,3 +9,6 @@ test.py
itchat.pkl
QR.jpg
.DS_Store
venv/*
.idea/*
.vscode/*
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -12,6 +12,16 @@ itchat是一个开源的微信个人号接口,使用python调用微信从未

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



## 安装 UOS Patch

暂时请通过github安装

```
pip3 install git+https://github.com/luvletter2333/ItChat.git
```

## 安装

可以通过本命令安装itchat:
39 changes: 28 additions & 11 deletions itchat/components/login.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@

logger = logging.getLogger('itchat')


def load_login(core):
core.login = login
core.get_QRuuid = get_QRuuid
@@ -30,6 +31,7 @@ def load_login(core):
core.get_msg = get_msg
core.logout = logout


def login(self, enableCmdQR=False, picDir=None, qrCallback=None,
loginCallback=None, exitCallback=None):
if self.alive or self.isLogging:
@@ -97,7 +99,9 @@ def get_QRuuid(self):
url = '%s/jslogin' % config.BASE_URL
params = {
'appid' : 'wx782c26e4c19acffb',
'fun' : 'new', }
'fun' : 'new',
'redirect_uri' : 'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?mod=desktop',
'lang' : 'zh_CN' }
headers = { 'User-Agent' : config.USER_AGENT }
r = self.s.get(url, params=params, headers=headers)
regx = r'window.QRLogin.code = (\d+); window.QRLogin.uuid = "(\S+?)";'
@@ -151,7 +155,11 @@ def process_login_info(core, loginContent):
'''
regx = r'window.redirect_uri="(\S+)";'
core.loginInfo['url'] = re.search(regx, loginContent).group(1)
headers = { 'User-Agent' : config.USER_AGENT }
headers = { 'User-Agent' : config.USER_AGENT,
'client-version' : config.UOS_PATCH_CLIENT_VERSION,
'extspam' : config.UOS_PATCH_EXTSPAM,
'referer' : 'https://wx.qq.com/?&lang=zh_CN&target=t'
}
r = core.s.get(core.loginInfo['url'], headers=headers, allow_redirects=False)
core.loginInfo['url'] = core.loginInfo['url'][:core.loginInfo['url'].rfind('/')]
for indexUrl, detailedUrl in (
@@ -170,15 +178,24 @@ def process_login_info(core, loginContent):
core.loginInfo['deviceid'] = 'e' + repr(random.random())[2:17]
core.loginInfo['logintime'] = int(time.time() * 1e3)
core.loginInfo['BaseRequest'] = {}
for node in xml.dom.minidom.parseString(r.text).documentElement.childNodes:
if node.nodeName == 'skey':
core.loginInfo['skey'] = core.loginInfo['BaseRequest']['Skey'] = node.childNodes[0].data
elif node.nodeName == 'wxsid':
core.loginInfo['wxsid'] = core.loginInfo['BaseRequest']['Sid'] = node.childNodes[0].data
elif node.nodeName == 'wxuin':
core.loginInfo['wxuin'] = core.loginInfo['BaseRequest']['Uin'] = node.childNodes[0].data
elif node.nodeName == 'pass_ticket':
core.loginInfo['pass_ticket'] = core.loginInfo['BaseRequest']['DeviceID'] = node.childNodes[0].data
cookies = core.s.cookies.get_dict()
core.loginInfo['skey'] = core.loginInfo['BaseRequest']['Skey'] = ""
core.loginInfo['wxsid'] = core.loginInfo['BaseRequest']['Sid'] = cookies["wxsid"]
core.loginInfo['wxuin'] = core.loginInfo['BaseRequest']['Uin'] = cookies["wxuin"]
core.loginInfo['pass_ticket'] = core.loginInfo['BaseRequest']['DeviceID'] = core.loginInfo['deviceid']
# A question : why pass_ticket == DeviceID ?
# deviceID is only a randomly generated number

# UOS PATCH By luvletter2333, Sun Feb 28 10:00 PM
# for node in xml.dom.minidom.parseString(r.text).documentElement.childNodes:
# if node.nodeName == 'skey':
# core.loginInfo['skey'] = core.loginInfo['BaseRequest']['Skey'] = node.childNodes[0].data
# elif node.nodeName == 'wxsid':
# core.loginInfo['wxsid'] = core.loginInfo['BaseRequest']['Sid'] = node.childNodes[0].data
# elif node.nodeName == 'wxuin':
# core.loginInfo['wxuin'] = core.loginInfo['BaseRequest']['Uin'] = node.childNodes[0].data
# elif node.nodeName == 'pass_ticket':
# core.loginInfo['pass_ticket'] = core.loginInfo['BaseRequest']['DeviceID'] = node.childNodes[0].data
if not all([key in core.loginInfo for key in ('skey', 'wxsid', 'wxuin', 'pass_ticket')]):
logger.error('Your wechat account may be LIMITED to log in WEB wechat, error info:\n%s' % r.text)
core.isLogging = False
5 changes: 4 additions & 1 deletion itchat/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os, platform

VERSION = '1.3.10'
VERSION = '1.4.0'
BASE_URL = 'https://login.weixin.qq.com'
OS = platform.system() # Windows, Linux, Darwin
DIR = os.getcwd()
DEFAULT_QR = 'QR.png'
TIMEOUT = (10, 60)

USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'

UOS_PATCH_CLIENT_VERSION = '2.0.0'
UOS_PATCH_EXTSPAM = 'Gp8ICJkIEpkICggwMDAwMDAwMRAGGoAI1GiJSIpeO1RZTq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cRFZcWjgc2wCKh+uCYkTVbNQpB9B90YlNmI3fWTuUOUjwOzQRxJZj11NsimjOJ50qQwTTFj6qQvQ1a/I+MkTx5UO+yNHl718JWcR3AXGmv/aa9rD1eNP8ioTGlOZwPgmr2sor2iBpKTOrB83QgZXP+xRYkb4zVC+LoAXEoIa1+zArywlgREer7DLePukkU6wHTkuSaF+ge5Of1bXuU4i938WJHj0t3D8uQxkJvoFi/EYN/7u2P1zGRLV4dHVUsZMGCCtnO6BBigFMAA='
6 changes: 5 additions & 1 deletion itchat/utils.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,10 @@

emojiRegex = re.compile(r'<span class="emoji emoji(.{1,10})"></span>')
htmlParser = HTMLParser()
if not hasattr(htmlParser, 'unescape'):
import html
htmlParser.unescape = html.unescape
# FIX Python 3.9 HTMLParser.unescape is removed. See https://docs.python.org/3.9/whatsnew/3.9.html
try:
b = u'\u2588'
sys.stdout.write(b + '\r')
@@ -71,7 +75,7 @@ def _emoji_formatter(m):
def msg_formatter(d, k):
emoji_formatter(d, k)
d[k] = d[k].replace('<br/>', '\n')
d[k] = htmlParser.unescape(d[k])
d[k] = htmlParser.unescape(d[k])

def check_file(fileDir):
try: