Example #1
0
    def post(self):
        if ('signature' not in self.request.arguments or
           'timestamp' not in self.request.arguments or
           'nonce' not in self.request.arguments): 
            return

        # check signature
        signature = self.get_argument('signature')
        timestamp = self.get_argument('timestamp')
        nonce = self.get_argument('nonce')
        if not interface_logic.check_signature(signature, timestamp, nonce, config.OA_TOKEN):
            MyLogger().getlogger().critical('Ileggal intrution!')
            return

        # parse msg
        msg = self.request.body
        MyLogger().getlogger().info('Recv msg: ' + msg)
        msgdict = msg_helper.parse_input_msg(msg)

        # check if send to the right oa
        to_user_name = msg_helper.get_value_by_key(msgdict, 'ToUserName')
        if to_user_name != config.OA_USERNAME:
            MyLogger().getlogger().critical('Send to the wrong official account!')
            return

        # process msg
        reply_msg = interface_logic.process_msg(msgdict)
        if reply_msg != None:
            MyLogger().getlogger().info('Reply msg: ' + reply_msg)
            self.write(reply_msg)
            return
Example #2
0
    def get(self):
        MyLogger().getlogger().critical('Ileggal intrution!')
        if ('signature' not in self.request.arguments or
           'timestamp' not in self.request.arguments or
           'nonce' not in self.request.arguments or
           'echostr' not in self.request.arguments):
            return

        # check signature
        signature = self.get_argument('signature')
        timestamp = self.get_argument('timestamp')
        nonce = self.get_argument('nonce')
        echostr = self.get_argument('echostr')
        if not interface_logic.check_signature(signature, timestamp, nonce, config.OA_TOKEN):
            MyLogger().getlogger().critical('Ileggal intrution!')
            return

        self.write(echostr)