How to use the wechatpy.enterprise.parse_message function in wechatpy

To help you get started, we’ve selected a few wechatpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jxtech / wechatpy / tests / test_enterprise_parser.py View on Github external
def test_parse_click_event(self):
        xml = """
        
        
        123456789
        
        
        
        1
        """

        msg = parse_message(xml)

        self.assertEqual('event', msg.type)
        self.assertEqual('click', msg.event)
        self.assertEqual('EVENTKEY', msg.key)
github jxtech / wechatpy / tests / test_enterprise_parser.py View on Github external
def test_parse_video_message(self):
        xml = """
        
        
        1357290913
        
        
        
        1234567890123456
        1
        """

        msg = parse_message(xml)
        self.assertEqual('video', msg.type)
github jxtech / wechatpy / tests / test_enterprise_parser.py View on Github external
def test_parse_voice_message(self):
        xml = """
        
        
        1357290913
        
        
        
        1234567890123456
        1
        """

        msg = parse_message(xml)
        self.assertEqual('voice', msg.type)
github jxtech / wechatpy / tests / test_enterprise_parser.py View on Github external
def test_parse_view_event(self):
        xml = """
        
        
        123456789
        
        
        
        1
        """

        msg = parse_message(xml)

        self.assertEqual('event', msg.type)
        self.assertEqual('view', msg.event)
        self.assertEqual('www.qq.com', msg.url)
github jxtech / wechatpy / tests / test_enterprise_parser.py View on Github external
def test_parse_location_event(self):
        xml = """
        
        
        123456789
        
        
        23.137466
        113.352425
        119.385040
        1
        """

        msg = parse_message(xml)

        self.assertEqual('event', msg.type)
        self.assertEqual('location', msg.event)
        self.assertEqual(23.137466, msg.latitude)
        self.assertEqual(113.352425, msg.longitude)
        self.assertEqual(119.385040, msg.precision)
github jxtech / wechatpy / tests / test_enterprise_parser.py View on Github external
def test_parse_location_message(self):
        xml = """
        
        
        1351776360
        
        23.134521
        113.358803
        20
        <label></label>
        1234567890123456
        1
        """

        msg = parse_message(xml)
        self.assertEqual('location', msg.type)
github jxtech / wechatpy / tests / test_enterprise_parser.py View on Github external
def test_parse_subscribe_event(self):
        xml = """
        
        
        123456789
        
        
        1
        """

        msg = parse_message(xml)

        self.assertEqual('event', msg.type)
        self.assertEqual('subscribe', msg.event)
github jxtech / wechatpy / tests / test_enterprise_parser.py View on Github external
def test_parse_text_message(self):
        xml = """
        
        
         1348831860
        
        <content></content>
        1234567890123456
        1
        """

        msg = parse_message(xml)
        self.assertEqual('text', msg.type)
        self.assertEqual(1, msg.agent)
github cloverstd / flask-wechatpy / flask_wechatpy / __init__.py View on Github external
)
        except InvalidSignatureException:
            abort(403)
        return echo_str

    try:
        msg = crypto.decrypt_message(
            request.data,
            signature,
            timestamp,
            nonce,
        )
    except (InvalidSignatureException, InvalidCorpIdException):
        return abort(403)
    else:
        request.wechat_msg = parse_message(msg)

    res = method(*args, **kwargs)
    xml = ''

    if isinstance(res, BaseReply):
        xml = res.render()

    crypto = WeChatCrypto(
        current_app.config['WECHAT_TOKEN'],
        current_app.config['WECHAT_AES_KEY'],
        current_app.config['WECHAT_APPID']
    )
    xml = crypto.encrypt_message(xml, nonce, timestamp)

    return xml
github jxtech / wechatpy / examples / echo-enterprise / app.py View on Github external
echo_str
            )
        except InvalidSignatureException:
            abort(403)
        return echo_str
    else:
        try:
            msg = crypto.decrypt_message(
                request.data,
                signature,
                timestamp,
                nonce
            )
        except (InvalidSignatureException, InvalidCorpIdException):
            abort(403)
        msg = parse_message(msg)
        if msg.type == 'text':
            reply = create_reply(msg.content, msg).render()
        else:
            reply = create_reply('Can not handle this for now', msg).render()
        res = crypto.encrypt_message(reply, nonce, timestamp)
        return res