crypto.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from __future__ import absolute_import, unicode_literals
  2. from wechatpy.crypto import BasePrpCrypto, BaseWeChatCrypto
  3. from wechatpy.enterprise.exceptions import InvalidCorpIdException
  4. class PrpCrypto(BasePrpCrypto):
  5. def encrypt(self, text, corp_id):
  6. return self._encrypt(text, corp_id)
  7. def decrypt(self, text, corp_id):
  8. return self._decrypt(text, corp_id, InvalidCorpIdException)
  9. class WeChatCrypto(BaseWeChatCrypto):
  10. def __init__(self, token, encoding_aes_key, corp_id):
  11. super(WeChatCrypto, self).__init__(token, encoding_aes_key, corp_id)
  12. self.corp_id = corp_id
  13. def check_signature(self, signature, timestamp, nonce, echo_str):
  14. return self._check_signature(
  15. signature,
  16. timestamp,
  17. nonce,
  18. echo_str,
  19. PrpCrypto
  20. )
  21. def encrypt_message(self, msg, nonce, timestamp=None):
  22. return self._encrypt_message(
  23. msg,
  24. nonce,
  25. timestamp,
  26. PrpCrypto
  27. )
  28. def decrypt_message(self, msg, signature, timestamp, nonce):
  29. return self._decrypt_message(
  30. msg,
  31. signature,
  32. timestamp,
  33. nonce,
  34. PrpCrypto
  35. )