Skip to content

jerrypnz/ItChat

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

itchat

Gitter python English version

itchat是一个开源的微信个人号接口,使用他你可以轻松的通过命令行使用个人微信号。

微信机器人的实现及命令行版微信见robot分支,Python 3.5.1 的版本可见这里:here

使用不到三十行的代码,你就可以完成一个能够处理所有信息的微信机器人。

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

Documents

你可以在这里获取api的使用帮助。

Installation

可以通过本命令安装itchat:

pip install itchat

Simple uses

通过如下代码,微信已经可以就日常的各种信息进行获取与回复。

import itchat, time

@itchat.msg_register(['Text', 'Map', 'Card', 'Note', 'Sharing'])
def text_reply(msg):
    itchat.send('%s: %s'%(msg['Type'], msg['Text']), msg['FromUserName'])

@itchat.msg_register(['Picture', 'Recording', 'Attachment', 'Video'])
def download_files(msg):
    fileDir = '%s%s'%(msg['Type'], int(time.time()))
    msg['Text'](fileDir)
    itchat.send('%s received'%msg['Type'], msg['FromUserName'])
    itchat.send('@%s@%s'%('img' if msg['Type'] == 'Picture' else 'fil', fileDir), msg['FromUserName'])

@itchat.msg_register('Friends')
def add_friend(msg):
    itchat.add_friend(**msg['Text'])
    itchat.get_contract()
    itchat.send_msg('Nice to meet you!', msg['RecommendInfo']['UserName'])

@itchat.msg_register('Text', isGroupChat = True)
def text_reply(msg):
    if msg['isAt']:
        itchat.send(u'@%s\u2005I received: %s'%(msg['ActualNickName'], msg['Content']), msg['FromUserName'])

itchat.auto_login()
itchat.run()

Have a try

这是一个基于这一项目的开源小机器人,百闻不如一见,有兴趣可以尝试一下。

QRCode

Screenshots

file_autoreply login_page

FAQ

Q: 为什么中文的文件没有办法上传?

A: 这是由于requests的编码问题导致的。若需要支持中文文件传输,将fields.py文件放入requests包的packages/urllib3下即可

Author

LittleCoder: 整体构架及完成Python2版本。

Chyroc: 完成Python3版本。

See also

liuwons/wxBot: 类似的基于Python的微信机器人

zixia/wechaty: 基于Javascript(ES6)的微信个人账号机器人NodeJS框架/库

Comments

如果有什么问题或者建议都可以在这个Issue和我讨论

或者也可以在gitter上交流:Gitter

About

API for Wechat. 微信个人号接口(支持文件、图片上下载)、微信机器人及命令行微信。三十行即可自定义个人号机器人。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%