It is a long time did not write technical blog, cover because of recent learning knowledge, also did not sum up what is worth sharing content, so has been stopped pen so far. Recent work and nails have been developed, and the authorities have not provided any Python SDK, so they have to write them all themselves. I will now share the "encryption/decryption/signature" portion of the implementation of the relative cost of time, hoping to help some people.
The specific mechanism of encryption/decryption can refer to the official documentation.
To install this extension in your project, you can use: pip install dingtalk_crypto
install.
Using the method, you can refer to the following test code:
#-*-Coding:utf-8-*-import json from dingtalk_crypto import Dingtalkcrypto # This is the nail official test data # @see Https://open-doc. dingtalk.com/doc2/detail.htm?treeid=175&articleid=104945&doctype=1 Encrypt_text = ' 1a3nbxmcfwkcjvfoq7whjhb+ix3qhpsc9jbadzne1i03peok1laoqorz3+nlygnhwmwj3vdmg ' \ ' + Ozrhmeizi7gtrwvdubmfxjz8ej23jvya9vryej5as7xm/zpulx8neqis44w53h1qagnc3przm7zc ' \ '/ d6ibr0rguathb6zrhp8pyrfgnnos9phsbdhlegk+agganfwjxuq9+0pzcy0w9lq== ' crypto = Dingtalkcrypto (' 4g5j64qlyl3zvetqxz5jiocdr586fn2zvjpa8zls3ij ', ' 123456 ', ' suite4xxxxxxxxxxxxxxx ') signature = ' 5a65ceeef9aab2d149439 f82dc191dd6c5cbe2c0 ' timestamp = ' 1445827045067 ' nonce = ' nexhmp4r ' class Testcrypto:def Test_decrypt (self): Rand str, length, msg, Suite_key = Crypto.decrypt (encrypt_text) msg = json.loads (msg) assert msg[' eventtype '] = = ' Chec K_create_suite_url ' assert msg[' Random '] = = ' LPIDSNLF ' assert suite_key = ' suite4xxxxxxxxxxxxxxx ' def test_enc Ode (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, post the project's source address, hoping to have some communication.