From 7ec3683c8e41460f4bb0bd3a6677198742313e2b Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期二, 02 六月 2026 14:34:57 +0800
Subject: [PATCH] 新增智能电表、空调管理
---
server/visits/dmvisit_admin/src/main/java/com/doumee/device/ElectronicNotifyController.java | 81 +++++++++++-----------------------------
1 files changed, 22 insertions(+), 59 deletions(-)
diff --git a/server/visits/dmvisit_admin/src/main/java/com/doumee/device/ElectronicNotifyController.java b/server/visits/dmvisit_admin/src/main/java/com/doumee/device/ElectronicNotifyController.java
index 68fe16b..9e104b4 100644
--- a/server/visits/dmvisit_admin/src/main/java/com/doumee/device/ElectronicNotifyController.java
+++ b/server/visits/dmvisit_admin/src/main/java/com/doumee/device/ElectronicNotifyController.java
@@ -1,72 +1,35 @@
package com.doumee.device;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
+import com.doumee.core.annotation.trace.Trace;
+import com.doumee.service.business.YwElectricalBizService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.util.*;
-
+@Trace(exclude = true)
@RestController
@RequestMapping("/electronic")
+@Slf4j
public class ElectronicNotifyController {
- @RequestMapping("/notify")
- public String notify(String response_content, String timestamp, String sign) {
- System.out.println("timestamp: " + timestamp);
- System.out.println("response_content: " + response_content);
- System.out.println("sign: " + sign);
- // 楠岀
- if(!checkSign(response_content, timestamp, sign)) {
- System.out.println("sign check failed");
- return "sign check failed";
- }
- System.out.println("sign check success");
- List<Map<String, Object>> responseContent= new ArrayList<>();
- JSONArray contentArray = JSON.parseArray(response_content);
- for(int i = 0; i < contentArray.size(); ++i) {
- HashMap<String, Object> contentMap = new HashMap<>();
- JSONObject contentObject = contentArray.getJSONObject(i);
- Set<String> keySet = contentObject.keySet();
- for(String key: keySet) {
- contentMap.put(key, contentObject.getObject(key, Object.class));
- }
- responseContent.add(contentMap);
- }
- System.out.println("鎺ユ敹寮傛閫氱煡鏁版嵁锛�" + responseContent);
- return "SUCCESS";
- }
+ @Autowired
+ private YwElectricalBizService ywElectricalBizService;
- private boolean checkSign(String response_content, String timestamp, String sign) {
- // 闅忔満瀛楃涓� 鍚庡彴鑾峰彇
- String nonce = "XOfX547SeCIlhufeeBBwgZIN";
- String buf = response_content + timestamp + nonce;
- String encode = getMD5(buf);
- return encode.equals(sign);
- }
- // md5鍔犲瘑
- private String getMD5(String password) {
- MessageDigest md5 = null;
- try {
- md5 = MessageDigest.getInstance("MD5");
- } catch (Exception e) {
- throw new RuntimeException(e);
+ @PostMapping(value = "/electricalNotify", produces = MediaType.TEXT_PLAIN_VALUE)
+ public ResponseEntity<String> electricalNotify(
+ @RequestParam("response_content") String responseContent,
+ @RequestParam("timestamp") String timestamp,
+ @RequestParam("sign") String sign) {
+ boolean ok = ywElectricalBizService.handleElectricalNotify(responseContent, timestamp, sign);
+ if (!ok) {
+ return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("FAIL");
}
- byte[] byteArray = password.getBytes(StandardCharsets.UTF_8);
-
- byte[] md5Bytes = md5.digest(byteArray);
- StringBuilder hexValue = new StringBuilder();
- for (byte md5Byte : md5Bytes) {
- int val = ((int) md5Byte) & 0xff;
- if (val < 16) {
- hexValue.append("0");
- }
-
- hexValue.append(Integer.toHexString(val));
- }
- return hexValue.toString();
+ return ResponseEntity.ok("SUCCESS");
}
}
--
Gitblit v1.9.3