From c42614978ff12013a1eabebd0289b27169a5784f Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期二, 06 五月 2025 17:25:56 +0800 Subject: [PATCH] 1、实现万功能token(0000-0000-1234-9876-5); 2、web端单独实现命令结果等待器,并相应修改相关部分; 3、web端实现透传命令; 4、修改一些不当注释; 5、优化一些代码。 --- 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