26 lines
773 B
Python
26 lines
773 B
Python
"""
|
|
企微加解密自检(无外网)。
|
|
|
|
运行:在 agent 目录 .venv 下 python -m agent.channel.wecom.selftest
|
|
需已配置 WECOM_CALLBACK_TOKEN / WECOM_ENCODING_AES_KEY / WECOM_CORP_ID。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from agent.channel.wecom.crypto import WeComCrypto
|
|
from agent.config import get_settings
|
|
|
|
|
|
def main() -> None:
|
|
s = get_settings()
|
|
c = WeComCrypto(s.wecom_callback_token, s.wecom_encoding_aes_key, s.wecom_corp_id)
|
|
plain = "<xml><FromUserName><![CDATA[Alice]]></FromUserName><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[hi]]></Content><MsgId>1</MsgId></xml>"
|
|
enc = c.encrypt(plain)
|
|
dec = c.decrypt(enc)
|
|
assert "Alice" in dec and "hi" in dec
|
|
print("crypto_ok")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|