Exemple #1
0
 def POST(self):
     str_xml = web.data()  #获得post来的数据
     xml = etree.fromstring(str_xml)  #进行XML解析
     msgType = xml.xpath("MsgType")[0].text  #获得用户所输入的内容
     if msgType == "text":
         content = xml.xpath("Content")[0].text
     else:
         pass
     fromUser = xml.xpath("FromUserName")[0].text
     toUser = xml.xpath("ToUserName")[0].text
     db = Mysql._create_db()
     results = list(db.select('test'))
     count = int(results[0]["age"])
     count += 1
     num_updated = db.update('test', where="id > 10", age=str(count))
     if msgType == "text":
         msg = Antique.Menu(db, content, fromUser)
         return self.render.reply_text(fromUser, toUser, int(time.time()),
                                       u"第" + str(count) + u"次调用:\n" + msg)
     else:
         return self.render.reply_text(
             fromUser, toUser, int(time.time()),
             u"第" + str(count) + u"次调用:\n" + u"本助手目前只能识别文本消息,请重新输入命令\n")
Exemple #2
0
    def POST(self):
        str_xml = web.data()  #获得post来的数据
        xml = etree.fromstring(str_xml)  #进行XML解析
        msgType = xml.xpath("MsgType")[0].text  #获得用户所输入的内容
        if msgType == "text":
            content = xml.xpath("Content")[0].text
        else:
            pass
        fromUser = xml.xpath("FromUserName")[0].text
        toUser = xml.xpath("ToUserName")[0].text
        db = Mysql._create_db()

        if msgType == 'event':
            mscontent = xml.find("Event").text
            if mscontent == "subscribe":
                replayText = u'''感谢您关注古董局中局桌游!试试菜单栏就知道怎么愉快的玩耍啦。
使用“刷新”按钮可以查看当局游戏最新信息以及操作提示。'''
                return self.render.reply_text(fromUser, toUser,
                                              int(time.time()), replayText)

        #微信菜单管理
            cdcontent = xml.find("Event").text
            if cdcontent == "CLICK":
                keycontent = xml.find("EventKey").text
                if keycontent == u'盒闪淘宝':
                    replayText = u'【盒中闪电】,复制这条信息¥XKUE0VIbWwx¥后打开手机淘宝'
                    return self.render.reply_text(fromUser, toUser,
                                                  int(time.time()), replayText)
                if keycontent == u'开始游戏':
                    msg = Antique.Menu(db, "!", fromUser, 3)
                    return self.render.reply_text(fromUser, toUser,
                                                  int(time.time()), u"" + msg)
                if keycontent == u'退出游戏':
                    msg = Antique.Menu(db, "!", fromUser, 4)
                    return self.render.reply_text(fromUser, toUser,
                                                  int(time.time()), u"" + msg)
                if keycontent == u'刷新信息':
                    msg = Antique.Menu(db, "老齐真帅", fromUser, 0)
                    return self.render.reply_text(fromUser, toUser,
                                                  int(time.time()), u"" + msg)
                if keycontent == u'历史信息':
                    msg = Antique.Menu(db, ",", fromUser, 2)
                    return self.render.reply_text(fromUser, toUser,
                                                  int(time.time()), u"" + msg)
                if keycontent == u'帮助信息':
                    msg = Antique.Menu(db, "?", fromUser, 1)
                    return self.render.reply_text(fromUser, toUser,
                                                  int(time.time()), u"" + msg)
                if keycontent == u'加入我们':
                    replayText = u'''《古董局中局》桌游玩家QQ群:596772185
《古董局中局》桌游玩家微信群已经超过100人,请联系客服微信:18982287779 拉你进去哦'''
                    return self.render.reply_text(fromUser, toUser,
                                                  int(time.time()), replayText)
                if keycontent == u'客服':
                    replayText = u'''《古董局中局》微信客服号:18982287779
《古董局中局》桌游客服QQ号:2943517039'''
                    return self.render.reply_text(fromUser, toUser,
                                                  int(time.time()), replayText)

        if msgType == "text":
            msg = Antique.Menu(db, content, fromUser, 0)
            return self.render.reply_text(fromUser, toUser, int(time.time()),
                                          u"" + msg)
        else:
            return self.render.reply_text(fromUser, toUser, int(time.time()),
                                          u"" + u"本助手目前只能识别文本消息,请重新输入命令\n")