Skip to content

Instantly share code, notes, and snippets.

@littlecodersh
Last active January 23, 2023 15:35
Embed
What would you like to do?
Main script behind itchat robot
#coding=utf8
import itchat
# tuling plugin can be get here:
# https://github.com/littlecodersh/EasierLife/tree/master/Plugins/Tuling
from tuling import get_response
@itchat.msg_register('Text')
def text_reply(msg):
if u'作者' in msg['Text'] or u'主人' in msg['Text']:
return u'你可以在这里了解他:https://github.com/littlecodersh'
elif u'源代码' in msg['Text'] or u'获取文件' in msg['Text']:
itchat.send('@fil@main.py', msg['FromUserName'])
return u'这就是现在机器人后台的代码,是不是很简单呢?'
elif u'获取图片' in msg['Text']:
itchat.send('@img@applaud.gif', msg['FromUserName']) # there should be a picture
else:
return get_response(msg['Text']) or u'收到:' + msg['Text']
@itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video'])
def atta_reply(msg):
return ({ 'Picture': u'图片', 'Recording': u'录音',
'Attachment': u'附件', 'Video': u'视频', }.get(msg['Type']) +
u'已下载到本地') # download function is: msg['Text'](msg['FileName'])
@itchat.msg_register(['Map', 'Card', 'Note', 'Sharing'])
def mm_reply(msg):
if msg['Type'] == 'Map':
return u'收到位置分享'
elif msg['Type'] == 'Sharing':
return u'收到分享' + msg['Text']
elif msg['Type'] == 'Note':
return u'收到:' + msg['Text']
elif msg['Type'] == 'Card':
return u'收到好友信息:' + msg['Text']['Alias']
@itchat.msg_register('Text', isGroupChat = True)
def group_reply(msg):
if msg['isAt']:
return u'@%s\u2005%s' % (msg['ActualNickName'],
get_response(msg['Text']) or u'收到:' + msg['Text'])
@itchat.msg_register('Friends')
def add_friend(msg):
itchat.add_friend(**msg['Text'])
itchat.send_msg(u'项目主页:github.com/littlecodersh/ItChat\n'
+ u'源代码 :回复源代码\n' + u'图片获取:回复获取图片\n'
+ u'欢迎Star我的项目关注更新!', msg['RecommendInfo']['UserName'])
itchat.auto_login(True, enableCmdQR=True)
itchat.run()
@Shunder
Copy link

Shunder commented Mar 12, 2017

好像应该应该是#coding=utf-8 ?

@adustdu2015
Copy link

图灵机器人的python如何引入?是否需要注册图灵机器人?

@ipfgao
Copy link

ipfgao commented Jul 1, 2017

二维码变形了是什么情况?

改成itchat.auto_login(True, enableCmdQR=2)后可以了

@daicoolb
Copy link

daicoolb commented Jul 8, 2017

如何将itchat的程序变成是一个service 跑在后台呢?
这是我的python代码:

#!/usr/bin/env python
#coding:utf-8
import itchat

reply=u'不好意思,暑期启动了Itchat接口,设置了自动回复,现在不在服务区'

@itchat.msg_register(itchat.content.TEXT)
def print_content(msg):
#print(msg['Text'])
#def reply(msg):
itchat.send(reply,msg['FromUserName'])

itchat.auto_login(hotReload=True,enableCmdQR=2)
itchat.run()

编写一个service服务,但是启动总是不成功,是itchat有什么依赖么?

@JasonQWJ
Copy link

python 小白 这个问题是用法问题吗?
File "main.py", line 11
elif u'源代码' in msg['Text'] or u'获取文件' in msg['Text']:
^
SyntaxError: invalid syntax

@kaaaaai
Copy link

kaaaaai commented Aug 7, 2017

改成itchat.auto_login(True, enableCmdQR=2)后,二维码扫描显示“未找到17330349的相关信息”怎么破?而且第二次运行就二维码就无法被扫描

@zhao750456695
Copy link

新注册微信不能登陆网页版怎么破?

@xiaoguo
Copy link

xiaoguo commented Feb 7, 2018

@ kaaaaai 你最近怎么破的?我也遇到同样问题

@Dpuntu
Copy link

Dpuntu commented Feb 12, 2018

新微信好像都不行,我的都注册有两个月了,还是不行

@Mylife4air
Copy link

如何监听新用户入群?

@yanchenling
Copy link

print(get_response(a, 'ItChat'))
NameError: name 'a' is not defined

@yanchenling
Copy link

生成的二维码扫不上。。。

@mansonami
Copy link

itchat.auto_login(hotReload=True) 扫码不过的可以热启动

@PhoenixLegend
Copy link

二维码扫不上的,改成itchat.auto_login(True, enableCmdQR=2)后可以了

@Cuick
Copy link

Cuick commented Oct 25, 2018

~ » python3 main.py tuyou@zxzxck
Traceback (most recent call last):
File "main.py", line 49, in
itchat.auto_login(True, enableCmdQR=True)
File "/usr/local/lib/python3.6/site-packages/itchat/components/register.py", line 29, in auto_login
loginCallback=loginCallback, exitCallback=exitCallback):
File "/usr/local/lib/python3.6/site-packages/itchat/components/hotreload.py", line 54, in load_login_status
self.loginInfo['User'] = templates.User(self.loginInfo['User'])
KeyError: 'User'

