dede 管理多个网站,网站开发课程培训,自媒体seo优化,湖北什么是网络营销又是很久没有写技术博客了#xff0c;盖因最近都在学习知识#xff0c;也没有总结出什么值得分享的内容#xff0c;所以一直停笔至今。最近的工作和钉钉的开发打上了交到#xff0c;官方并没有提供任何Python的SDK#xff0c;于是只能全部自己写。现在我将其中实现起来相对…又是很久没有写技术博客了盖因最近都在学习知识也没有总结出什么值得分享的内容所以一直停笔至今。最近的工作和钉钉的开发打上了交到官方并没有提供任何Python的SDK于是只能全部自己写。现在我将其中实现起来相对费时间的“加密/解密/签名”部分分享出来希望能帮助到一些人。加密/解密的具体机制可以参考 官方文档 。在你的项目中安装这个扩展可以使用: pip install dingtalk_crypto安装。使用方法可以参考下面的测试代码# -*- coding: utf-8 -*-import jsonfrom dingtalk_crypto import DingTalkCrypto# 这个是钉钉官方给的测试数据# see https://open-doc.dingtalk.com/doc2/detail.htm?treeId175articleId104945docType1#s14encrypt_text 1a3NBxmCFwkCJvfoQ7WhJHBiX3qHPsc9JbaDznE1i03peOk1LaOQoRz3nlyGNhwmwJ3vDMG \OzrHMeiZI7gTRWVdUBmfxjZ8Ej23JVYa9VrYeJ5as7XM/ZpulX8NEQis44w53h1qAgnC3PRzM7Zc \/D6Ibr0rgUathB6zRHP8PYrfgnNOS9PhSBdHlegKAGGanfwjXuQ90pZcy0w9lQcrypto DingTalkCrypto(4g5j64qlyl3zvetqxz5jiocdr586fn2zvjpa8zls3ij,123456,suite4xxxxxxxxxxxxxxx)signature 5a65ceeef9aab2d149439f82dc191dd6c5cbe2c0timestamp 1445827045067nonce nEXhMP4rclass TestCrypto:def test_decrypt(self):randstr, length, msg, suite_key crypto.decrypt(encrypt_text)msg json.loads(msg)assert msg[EventType] check_create_suite_urlassert msg[Random] LPIdSnlFassert suite_key suite4xxxxxxxxxxxxxxxdef test_encode(self):encrypt_msg crypto.encrypt(hello world)randstr, length, msg, suite_key crypto.decrypt(encrypt_msg)assert msg hello worlddef test_check_signature(self):assert crypto.check_signature(encrypt_text, timestamp, nonce, signature)def test_sign(self):msg crypto.encrypt(hello world)actual_sig, actual_time, actual_nonce crypto.sign(msg)assert True最后贴出项目的 源码地址 希望能一些交流。