Giter Club home page Giter Club logo

itchatmp's Introduction

itchatmp

py27 py35 English version

itchatmp是一个开源的微信公众号、企业号接口,使用python调用微信公众号从未如此简单。

基于tornado框架,轻松满足效率需求。支持普通使用、nginx反向代理与wsgi。

同样的命令,支持同步与协程调用,适合各层次开发者使用。

与个人号接口itchat共享类似的操作方式,学习一次掌握两个工具。

安装

可以通过本命令安装itchatmp:

pip install itchatmp

快速入门

有了itchatmp,如果你想要回复发给自己的文本消息,只需要这样:

import itchatmp

itchatmp.update_config(itchatmp.WechatConfig(
    token='yourToken',
    appId = 'yourAppId',
    appSecret = 'yourAppSecret'))

@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
    return msg['Content']

itchatmp.run()

一些进阶应用可以在Advanced uses中看到,或者你也可以阅览文档

演示机器人

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

QRCode

截屏

demo

进阶使用

企业号配置

在配置时设置copId而非appId即可。

另,由于企业号没有明文模式,所以必须将加密模式设置为安全。

具体的设置可以看这里

协程使用

如果你需要使用协程版本的itchatmp,你需要另外安装一个组件:

pip install itchatmphttp

这样,你的itchatmp就变成协程版本了。同样,删除以后就变回了线程池版本。

例如回复信息的操作,协程也只需要这样写:

import itchatmp
from tornado import gen

itchatmp.update_config(itchatmp.WechatConfig(
    token='yourToken',
    appId = 'yourAppId',
    appSecret = 'yourAppSecret'))

@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):
    yield gen.sleep(3)
    r = yield itchatmp.send('First message', msg['FromUserName'])
    print('First message sent: %s' % r)
    yield gen.sleep(3)
    r = yield itchatmp.send('First message', msg['FromUserName'])
    print('Second message sent: %s' % r)

itchatmp.run()

itchatmp里面所有的方法都变成了协程方法,如果你不熟悉协程建议不要使用,线程池也足够满足普通需求。

如果你问出类似为什么time.sleep阻塞了协程的问题,我会很困扰的。

WSGI使用

如果你需要生成一个能够在类似SAE的平台上包装的应用,你可以这样生成:

app = itchatmp.run(isWsgi=True)

如果你还是无法配置,请阅读文档一栏的部署部分。

意见与建议

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

当然也可以加入我们新建的QQ群讨论:438747166

itchatmp's People

Contributors

littlecodersh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.