How to use the wechatpy.enterprise.crypto.WeChatCrypto 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_crypto.py View on Github external
def test_check_signature_should_fail(self):
        from wechatpy.exceptions import InvalidSignatureException

        signature = 'dd6b9c95b495b3f7e2901bfbc76c664930ffdb96'
        timestamp = '1411443780'
        nonce = '437374424'
        echo_str = '4ByGGj+sVCYcvGeQYhaKIk1o0pQRNbRjxybjTGblXrBaXlTXeOo1+bXFXDQQb1o6co6Yh9Bv41n7hOchLF6p+Q=='  # NOQA

        crypto = WeChatCrypto(self.token, self.encoding_aes_key, self.corp_id)
        self.assertRaises(
            InvalidSignatureException,
            crypto.check_signature,
            signature, timestamp, nonce, echo_str
        )
github jxtech / wechatpy / tests / test_crypto.py View on Github external
<content></content>


1
1411525903
"""

        expected = """


1411525903

"""

        crypto = WeChatCrypto(self.token, self.encoding_aes_key, self.corp_id)
        encrypted = crypto.encrypt_message(reply, nonce, timestamp)

        _crypto.PrpCrypto = origin_crypto

        self.assertEqual(expected, encrypted)
github jxtech / wechatpy / tests / test_crypto.py View on Github external
def test_check_signature_should_ok(self):
        signature = 'dd6b9c95b495b3f7e2901bfbc76c664930ffdb96'
        timestamp = '1411443780'
        nonce = '437374425'
        echo_str = '4ByGGj+sVCYcvGeQYhaKIk1o0pQRNbRjxybjTGblXrBaXlTXeOo1+bXFXDQQb1o6co6Yh9Bv41n7hOchLF6p+Q=='  # NOQA

        crypto = WeChatCrypto(self.token, self.encoding_aes_key, self.corp_id)
        echo_str = crypto.check_signature(
            signature,
            timestamp,
            nonce,
            echo_str
        )
github jxtech / wechatpy / tests / test_crypto.py View on Github external
def test_decrypt_message(self):
        xml = """


"""

        signature = '74d92dfeb87ba7c714f89d98870ae5eb62dff26d'
        timestamp = '1411525903'
        nonce = '461056294'

        crypto = WeChatCrypto(self.token, self.encoding_aes_key, self.corp_id)
        msg = crypto.decrypt_message(xml, signature, timestamp, nonce)
        msg_dict = xmltodict.parse(msg)['xml']
        self.assertEqual('test', msg_dict['Content'])
        self.assertEqual('messense', msg_dict['FromUserName'])
github jxtech / wechatpy / tests / test_crypto.py View on Github external
def test_decrypt_binary_message(self):
        xml = b"""


"""

        signature = '74d92dfeb87ba7c714f89d98870ae5eb62dff26d'
        timestamp = '1411525903'
        nonce = '461056294'

        crypto = WeChatCrypto(self.token, self.encoding_aes_key, self.corp_id)
        msg = crypto.decrypt_message(xml, signature, timestamp, nonce)
        msg_dict = xmltodict.parse(msg)['xml']
        self.assertEqual('test', msg_dict['Content'])
        self.assertEqual('messense', msg_dict['FromUserName'])
github cloverstd / flask-wechatpy / flask_wechatpy / __init__.py View on Github external
def _enterprise_wechat_required(method, *args, **kwargs):
    from wechatpy.enterprise import parse_message
    from wechatpy.enterprise.crypto import WeChatCrypto
    from wechatpy.enterprise.exceptions import InvalidCorpIdException
    signature = request.args.get('msg_signature')
    timestamp = request.args.get('timestamp')
    nonce = request.args.get('nonce')

    if not current_app.config.get('WECHAT_TOKEN'):
        return abort(500, "Token is None")

    crypto = WeChatCrypto(
        current_app.config['WECHAT_TOKEN'],
        current_app['WECHAT_AES_KEY'],
        current_app.config['WECHAT_APPID']
    )
    if request.method == 'GET':
        echo_str = request.args.get('echostr')
        try:
            echo_str = crypto.check_signature(
                signature,
                timestamp,
                nonce,
                echo_str
            )
        except InvalidSignatureException:
            abort(403)
        return echo_str
github jxtech / wechatpy / wechatpy / enterprise / crypto.py View on Github external
def __init__(self, token, encoding_aes_key, corp_id):
        super(WeChatCrypto, self).__init__(token, encoding_aes_key, corp_id)
        self.corp_id = corp_id
github cloverstd / flask-wechatpy / flask_wechatpy / __init__.py View on Github external
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