|
@@ -1,8 +1,10 @@
|
|
|
package com.hys.app.controller.erp.use;
|
|
|
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.dom4j.Document;
|
|
|
+import org.dom4j.DocumentHelper;
|
|
|
+import org.dom4j.Element;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
import java.security.MessageDigest;
|
|
|
import java.util.Arrays;
|
|
|
|
|
@@ -36,6 +38,36 @@ public class WeixinController {
|
|
|
return echostr;
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/receive_ticket")
|
|
|
+ public String receiveComponentVerifyTicket(@RequestBody String requestBody,
|
|
|
+ @RequestParam("msg_signature") String msgSignature,
|
|
|
+ @RequestParam("timestamp") String timestamp,
|
|
|
+ @RequestParam("nonce") String nonce) {
|
|
|
+ try {
|
|
|
+ // 1. 验证消息的真实性
|
|
|
+ if (!verifySignature(msgSignature, timestamp, nonce, requestBody)) {
|
|
|
+ return "fail";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 解密消息
|
|
|
+ String decryptedMsg = decryptMsg(requestBody);
|
|
|
+
|
|
|
+ // 3. 解析 XML
|
|
|
+ Document document = DocumentHelper.parseText(decryptedMsg);
|
|
|
+ Element root = document.getRootElement();
|
|
|
+ String componentVerifyTicket = root.elementText("ComponentVerifyTicket");
|
|
|
+
|
|
|
+ // 4. 存储 ticket
|
|
|
+ saveComponentVerifyTicket(componentVerifyTicket);
|
|
|
+
|
|
|
+ // 5. 返回成功响应
|
|
|
+ return "success";
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "fail";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private String sha1(String data) {
|
|
|
try {
|
|
|
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
|
@@ -50,4 +82,20 @@ public class WeixinController {
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public boolean verifySignature(String msgSignature, String timestamp, String nonce, String requestBody) {
|
|
|
+ // 实现签名验证逻辑
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String decryptMsg(String requestBody) {
|
|
|
+ // 实现消息解密逻辑
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveComponentVerifyTicket(String ticket) {
|
|
|
+ // 实现存储 ticket 的逻辑
|
|
|
+ }
|
|
|
}
|