示例#1
0
def text_handler(content, userid):
    resp = content
    if "survey" == content:
        userinfo = wechat.get_user_info(userid)
        question = generate_question(userinfo, "周末约吗?", "周五晚上去打麻将吗?")
        q = {}
        q["title"] = "周末约吗?"
        q["description"] = "周五晚上去打麻将吗?"
        q["url"] = get_question_url(wechat.conf.appid, question.id)
        return wechat.response_news([q])
    elif "test2" == content:
        userinfo = wechat.get_user_info(userid)
        question = generate_question(userinfo, "周末约吗?", "周六晚上去打麻将吗?")
        q = {}
        q["title"] = "周末约吗?"
        q["description"] = "周六晚上去打麻将吗?"
        q["url"] = get_question_info_url(wechat.conf.appid, question.id)
        return wechat.response_news([q])
    elif "test" == content:
        articles = [
            {"title": u"第一条新闻标题", "description": u"第一条新闻描述,这条新闻没有预览图", "url": u"http://www.baidu.com/"},
            {
                "title": u"第二条新闻标题, 这条新闻无描述",
                "picurl": u"http://doraemonext.oss-cn-hangzhou.aliyuncs.com/test/wechat-test.jpg",
                "url": u"http://www.github.com/",
            },
            {
                "title": u"第三条新闻标题",
                "description": u"第三条新闻描述",
                "picurl": u"http://doraemonext.oss-cn-hangzhou.aliyuncs.com/test/wechat-test.jpg",
                "url": u"http://www.v2ex.com/",
            },
        ]
        return wechat.response_news(articles)
    return wechat.response_text(resp)
示例#2
0
def retrieve_weuser(openid):
    userinfo = wechat.get_user_info(openid)
    logger.debug(userinfo)
    query = Query(WeUsers)
    query.equal_to("openid", userinfo.get("openid"))
    wuser = query.find()
    logger.debug(wuser)
    if len(wuser) <= 0:
        wuser = WeUsers()
        wuser.openid = userinfo.get("openid")
        wuser.city = userinfo.get("city")
        wuser.nickname = userinfo.get("nickname")
        wuser.headimgurl = userinfo.get("headimgurl")
        wuser.province = userinfo.get("province")
        wuser.sex = userinfo.get("sex")
        wuser.unionid = userinfo.get("unionid")
        wuser.save()
        return wuser
    else:
        wuser = wuser[0]
        logger.debug("%s had already been subscribed", userinfo.get("nickname"))
        return wuser