# -*- coding: utf-8 -*- import os, sys reload(sys) sys.setdefaultencoding('utf-8') import unicodedata from flask import Flask from flask.ext.werobot import WeRoBot from werobot.client import Client app = Flask(__name__) robot = WeRoBot(app, token="waiter1109", rule='/test') mywxid = "wx088f6d071740acfc" mywxsecret = "524a1ebcc15b4e4f27c66f02f071c5ff" @robot.subscribe def echo(message): return '你好! 欢迎关注逸筠提琴!' @robot.unsubscribe def echo(message): return '舍不得跟你分开' import re
from flask import Flask, url_for from flask.ext.werobot import WeRoBot app = Flask(__name__) robot = WeRoBot() app.debug = True app.config.from_pyfile('app.cfg') @robot.handler def reply(message): return 'Hello!' robot.init_app(app) another_robot = WeRoBot(token='abcdefg', enable_session=True) @another_robot.handler def another_reply(message): return "Hey, that's another robot!" another_robot.init_app(app, endpoint='werobot_2', rule='/wechat/2') @app.route('/') def index():
def __init__(self, message): message.pop('type') self.type = message.pop('Event').lower() if self.type == 'click': self.key = message.pop('EventKey') elif self.type in ['subscribe', 'scan']: try: self.key = int(message.pop('EventKey', '')[8:] or 0) except: self.key = 0 elif self.type == 'location': self.latitude = float(message.pop('Latitude')) self.longitude = float(message.pop('Longitude')) self.precision = float(message.pop('Precision')) super(EventMessage, self).__init__(message) def scan(self, f): self.add_handler(f, type='scan') return f WeRoBot.message_types = [ 'subscribe', 'unsubscribe', 'click', 'view', 'text', 'image', 'link', 'location', 'voice', 'scan', ] WeRoBot.scan = scan patch_monkey() robot = WeRoBot()
app = Flask(__name__) app.config.from_object(config) app.debug = True lm = LoginManager() lm.init_app(app) lm.login_view = 'login' lm.login_message = unicode('请先登录', 'utf-8') #CsrfProtect(app) mail = Mail(app) db = SQLAlchemy(app) robot = WeRoBot(app, token=WEROBOT_TOKEN, enable_session=True) from mbp import views from mbp.Logic import wechatrobot #初始化管理 import mbp.manage @app.errorhandler(404) def internal_error(error): return render_template('404.html'), 404 @app.errorhandler(500) def internal_error(error):
from flask import Flask, url_for from flask.ext.werobot import WeRoBot app = Flask(__name__) robot = WeRoBot() app.debug = True app.config.from_pyfile('app.cfg') @robot.handler def reply(message): return 'Hello!' robot.init_app(app) another_robot = WeRoBot(token='abcdefg', enable_session=True) @another_robot.handler def another_reply(message): return "Hey, that's another robot!" another_robot.init_app(app, endpoint='werobot_2', rule='/wechat/2') @app.route('/') def index(): return 'First WeRoBot will handle WeChat requests at %s <br />' \