def setUp(self): app = self.create_app() self.client = app.test_client() weixin = Weixin(app) app.add_url_rule('/', view_func=weixin.view_func) self.weixin = weixin self.app = app self.setup_weixin()
# -*- coding: utf-8 -*- from flask import Flask from flask_weixin import Weixin app = Flask(__name__) app.secret_key = 'secret' app.config['WEIXIN_TOKEN'] = 'nevertellyou' 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) eventType = kwargs.get('event', '') cmd = '' for (key, value) in kwargs.items(): cmd = cmd + '\nkey: ' + key cmd = cmd + '\nvalue:' + str(value)
# -*- coding: utf-8 -*- import requests from flask import Flask from flask_weixin import Weixin from caiyun import settings from caiyun.utils import caiyun_reply app = Flask(__name__) app.config.from_object(settings) weixin = Weixin() weixin.init_app(app) app.add_url_rule('/', view_func=weixin.view_func) CAIYUN_API = app.config['CAIYUN_API'] CAIYUN_TOKEN = app.config['CAIYUN_TOKEN'] @weixin.register('*') def reply(**kwargs): username = kwargs.get('sender') sender = kwargs.get('receiver') content = kwargs.get('content') type = kwargs.get('type') if type == 'location': x = kwargs.get('location_x') y = kwargs.get('location_y') url = CAIYUN_API.format(latitude=x, longitude=y, format='json',