Пример #1
0
    def processOrder(self, msg):
        '''
        处理指令
        '''
        replyMsg = Msg()

        humidifier = Humidifier.Humidifier()
        content = msg.content
        replyMsg.content = content

        if ('温度' in content):
            replyMsg.content = Data().getT()

        if ('湿度' in content):
            replyMsg.content = Data().getH()

        if ('开' in content):
            humidifier.open()
            replyMsg.content = '加湿器已打开'

        if ('关' in content):
            humidifier.close()
            replyMsg.content = '加湿器已关闭'

        replyMsg.fromUserName = msg.toUserName
        replyMsg.toUserName = msg.fromUserName

        return replyMsg
Пример #2
0
    def parseUserOrder(self, xmlStr):
        '''
        解析用户消息
        '''
        xml = etree.fromstring(xmlStr)

        msg = Msg()

        msg.msgType = xml.find("MsgType").text
        msg.fromUserName = xml.find("FromUserName").text
        msg.toUserName = xml.find("ToUserName").text
        msg.createTime = xml.find("CreateTime").text

        if (msg.msgType == 'text'):
            msg.content = xml.find("Content").text

        if (msg.msgType == 'voice'):
            msg.content = xml.find("Recognition").text

        logger.info(msg.content)

        return msg