当前位置:网站首页>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

 Insert picture description here

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
 Insert picture description here

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
 Insert picture description here

3. Encryption and decryption scheme description

Click to enter Encryption and decryption scheme description
 Insert picture description here

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

 Insert picture description here

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
 Insert picture description here

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
 Insert picture description here

2.2. Depend on the introduction of

In the project pom.xml Introduce in the file commons-codec rely on
 Insert picture description here

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
 Insert picture description here

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
 Insert picture description here

2.5. Restart project

A little

2.6. verification URL effectiveness

then , Do the following , Save again
 Insert picture description here

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 .
 Insert picture description here
 Insert picture description here

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)
 Insert picture description here

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
 Insert picture description here

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
 Insert picture description here

3.4. Restart project

A little

3.5. Send a message

 Insert picture description here

3.6. verification

 Insert picture description here

3.7. Log monitoring

Console log
 Insert picture description here

 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

 Insert picture description here

Four 、 The source code to share
4.1. Back end source code

Back end :https://gitee.com/gblfy/qywx-inner-java
 Insert picture description here

4.2. Front end source code

front end :https://gitee.com/gblfy/qywx-vuejs
 Insert picture description here

原网站

版权声明
本文为[gblfy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011516525948.html