大佬们这个怎么解决啊?

@tonyzyang
Copy link

扫完之后登陆了,但我并没有看到登录的网页啊?

@biyingwu
Copy link

有人知道tuling如何下载吗

@a514259542
Copy link

图灵机器人的python如何引入?是否需要注册图灵机器人?

同问

@yxc6123
Copy link

yxc6123 commented Aug 1, 2019

图灵机器人的python如何引入?是否需要注册图灵机器人?

同问

是的哦。要下载注册
https://github.com/littlecodersh/EasierLife/blob/master/Plugins/Tuling/tuling.py

@JackHvikee
Copy link

JackHvikee commented Feb 23, 2020

Start auto replying.
LOG OUT!

立马就退出的原因:挂了VPN(mac),退出vpn即可

@sacevan
Copy link

sacevan commented Jun 16, 2021

~ » python3 main.py tuyou@zxzxck
Traceback (most recent call last):
File "main.py", line 49, in
itchat.auto_login(True, enableCmdQR=True)
File "/usr/local/lib/python3.6/site-packages/itchat/components/register.py", line 29, in auto_login
loginCallback=loginCallback, exitCallback=exitCallback):
File "/usr/local/lib/python3.6/site-packages/itchat/components/hotreload.py", line 54, in load_login_status
self.loginInfo['User'] = templates.User(self.loginInfo['User'])
KeyError: 'User'

大佬们这个怎么解决啊?

itchat.auto_login(hotReload=False) 取消热启动

@sacevan
Copy link

sacevan commented Jun 16, 2021

1203为了你的帐号安全,此微信号不能登录网页微信。你可以使用Windows微信或Mac微信在电脑端登录。Windows微信下载地址:https://pc.weixin.qq.com Mac微信下载地址:https://mac.weixin.qq.com

大佬们这个怎么解决啊?

@SAMZONG
Copy link

SAMZONG commented Sep 15, 2021

1203为了你的帐号安全,此微信号不能登录网页微信。你可以使用Windows微信或Mac微信在电脑端登录。Windows微信下载地址:https://pc.weixin.qq.com Mac微信下载地址:https://mac.weixin.qq.com

大佬们这个怎么解决啊?

集成下 itchat_uos

pip install itchat_uos

@XYKaiDream
Copy link

新注册的号,装了itchat_uos后依然登陆不上去KeyError: 'wxsid'

@hyh19962008
Copy link

扫码之后显示

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    itchat.auto_login()
  File "/home/demon/.local/lib/python3.6/site-packages/itchat/components/register.py", line 36, in auto_login
    loginCallback=loginCallback, exitCallback=exitCallback)
  File "/home/demon/.local/lib/python3.6/site-packages/itchat/components/login.py", line 55, in login
    status = self.check_login()
  File "/home/demon/.local/lib/python3.6/site-packages/itchat/components/login.py", line 141, in check_login
    if process_login_info(self, r.text):
  File "/home/demon/.local/lib/python3.6/site-packages/itchat/components/login.py", line 183, in process_login_info
    core.loginInfo['wxsid'] = core.loginInfo['BaseRequest']['Sid'] = cookies["wxsid"]
KeyError: 'wxsid'

@muchun0
Copy link

muchun0 commented Oct 14, 2022

无法扫码登陆,在循环下载二维码。尝试了上边两位大佬提供的添加参数【itchat.auto_login(hotReload=True) 扫码不过的可以热启动】和【二维码扫不上的,改成itchat.auto_login(True, enableCmdQR=2)后可以了】均未解决

@sereinwong33
Copy link

扫码之后没动静,没有网页啊

@daicoolb
Copy link

daicoolb commented Dec 12, 2022 via email

@xuxin1
Copy link

xuxin1 commented Jan 10, 2023

扫码之后显示

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    itchat.auto_login()
  File "/home/demon/.local/lib/python3.6/site-packages/itchat/components/register.py", line 36, in auto_login
    loginCallback=loginCallback, exitCallback=exitCallback)
  File "/home/demon/.local/lib/python3.6/site-packages/itchat/components/login.py", line 55, in login
    status = self.check_login()
  File "/home/demon/.local/lib/python3.6/site-packages/itchat/components/login.py", line 141, in check_login
    if process_login_info(self, r.text):
  File "/home/demon/.local/lib/python3.6/site-packages/itchat/components/login.py", line 183, in process_login_info
    core.loginInfo['wxsid'] = core.loginInfo['BaseRequest']['Sid'] = cookies["wxsid"]
KeyError: 'wxsid'

了解下 https://github.com/zhayujie/chatgpt-on-wechat/wiki/FAQs

4.登录报错 KeyError:'wxsid'
login.py", line 183, in process_login_info
    core.loginInfo['wxsid'] = core.loginInfo['BaseRequest']['Sid'] = cookies["wxsid"]
KeyError: 'wxsid'
一般原因为使用了itchat且无法登录网页版微信,解决方法是先卸载itchat,然后安装itchat-uos 1.5.0.dev0版本。

@daicoolb
Copy link

daicoolb commented Jan 10, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment