Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Oct 17, 2013
1 parent 1284b98 commit c71fe92
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ clean: clean-build clean-pyc clean-docs
clean-build:
@rm -fr build/
@rm -fr dist/
@rm -fr cover/
@rm -fr *.egg-info


Expand Down
55 changes: 55 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# coding: utf-8

from flask import Flask
from flask_weixin import Weixin

app = Flask(__name__)
app.secret_key = 'secret'
app.config['WEIXIN_TOKEN'] = 'B0e8alq5ZmMjcnG5gwwLRPW2'

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


jing_music = (
'http://cc.cdn.jing.fm/201310171130/19e715ce8223efd159559c15de175ab6/'
'2012/0428/11/AT/2012042811ATk.m4a'
)


@weixin('*')
def reply_all(**kwargs):
username = kwargs.get('sender')
sender = kwargs.get('receiver')
message_type = kwargs.get('type')
content = kwargs.get('content', message_type)

if content == 'music':
return weixin.reply(
username, type='music', sender=sender,
title='Weixin Music',
description='weixin description',
music_url=jing_music,
hq_music_url=jing_music,
)
elif content == 'news':
return weixin.reply(
username, type='news', sender=sender,
articles=[
{
'title': 'Weixin News',
'description': 'weixin description',
'picurl': '',
'url': 'http://lepture.com/',
}
]
)
else:
return weixin.reply(
username, sender=sender, content=content
)


if __name__ == '__main__':
# you need a proxy to serve it on 80
app.run()

0 comments on commit c71fe92

Please sign in to comment.