Giter Club home page Giter Club logo

flask-weixin's Introduction

Flask-Weixin

Flask-Weixin is the implementation for http://mp.weixin.qq.com/ with the flavor of Flask. It can be used without Flask too.

Wheel Status Latest Version Travis CI Coverage Status

Installation

You can install Flask-Weixin with pip:

$ pip install Flask-Weixin

Or, with setuptools easy_install in case you didn't have pip:

$ easy_install Flask-Weixin

Getting Started

Eager to get started? It is always the Flask way to create a new instance:

from flask_weixin import Weixin

weixin = Weixin(app)

Or pass the app later:

weixin = Weixin()
weixin.init_app(app)

However, you need to configure before using it, here is the configuration list:

  • WEIXIN_TOKEN: this is required
  • WEIXIN_SENDER: a default sender, optional
  • WEIXIN_EXPIRES_IN: not expires by default

For Flask user, it is suggested that you use the default view function:

app.add_url_rule('/', view_func=weixin.view_func)

@weixin.register('*')
def reply(**kwargs):
    username = kwargs.get('sender')
    sender = kwargs.get('receiver')
    content = kwargs.get('content')
    return weixin.reply(
        username, sender=sender, content=content
    )

The example above will reply anything the user sent.

Or you can register a function to handle a specific keyword:

@weixin.register('help')
def reply_help(**kwargs):
    ...

this function will be used to handle text message help.

There are more ways to match messages to handlers:

@weixin.register(type='event', event='subscribe')
def send_welcome(**kwargs):
    username = kwargs.get('sender')
    sender = kwargs.get('receiver')
    return weixin.reply(username, sender=sender, content='Thanks for follow!')

this function will send a message to new followers.

Message Types

Every message from weixin has these information:

  • id: message ID
  • receiver: which is ToUserName in the official documentation
  • sender: which is FromUserName in the official documentation
  • type: message type
  • timestamp: message timestamp

Text Type

Text type has an extra data: content.

Image Type

Image type has an extra data: picurl.

Link Type

Link type has extra data:

  • title: article title
  • description: article description
  • url: original url of the article

Location Type

Location type has extra data:

  • location_x
  • location_y
  • scale
  • label

Event Type

Event type has extra data:

  • event
  • event_key
  • latitude
  • longitude
  • precision

Voice Type

Event type has extra data:

  • media_id
  • format
  • recognition

flask-weixin's People

Contributors

lepture avatar tonyseek avatar verycb avatar wong2 avatar xtao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-weixin's Issues

关于订阅提示信息的问题

你好!我的微信公众号目前需要用到一些微信方面的API,用了您的这个库,觉得非常非常方便。不过现在有一个问题,新用户订阅我们微信号的时候,我们希望能够有一段文字提示。请问这个库里面有没有提供这样的功能?

No 'README.rst' found for installation

~  pip install Flask-Weixin
Downloading/unpacking Flask-Weixin
  Downloading Flask-Weixin-0.1.0.tar.gz
  Running setup.py egg_info for package Flask-Weixin
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/vagrant/build/Flask-Weixin/setup.py", line 26, in <module>
        long_description=open('README.rst').read(),
    IOError: [Errno 2] No such file or directory: 'README.rst'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/vagrant/build/Flask-Weixin/setup.py", line 26, in <module>

    long_description=open('README.rst').read(),

IOError: [Errno 2] No such file or directory: 'README.rst'

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /home/vagrant/.pip/pip.log

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.