From a0a9fc7a58a39626a395d2760194641726e1cd35 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期五, 25 四月 2025 10:48:15 +0800
Subject: [PATCH] 1、微信小程序后端轮灌迟延时长改为可配置的; 2、微信小程序查询取水口接口实现修改,改为后端模糊查询;

---
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/HmacSha256.java |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/HmacSha256.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/HmacSha256.java
new file mode 100644
index 0000000..9f5e7c2
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/util/HmacSha256.java
@@ -0,0 +1,43 @@
+package com.dy.pipIrrWechat.util;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-07-15 10:19
+ * @LastEditTime 2024-07-15 10:19
+ * @Description
+ */
+public class HmacSha256 {
+    public static String getSignature(String secretKey, String data) throws NoSuchAlgorithmException, InvalidKeyException {
+        // 鍒涘缓瀵嗛挜瀵硅薄
+        byte[] keyBytes = secretKey.getBytes(StandardCharsets.UTF_8);
+        SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "HmacSHA256");
+
+        // 鍒涘缓Mac瀵硅薄骞跺垵濮嬪寲
+        Mac mac = Mac.getInstance("HmacSHA256");
+        mac.init(secretKeySpec);
+
+        // 灏嗗緟鍔犲瘑鐨勬暟鎹浆鎹负瀛楄妭鏁扮粍
+        byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
+
+        // 浣跨敤瀵嗛挜瀵规暟鎹繘琛屽姞瀵�
+        byte[] encryptedBytes = mac.doFinal(dataBytes);
+
+        // 灏嗗姞瀵嗗悗鐨勭粨鏋滆浆鎹负鍗佸叚杩涘埗瀛楃涓�
+        StringBuilder hexString = new StringBuilder();
+        for (byte b : encryptedBytes) {
+            String hex = Integer.toHexString(0xff & b);
+            if (hex.length() == 1) {
+                hexString.append('0');
+            }
+            hexString.append(hex);
+        }
+        String hmacSha256 = hexString.toString();
+        return hmacSha256;
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0