From 9eed388bf3c07dc0ea24fb0637b4964c8e387437 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 22 Dec 2025 16:45:43 +0800
Subject: [PATCH] fix(symbols): 修复K线数据获取逻辑
---
src/main/java/com/xcong/excoin/modules/newPrice/utils/SignUtils.java | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/newPrice/utils/SignUtils.java b/src/main/java/com/xcong/excoin/modules/newPrice/utils/SignUtils.java
new file mode 100644
index 0000000..9d5da67
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/newPrice/utils/SignUtils.java
@@ -0,0 +1,55 @@
+package com.xcong.excoin.modules.newPrice.utils;
+
+import lombok.extern.slf4j.Slf4j;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.util.Base64;
+
+
+@Slf4j
+public class SignUtils {
+
+ public static String signRest(String secretKey, String timestamp, String method, String path, String body) {
+ String str = String.format("%s%s%s%s",
+ timestamp, // timestamp
+ method, // method GET/POST
+ path, // requestPath
+ body // body
+ );
+ try {
+ return Base64.getEncoder().encodeToString(hmacSHA256(secretKey.getBytes(), str.getBytes()));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+
+ /**
+ * HmacSHA256算法,返回的结果始终是32位
+ *
+ * @param key 加密的键,可以是任何数据
+ * @param content 待加密的内容
+ * @return 加密后的内容
+ * @throws Exception ex
+ */
+ public static byte[] hmacSHA256(byte[] key, byte[] content) throws Exception {
+ Mac hmacSha256 = Mac.getInstance("HmacSHA256");
+ hmacSha256.init(new SecretKeySpec(key, 0, key.length, "HmacSHA256"));
+ return hmacSha256.doFinal(content);
+ }
+
+ public static String signWebsocket(String timestamp, String secretKey) {
+ String str = String.format("%s%s%s",
+ timestamp,
+ "GET",
+ "/users/self/verify");
+ try {
+ return Base64.getEncoder().encodeToString(hmacSHA256(secretKey.getBytes(), str.getBytes()));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
--
Gitblit v1.9.1