In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to achieve message encryption in the development of Wechat public platform. It is very detailed and has a certain reference value. Interested friends must finish reading it.
Encryption Settin
Enter the "developer Center" at the backend of the official account, and we can see the settings for Url interfacing:
Click "modify Settings" to go to the modification page:
There are three ways to encrypt:
Plaintext mode, that is, the original message format
Compatible mode, plaintext and ciphertext will coexist, and officially released products are not recommended (because they still contain plaintext and cannot achieve the effect of encryption)
Security mode, in which the message will be encrypted, and the developer's server can decrypt it through the official algorithm to get the original message in plaintext mode.
For all encrypted messages, the returned information also needs to be encrypted.
Processing encrypted information
Senparc.Weixin.MP has made automatic judgment on three types of messages, and the development process does not need to pay attention to any decryption and encryption process, but can still maintain the development process in "plaintext mode".
In the corresponding MessageHandler, we can know the current encryption status through some parameters:
MessageHandler.UsingEcryptMessage: whether encrypted information is used (including compatibility mode and security mode)
MessageHandler.UsingCompatibilityModelEcryptMessage: whether compatibility mode is used to encrypt information
Through the combination of the above two attributes, we can know which encryption mode the current account is using (of course, in most cases, developers no longer need to care).
In order to better track information, MessageHandler added the attribute FinalResponseDocument:
MessageHandler.ResponseDocument: response data XML object for plaintext structure
MessageHandler.FinalResponseDocument: the XML object that will eventually be returned to the server, which will be the same as ResponseDocument without encryption, otherwise it will be encrypted automatically
Encryption principle
Encryption algorithms (including sample downloads in several languages) can be found in the official help documentation: http://mp.weixin.qq.com/wiki/index.php?title=%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88
What I want to explain here is EncodingAESKey, and the official explanation is a bit circuitous. In fact, EncodingAESKey is an Base64 encoding of AESKey, while AESKey is a random string of length 32 (selected from Amurz ZJ 0-9). Since the Base64 encoding length of 32 characters is fixed 44 (the last character is =), after the = is removed, the final 43-character EncodingAESKey is generated. EncodingAESKey is used in the process of message encryption and decryption and requires strict secrecy.
The following is a piece of code for C # to generate EncodingAESKey:
Protected string CreateEncodingAESKey () {string aesKey = GetRadomStr (32); / / get the random string var encodingAesKey = Convert.ToBase64String (Encoding.UTF8.GetBytes (aesKey), Base64FormattingOptions.None); return encodingAesKey.Substring (0, encodingAesKey.Length-1) } these are all the contents of the article "how to encrypt messages in the Development of Wechat Public platform". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.