def weixin():
    web_chat = WebChat('1234', 'wx74cda484a2ba4fc2',
                       '613db0445596a3d5dd39b7f418979c1f')

    if request.method == "GET":
        if web_chat.validate(
                **parse_request(request.args, ("timestamp", "nonce",
                                               "signature"))):
            print make_response(request.args.get("echostr"))
            return make_response(request.args.get("echostr"))
        raise LookupError

    if request.method == "POST":
        # 这里需要验证 #todo
        xml_recv = ET.fromstring(request.data)
        MsgType = xml_recv.find("MsgType").text

        if MsgType == "event":
            return response_event(xml_recv, web_chat, request)
        if MsgType == "text":
            return response_text(xml_recv, web_chat)
        if MsgType == 'voice':
            return response_voice(xml_recv, web_chat)
        if MsgType == 'location':
            return response_location(xml_recv, web_chat)
def weixin():
    web_chat = WebChat('1234','wx74cda484a2ba4fc2','613db0445596a3d5dd39b7f418979c1f')


    if request.method == "GET":
        if web_chat.validate(**parse_request(request.args, ("timestamp", "nonce", "signature"))):
            print make_response(request.args.get("echostr"))
            return make_response(request.args.get("echostr"))
        raise LookupError

    if request.method == "POST":
        # 这里需要验证 #todo
        xml_recv = ET.fromstring(request.data)
        MsgType = xml_recv.find("MsgType").text

        if MsgType == "event":
            return response_event(xml_recv, web_chat, request)
        if MsgType == "text":
            return response_text(xml_recv, web_chat)
        if MsgType == 'voice':
            return response_voice(xml_recv, web_chat)
        if MsgType == 'location':
            return response_location(xml_recv, web_chat)
# coding: utf-8

import sys
from repast.weixin.webchat import WebChat


reload(sys)
sys.setdefaultencoding('UTF-8')

appid = 'wx74cda484a2ba4fc2'
secret = '613db0445596a3d5dd39b7f418979c1f'

webChat = WebChat('1234',appid,secret)
menu = """
{
   "button": [
       {
            "type":"CLICK",
           "name":"主页",
           "key":"home"
       },
       {
           "type":"CLICK",
           "name": "进度",
           "key": "schedule"
       },
       {
           "type": "CLICK",
           "name": "我的",
           "key": "my"
       }
from repast.services.queue_setting_service import get_schedule_by_user_id


def loop_message(openid, web_chat, content):
    user_service = UserService()
    user = user_service.get_user_by_openid(openid)
    schedule = get_schedule_by_user_id(user.id)
    if schedule:
        web_chat.send_text_message(openid, content)


def loop_time(web_chat):
    args_time = get_date_time_str()
    queue = Queue.query.filter(Queue.queue_time.like(args_time),
                               Queue.user_id != '', Queue.status == 1).all()
    if queue:
        for q in queue:
            num = q.now_queue_number - 1
            con = "You have "
            content = con + str(num)
            user = User.query.filter(User.id == q.user_id).first()
            loop_message(user.openid, web_chat, content)


if __name__ == '__main__':
    web_chat = WebChat('1234', 'wx55970915710ceae8',
                       '0a9fcd79087745628d8eb5dd5fb9c418')
    while True:
        time.sleep(180)
        loop_time(web_chat)
# coding: utf-8

import sys
from repast.weixin.webchat import WebChat

reload(sys)
sys.setdefaultencoding('UTF-8')

appid = 'wx74cda484a2ba4fc2'
secret = '613db0445596a3d5dd39b7f418979c1f'

webChat = WebChat('1234', appid, secret)
menu = """
{
   "button": [
       {
            "type":"CLICK",
           "name":"主页",
           "key":"home"
       },
       {
           "type":"CLICK",
           "name": "进度",
           "key": "schedule"
       },
       {
           "type": "CLICK",
           "name": "我的",
           "key": "my"
       }
       ]