当前位置:网站首页>Enterprise wechat H5_ Integrated message decryption class, message push get and post callback processing
Enterprise wechat H5_ Integrated message decryption class, message push get and post callback processing
2022-06-12 00:19:00 【gblfy】

List of articles
One 、 verification URL effectiveness
Official document :https://developer.work.weixin.qq.com/document/path/90238
1. Read the document
When you click “ preservation ” When submitting the above information , Enterprise wechat will send a verification message to the filled in URL, The request method is GET.
After the enterprise's receiving message server receives the authentication request , You need to respond correctly to pass URL verification 
2. Document analysis
You can know from the documentation , Let's apply the received message service period configuration of the management configuration url, Enterprise wechat will send a get The request to carry 4 Parameters (msg_signature、timestamp、nonce、echostr) To verify URL effectiveness 
3. Encryption and decryption scheme description
Click to enter Encryption and decryption scheme description 
4. Download encryption and decryption algorithm
Since the encryption and decryption algorithm is relatively complex , Enterprise wechat provides an algorithm library , So far c++/python/php/java/golang/c# Wait for the language version . Both provide decryption 、 encryption 、 verification URL Three interfaces , Enterprises can download according to their own needs , download Download address

5. case analysis
open Readme.txt
matters needing attention
1.com\qq\weixin\mp\aes The directory is the interface required by users to access enterprise wechat , among WXBizMsgCrypt.java The document provides WXBizMsgCrypt Class encapsulates three interfaces for users to access enterprise wechat , Other class files are used by users to realize encryption and decryption , Users don't have to care .sample.java The file provides an example of the use of the interface .
2.WXBizMsgCrypt Encapsulates the VerifyURL, DecryptMsg, EncryptMsg Three interfaces , Respectively used for developer verification callback url, Decryption of received user reply message and encryption process of developer reply message . Use method can refer to Sample.java file .
3. For the encryption and decryption protocol, please refer to the official document of enterprise wechat .
4. Please use jdk1.6 Version above . in the light of org.apache.commons.codec.binary.Base64, Need to import rack package commons-codec-1.9( or commons-codec-1.8 And so on ), We offer , Official download address :http://commons.apache.org/proper/commons-codec/download_codec.cgi
**** Please pay special attention ******
5. abnormal java.security.InvalidKeyException:illegal Key Size Solutions for :
Download... On the official website JCE Unrestricted permission policy file (JDK7 Download address :
http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html Decompress after downloading , You can see local_policy.jar and US_export_policy.jar as well as readme.txt. If installed JRE, Put two jar Files in %JRE_HOME%\lib\security Overwrite the original file in the directory , If installed JDK, Put two jar Files in %JDK_HOME%\jre\lib\security Overwrite the original file in the directory
from Readme.txt The contents of the document are analyzed as follows :
1.com\qq\weixin\mp\aes Some encryption and decryption tool classes are provided under the directory
2.WXBizMsgCrypt It is used for callback url, Decryption of received user reply message and encryption process of developer reply message .Sample.java The file is a case code
3.commons-codec-1.9 Dependence 
Two 、 Actual combat integration
2.1. Tool class copy
take com\qq\weixin\mp\aes Copy the tool classes under the directory to the project com.gblfy.qywxinner.qywxdecode Under the bag 
2.2. Depend on the introduction of
In the project pom.xml Introduce in the file commons-codec rely on 
2.3. Case study 1 Integrate
In the project com.gblfy.qywxinner.controller Under bag MessageController Class callback Method , take Sample.java Class 1 Copy the code , take sToken、sCorpID、sEncodingAESKey Replace the configuration information with your own 
2.4. Processing parameters
Because enterprise wechat will carry 4 Parameters (msg_signature、timestamp、nonce、echostr) Request our configuration verification url Valid address (http://4663588nl3.zicp.vip/message/callback), therefore , We need to start callback Method to receive the parameters from the enterprise wechat sVerifyMsgSig、sVerifyTimeStamp、sVerifyNonce、sVerifyEchoStr
It's written as shown in the picture 
2.5. Restart project
A little
2.6. verification URL effectiveness
then , Do the following , Save again 
2.7. verification
Click Save opportunity to request our configuration url Address , Enter us callback The methods of , Perform encryption and decryption operations , then , return .

3、 ... and 、 Message receiving and processing
3.1. Document reading
Receive the parameters and replies from the enterprise wechat
The request method is POST, Same address (http://4663588nl3.zicp.vip/message/callback)
3.2. Case study 2 Copy
In the project com.gblfy.qywxinner.controller Under bag MessageController Class callbackData Method , take Sample.java Class 2 Copy the code , take sToken、sCorpID、sEncodingAESKey Replace the configuration information with your own 
3.3. Processing parameters
Because enterprise wechat will carry 4 Parameters (msg_signature、timestamp、nonce) Request our configuration verification url Valid address (http://4663588nl3.zicp.vip/message/callback), therefore , We need to start callback Method to receive the parameters from the enterprise wechat sVerifyMsgSig, sReqTimeStamp, sReqNonce, sRespData, among sRespData It is our message body
It's written as shown in the picture 
3.4. Restart project
A little
3.5. Send a message

3.6. verification

3.7. Log monitoring
Console log 
Decrypt decrypt Messages pushed by enterprise wechat ->sMsg:<xml><ToUserName><![CDATA[wwea98220fdcd8a38d]]></ToUserName><FromUserName><![CDATA[ZeXin]]></FromUserName><CreateTime>1646043916</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[ Hello , Test enterprise wechat processing messages ]]></Content><MsgId>7069704788922636053</MsgId><AgentID>1000002</AgentID></xml>
Content: Hello , Test enterprise wechat processing messages
reply ->data:<xml><ToUserName><![CDATA[ZeXin]]></ToUserName><FromUserName><![CDATA[ZeXin]]></FromUserName><CreateTime>1646043916</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[this is a test]]></Content></xml>
3.8. Received a reply message

Four 、 The source code to share
4.1. Back end source code
Back end :https://gitee.com/gblfy/qywx-inner-java
4.2. Front end source code
front end :https://gitee.com/gblfy/qywx-vuejs
边栏推荐
- Construction environnementale 2
- [day 6 of JUC learning] concurrent calculator and thread random factor
- Do you want to take the postgraduate entrance examination? Will you be able to find a good job after graduate school?
- 多年测试菜鸟对黑盒测试的理解
- Mmdetection custom fetch detection result script and image_ demo. Py parsing
- Month selector disable data after the current month to include the current month
- "Failure" of the prospectus of Laowang: Laowang made its first dash for listing in Hong Kong, and the turnover rate continued to decline
- Experiment 6 constructor + copy construction
- 2022 Tibet's latest eight members (security officer) simulated test question bank and answers
- 将数组分成和相等的三个部分[问题分析]
猜你喜欢

Is the o2o platform worth doing in 2022

Graph and graph traversal

ironSource&nbsp; New functions are released, and developers can adjust advertising strategies in real time in the same session

Pass the command parameters for operating mongodb to Mongo in the shell

【juc学习之路第7天】ReentrantLock与ReentrantReadWriteLock

Wechat applet Chinese English conversion

chisel环境搭建(win10 + vscode)

The time selector style is disordered and the middle text is blocked

汛期化工和危险品企业如何加强防控重大安全风险

苹果手机wps文件如何发送到qq邮箱
随机推荐
Point cloud library PCL from introduction to mastery learning records Chapter 8
Experiment 7 class construction and static member function
No permission to mount SMB share prompt directory
苹果手机wps如何改字体大小
OpenMMLab:AI CV框架
wps表格怎么取消智能表格样式
Web keyboard input method application development guide (2) -- keyboard events
SF14 | supertrend "super trend" indicator magic change and upgrade (source code)
chisel环境搭建(win10 + vscode)
C language Niuke net string space substitution
[academic related] it is suggested to collect. Which behaviors are academic misconduct?
明德扬ADC系列开发板-Ad9653子板 多通道 高分辨率 高采样率
MySQL basic tutorial -- MySQL transaction and storage engine
What is bonded warehouse and what is the difference between them
DOM知识点总结
How to uninstall pscs6 in win10 system
挂载smb共享提示目录无权限
Wechat applet Chinese English conversion
Understanding of black box testing by novices after years of testing
WALLYS Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-WiFi 6E-Module-5G-high-power