From 203223860baa19deb6860eb2ba3181910d662980 Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期四, 17 四月 2025 14:22:59 +0800 Subject: [PATCH] 1. 轮灌组被终止时灌溉时长为实际数值。2. 计划历史表按照创建时间倒排序。3. 发布计划时判断是否同项目下未完成计划,是否其他项目下使用了本计划的轮灌组且计划未完成。4. 根据计划ID获取计划最新状态。 --- pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/HmacSha256.java | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/HmacSha256.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/HmacSha256.java new file mode 100644 index 0000000..176dd63 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/util/HmacSha256.java @@ -0,0 +1,43 @@ +package com.dy.pipIrrSell.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-03-06 11:47 + * @LastEditTime 2024-03-06 11:47 + * @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