I haven't written a technical blog for a long time. because I have been learning knowledge recently and have not summed up anything worth sharing, I have been suspended. Recent work and DingTalk development have been handed over. The official website does not provide any Python SDK, so you can only write it on your own. Now I will share the "encryption and decryption signature" part that is relatively time-consuming, hoping to help some people. Encryption has not been written into a technical blog for a long time. because he has been learning knowledge recently and has not summed up anything worth sharing, he has been suspended. Recent work and DingTalk development have been handed over. The official website does not provide any Python SDK, so you can only write it on your own. Now I want to share the "encryption, decryption, and signature" section, which is relatively time-consuming.
For details about the encryption/decryption mechanism, refer to the official documentation.
To install this extension in your project, you can use:
pip install dingtalk_crypto
Install.
For instructions, refer to the following test code:
#-*-Coding: UTF-8-*-import jsonfrom dingtalk_crypto import DingTalkCrypto # This is the test data officially provided by DingTalk # @ see https://open-doc.dingtalk.com/doc2/detail.htm?treeId=175&articleId=104945&docType=1#s14 Encrypt_text = 'encrypt + encrypt + decrypt '\' + encrypt/decrypt '\'/encrypt + AGGanfwjXuQ9 + 0pzcy0w9scsi = 'crypto = DingTalkCrypto ('clerk', '123 ', 'suite4xxxxxxxxxxxxxxxx') signature = 'clerk' timestamp = '000000' nonce = 'nexhmp4r 'class TestCrypto: def test_decrypt (self): randstr, length, msg, suite_key = crypto. decrypt (encrypt_text) msg = json. loads (msg) assert msg ['eventtype'] = 'check _ create_suite_url 'assert msg ['Rand'] = 'lpidsnlf 'assert suite_key = 'suite4xxxxxxxxxxxxxx' def test_encode (self ): encrypt_msg = crypto. encrypt ('Hello World') randstr, length, msg, suite_key = crypto. decrypt (encrypt_msg) assert msg = 'Hello World' def 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
Finally, paste the source code address of the project and hope to have some exchanges.
The above is a detailed description of the Python DingTalk encryption/decryption tool. For more information, see other related articles in the first PHP community!