当前位置:网站首页>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
边栏推荐
- UVM: transaction level modeling (TLM) 1.0 communication standard
- gin解决跨域问题
- Creating and running JMeter performance test scenarios
- 【juc学习之路第6天】并发计算器与线程随机因子
- Motianlun domestic database salon | Xu Li: Alibaba cloud's native lindorm TSDB database drives the upgrading of industrial it & ot hyper integrated digital system
- Experiment 6 constructor + copy construction
- The time selector style is disordered and the middle text is blocked
- Industrial control system ICs
- 汛期化工和危险品企业如何加强防控重大安全风险
- wps表格怎么取消智能表格样式
猜你喜欢

时间选择器样式错乱 中间文字被遮挡

Experiment 7 class construction and static member function

愉快无负担的跨进程通信方式
![[pat (basic level) practice] - [simple simulation] 1076 WiFi password](/img/e4/82bdc74dcaa9f397c81135da0c0097.jpg)
[pat (basic level) practice] - [simple simulation] 1076 WiFi password

Pycharm file name taboo

Graph and graph traversal

组态王如何利用无线Host-Link通信模块远程采集PLC数据?

Binary sort tree

IP编址概述

The road of global evolution of vivo global mall -- multilingual solution
随机推荐
[flume] notes
IP addressing overview
What is bonded warehouse and what is the difference between them
How many steps does it take for C language to become Fibonacci number
DPT-FSNET: DUAL-PATH TRANSFORMER BASED FULL-BAND AND SUB-BAND FUSION NETWORK FOR SPEECH ENHANCEMENT
Water for a while
Construction environnementale 2
Teach you to play with SSM framework
Summary of DOM knowledge points
Pycharm file name taboo
Pre resolution and scope
R language spline curve piecewise linear regression model piecewise regression estimation of individual stock beta value analysis of yield data
Meet o & M (I) common questions for O & M interview
2022 618笔记本选购指北
Pleasant and burden free cross process communication
What are the software development processes of the visitor push mall?
WPS标题段前间距设置无效解决方案
苹果手机wps如何改字体大小
NFS quotas:Cannot register service: RPC: Authentication error
win10文件夹状态红叉表示的是什么