From 2ebcc4915d1ce35557be46144dc6dd46825a3c6e Mon Sep 17 00:00:00 2001 From: Van0313 <60689272+Van0313@users.noreply.github.com> Date: Tue, 17 Jun 2025 22:04:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BD=95=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/jd/erp/TestController.java | 30 +++++ .../request/AuthorizeListQueryRequest.java | 7 ++ .../van/business/erp/request/ERPAccount.java | 62 +++++----- .../erp/request/ERPProductQueryRequest.java | 20 ---- .../business/erp/request/ERPRequestBase.java | 108 +++++++++-------- .../cn/van/business/erp/request/HttpTest.java | 107 +++++++++++++++++ .../erp/request/ProductListQueryRequest.java | 7 ++ .../cn/van/business/erp/request/test.java | 111 ------------------ .../java/cn/van/business/util/JwtUtils.java | 3 +- 9 files changed, 242 insertions(+), 213 deletions(-) create mode 100644 src/main/java/cn/van/business/controller/jd/erp/TestController.java create mode 100644 src/main/java/cn/van/business/erp/request/AuthorizeListQueryRequest.java delete mode 100644 src/main/java/cn/van/business/erp/request/ERPProductQueryRequest.java create mode 100644 src/main/java/cn/van/business/erp/request/HttpTest.java create mode 100644 src/main/java/cn/van/business/erp/request/ProductListQueryRequest.java delete mode 100644 src/main/java/cn/van/business/erp/request/test.java diff --git a/src/main/java/cn/van/business/controller/jd/erp/TestController.java b/src/main/java/cn/van/business/controller/jd/erp/TestController.java new file mode 100644 index 0000000..80bebdc --- /dev/null +++ b/src/main/java/cn/van/business/controller/jd/erp/TestController.java @@ -0,0 +1,30 @@ +package cn.van.business.controller.jd.erp; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.van.business.erp.request.AuthorizeListQueryRequest; +import cn.van.business.erp.request.ERPAccount; +import cn.van.business.erp.request.ProductListQueryRequest; +import com.alibaba.fastjson2.JSONObject; + +/** + * @author Leo + * @version 1.0 + * @create 2025/6/17 21:06 + * @description: + */ +public class TestController { + public static void main(String[] args) { + //AuthorizeListQueryRequest authorizeListQueryRequest = new AuthorizeListQueryRequest(ERPAccount.ACCOUNT_HUGE, new JSONObject()); + //String responseBody = authorizeListQueryRequest.getResponseBody(); + //System.out.println(responseBody); + System.out.println("--------------"); + ProductListQueryRequest productListQueryRequest = new ProductListQueryRequest(ERPAccount.ACCOUNT_HUGE); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("page_no", 1); + jsonObject.put("page_size", 1); + productListQueryRequest.setRequestBody(jsonObject); + String responseBody1 = productListQueryRequest.getResponseBody(); + System.out.println(responseBody1); + } +} diff --git a/src/main/java/cn/van/business/erp/request/AuthorizeListQueryRequest.java b/src/main/java/cn/van/business/erp/request/AuthorizeListQueryRequest.java new file mode 100644 index 0000000..3c46515 --- /dev/null +++ b/src/main/java/cn/van/business/erp/request/AuthorizeListQueryRequest.java @@ -0,0 +1,7 @@ +package cn.van.business.erp.request; + +public class AuthorizeListQueryRequest extends ERPRequestBase { + public AuthorizeListQueryRequest(ERPAccount erpAccount) { + super("https://open.goofish.pro/api/open/user/authorize/list", erpAccount); + } +} diff --git a/src/main/java/cn/van/business/erp/request/ERPAccount.java b/src/main/java/cn/van/business/erp/request/ERPAccount.java index 0782688..77e4b7f 100644 --- a/src/main/java/cn/van/business/erp/request/ERPAccount.java +++ b/src/main/java/cn/van/business/erp/request/ERPAccount.java @@ -1,31 +1,31 @@ -//package cn.van.business.erp.request; -// -///** -// * @author Leo -// * @version 1.0 -// * @create 2025/4/10 15:20 -// * @description:ERP账户枚举类 -// */ -//public enum ERPAccount { -// // 胡歌 -// ACCOUNT_HUGE("1016208368633221", "waLiRMgFcixLbcLjUSSwo370Hp1nBcBu"), -// // 刘强东 -// ACCOUNT_LQD("anotherApiKey", "anotherApiSecret"); -// -// private final String apiKey; -// private final String apiKeySecret; -// -// ERPAccount(String apiKey, String apiKeySecret) { -// this.apiKey = apiKey; -// this.apiKeySecret = apiKeySecret; -// } -// -// public String getApiKey() { -// return apiKey; -// } -// -// public String getApiKeySecret() { -// return apiKeySecret; -// } -//} -// +package cn.van.business.erp.request; + +/** + * @author Leo + * @version 1.0 + * @create 2025/4/10 15:20 + * @description:ERP账户枚举类 + */ +public enum ERPAccount { + // 胡歌 + ACCOUNT_HUGE("1016208368633221", "waLiRMgFcixLbcLjUSSwo370Hp1nBcBu"), + // 刘强东 + ACCOUNT_LQD("anotherApiKey", "anotherApiSecret"); + + private final String apiKey; + private final String apiKeySecret; + + ERPAccount(String apiKey, String apiKeySecret) { + this.apiKey = apiKey; + this.apiKeySecret = apiKeySecret; + } + + public String getApiKey() { + return apiKey; + } + + public String getApiKeySecret() { + return apiKeySecret; + } +} + diff --git a/src/main/java/cn/van/business/erp/request/ERPProductQueryRequest.java b/src/main/java/cn/van/business/erp/request/ERPProductQueryRequest.java deleted file mode 100644 index 00b0992..0000000 --- a/src/main/java/cn/van/business/erp/request/ERPProductQueryRequest.java +++ /dev/null @@ -1,20 +0,0 @@ -//package cn.van.business.erp.request; -// -//import com.fasterxml.jackson.core.JsonProcessingException; -//import com.fasterxml.jackson.databind.ObjectMapper; -// -//public class ProductQueryRequest extends ERPRequestBase { -// public ProductQueryRequest(String url, ERPAccount erpAccount, ApifoxModel requestBody) { -// super(url, erpAccount, requestBody); -// } -// -// @Override -// public String getRequestBodyAsString() { -// try { -// ObjectMapper objectMapper = new ObjectMapper(); -// return objectMapper.writeValueAsString(requestBody); -// } catch (JsonProcessingException e) { -// throw new RuntimeException("Failed to convert request body to JSON", e); -// } -// } -//} diff --git a/src/main/java/cn/van/business/erp/request/ERPRequestBase.java b/src/main/java/cn/van/business/erp/request/ERPRequestBase.java index e5890e3..7026d92 100644 --- a/src/main/java/cn/van/business/erp/request/ERPRequestBase.java +++ b/src/main/java/cn/van/business/erp/request/ERPRequestBase.java @@ -1,49 +1,59 @@ -//package cn.van.business.erp.request; -// -//import com.fasterxml.jackson.core.JsonProcessingException; -//import com.fasterxml.jackson.databind.ObjectMapper; -// -//import java.nio.charset.StandardCharsets; -//import java.security.MessageDigest; -//import java.security.NoSuchAlgorithmException; -// -//public abstract class ERPRequestBase { -// protected final String url; -// protected final ERPAccount erpAccount; -// protected final Object requestBody; -// -// public ERPRequestBase(String url, ERPAccount erpAccount, Object requestBody) { -// this.url = url; -// this.erpAccount = erpAccount; -// this.requestBody = requestBody; -// } -// -// public String getUrl() { -// return url; -// } -// -// public ERPAccount getErpAccount() { -// return erpAccount; -// } -// -// public abstract String getRequestBodyAsString(); -// -// protected String genMd5(String str) { -// StringBuilder result = new StringBuilder(); -// try { -// MessageDigest md = MessageDigest.getInstance("MD5"); -// byte[] digest = md.digest(str.getBytes(StandardCharsets.UTF_8)); -// for (byte b : digest) { -// result.append(String.format("%02x", b & 0xff)); -// } -// } catch (NoSuchAlgorithmException e) { -// throw new RuntimeException(e); -// } -// return result.toString(); -// } -// -// protected String genSign(long timestamp, String jsonStr) { -// String data = erpAccount.getApiKey() + "," + genMd5(jsonStr) + "," + timestamp + "," + erpAccount.getApiKeySecret(); -// return genMd5(data); -// } -//} +package cn.van.business.erp.request; + +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson2.JSONObject; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public abstract class ERPRequestBase { + protected String url; + protected String sign; + protected ERPAccount erpAccount; + protected JSONObject requestBody; + + public ERPRequestBase(String url, ERPAccount erpAccount) { + this.url = url; + this.erpAccount = erpAccount; + } + + public void setRequestBody(JSONObject requestBody) { + this.requestBody = requestBody; + } + + public String genMd5(String str) { + StringBuilder result = new StringBuilder(); + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] digest = md.digest(str.getBytes(StandardCharsets.UTF_8)); + for (byte b : digest) { + result.append(String.format("%02x", b & 0xff)); + } + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + return result.toString(); + } + + public void genSign() { + long timestamp = System.currentTimeMillis() / 1000; + String jsonStr = requestBody.toJSONString(); + String data = erpAccount.getApiKey() + "," + genMd5(jsonStr) + "," + timestamp + "," + erpAccount.getApiKeySecret(); + this.sign = genMd5(data); + } + + public String getRequestUrl() { + return url+"?appid="+erpAccount.getApiKey()+"×tamp="+System.currentTimeMillis()/1000+"&sign="+sign; + } + public String getRequestBody() { + return requestBody.toJSONString(); + } + public String getResponseBody() { + genSign(); + HttpRequest post = HttpRequest.post(getRequestUrl()); + post.body(getRequestBody()); + return post.execute().body(); + } + +} diff --git a/src/main/java/cn/van/business/erp/request/HttpTest.java b/src/main/java/cn/van/business/erp/request/HttpTest.java new file mode 100644 index 0000000..0f30183 --- /dev/null +++ b/src/main/java/cn/van/business/erp/request/HttpTest.java @@ -0,0 +1,107 @@ +package cn.van.business.erp.request; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class HttpTest { + private static String apiKey = "1016208368633221"; // 开放平台提供的应用KEY + private static String apiKeySecret = "o9wl81dncmvby3ijpq7eur456zhgtaxs"; // 开放平台提供的应用密钥 + private static String domain = "https://open.goofish.pro"; // 域名 + + public static void main(String[] args) { + // 获取当前时间戳 + long timestamp = System.currentTimeMillis() / 1000L; + System.out.println("timestamp: " + timestamp); + + // 请求体JSON字符串 + String productId = "941757976162"; + String jsonBody = "{\"product_id\":" + productId + "}"; + + // 生成签名 + String sign = genSign(timestamp, jsonBody); + System.out.println("sign: " + sign); + + // 拼接请求地址 + String apiUrl = domain + "/api/open/product/detail?appid=" + apiKey + "×tamp=" + timestamp + "&sign=" + + sign; + + try { + // 创建URL对象 + URL url = new URL(apiUrl); + + // 打开连接 + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + + // 设置请求方法为POST + connection.setRequestMethod("POST"); + + // 设置请求头部 + connection.setRequestProperty("Content-Type", "application/json"); + connection.setRequestProperty("Accept", "application/json"); + + // 启用输出流 + connection.setDoOutput(true); + + // 获取输出流并写入请求体 + OutputStream outputStream = connection.getOutputStream(); + outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8)); + outputStream.close(); + + // 获取响应状态码 + int responseCode = connection.getResponseCode(); + System.out.println("API Response Code: " + responseCode); + + // 读取响应内容 + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + StringBuilder response = new StringBuilder(); + while ((line = bufferedReader.readLine()) != null) { + response.append(line); + } + bufferedReader.close(); + + // 关闭连接 + connection.disconnect(); + + System.out.println("API Response: " + response.toString()); + + } catch (IOException e) { + // 在此处处理异常 + e.printStackTrace(); + } + } + + // md5加密 + private static String genMd5(String str) { + StringBuilder result = new StringBuilder(); + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] digest = md.digest(str.getBytes(StandardCharsets.UTF_8)); + for (byte b : digest) { + result.append(String.format("%02x", b & 0xff)); + } + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + return result.toString(); + } + + // 生成签名 + private static String genSign(long timestamp, String jsonStr) { + // 拼接字符串 + String data = apiKey + "," + genMd5(jsonStr) + "," + timestamp + "," + apiKeySecret; + + // 商务对接模式 拼接字符串 + // String data = apiKey + "," + genMd5(jsonStr) + "," + timestamp + "," + seller_id + "," + apiKeySecret; + + // 生成签名 + return genMd5(data); + } +} diff --git a/src/main/java/cn/van/business/erp/request/ProductListQueryRequest.java b/src/main/java/cn/van/business/erp/request/ProductListQueryRequest.java new file mode 100644 index 0000000..2632e1e --- /dev/null +++ b/src/main/java/cn/van/business/erp/request/ProductListQueryRequest.java @@ -0,0 +1,7 @@ +package cn.van.business.erp.request; + +public class ProductListQueryRequest extends ERPRequestBase { + public ProductListQueryRequest(ERPAccount erpAccount) { + super("https://open.goofish.pro/api/open/product/list", erpAccount); + } +} diff --git a/src/main/java/cn/van/business/erp/request/test.java b/src/main/java/cn/van/business/erp/request/test.java deleted file mode 100644 index 781dffd..0000000 --- a/src/main/java/cn/van/business/erp/request/test.java +++ /dev/null @@ -1,111 +0,0 @@ -//package cn.van.business.erp.request; -// -///** -// * @author Leo -// * @version 1.0 -// * @create 2025/4/9 21:30 -// * @description: -// */ -//import java.io.BufferedReader; -//import java.io.IOException; -//import java.io.InputStreamReader; -//import java.io.OutputStream; -//import java.net.HttpURLConnection; -//import java.net.URL; -//import java.nio.charset.StandardCharsets; -//import java.security.MessageDigest; -//import java.security.NoSuchAlgorithmException; -// -//public class HttpTest { -// private static long apiKey = 203413189371893L; // 开放平台提供的应用KEY -// private static String apiKeySecret = "o9wl81dncmvby3ijpq7eur456zhgtaxs"; // 开放平台提供的应用密钥 -// private static String domain = "https://open.goofish.pro"; // 域名 -// -// public static void main(String[] args) { -// // 获取当前时间戳 -// long timestamp = System.currentTimeMillis() / 1000L; -// -// // 请求体JSON字符串 -// String productId = "220656347074629"; -// String jsonBody = "{\"product_id\":" + productId + "}"; -// -// // 生成签名 -// String sign = genSign(timestamp, jsonBody); -// -// // 拼接请求地址 -// String apiUrl = domain + "/api/open/product/detail?appid=" + apiKey + "×tamp=" + timestamp + "&sign=" -// + sign; -// -// try { -// // 创建URL对象 -// URL url = new URL(apiUrl); -// -// // 打开连接 -// HttpURLConnection connection = (HttpURLConnection) url.openConnection(); -// -// // 设置请求方法为POST -// connection.setRequestMethod("POST"); -// -// // 设置请求头部 -// connection.setRequestProperty("Content-Type", "application/json"); -// connection.setRequestProperty("Accept", "application/json"); -// -// // 启用输出流 -// connection.setDoOutput(true); -// -// // 获取输出流并写入请求体 -// OutputStream outputStream = connection.getOutputStream(); -// outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8)); -// outputStream.close(); -// -// // 获取响应状态码 -// int responseCode = connection.getResponseCode(); -// System.out.println("API Response Code: " + responseCode); -// -// // 读取响应内容 -// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); -// String line; -// StringBuilder response = new StringBuilder(); -// while ((line = bufferedReader.readLine()) != null) { -// response.append(line); -// } -// bufferedReader.close(); -// -// // 关闭连接 -// connection.disconnect(); -// -// System.out.println("API Response: " + response.toString()); -// -// } catch (IOException e) { -// // 在此处处理异常 -// e.printStackTrace(); -// } -// } -// -// // md5加密 -// private static String genMd5(String str) { -// StringBuilder result = new StringBuilder(); -// try { -// MessageDigest md = MessageDigest.getInstance("MD5"); -// byte[] digest = md.digest(str.getBytes(StandardCharsets.UTF_8)); -// for (byte b : digest) { -// result.append(String.format("%02x", b & 0xff)); -// } -// } catch (NoSuchAlgorithmException e) { -// throw new RuntimeException(e); -// } -// return result.toString(); -// } -// -// // 生成签名 -// private static String genSign(long timestamp, String jsonStr) { -// // 拼接字符串 -// String data = apiKey + "," + genMd5(jsonStr) + "," + timestamp + "," + apiKeySecret; -// -// // 商务对接模式 拼接字符串 -// // String data = apiKey + "," + genMd5(jsonStr) + "," + timestamp + "," + seller_id + "," + apiKeySecret; -// -// // 生成签名 -// return genMd5(data); -// } -//} diff --git a/src/main/java/cn/van/business/util/JwtUtils.java b/src/main/java/cn/van/business/util/JwtUtils.java index 66d3ed3..53e0099 100644 --- a/src/main/java/cn/van/business/util/JwtUtils.java +++ b/src/main/java/cn/van/business/util/JwtUtils.java @@ -14,12 +14,11 @@ import java.util.Date; @Component public class JwtUtils { - private final String secret = "7b78f5cc9735091442361c78b863607d"; // 应配置在 application.yml 中 + private final String secret = "7b4c86d11fe2b64a5ce4d7d83de881b4afa76bf4a8bbc13ee50676c20b14c0835dda8a78a5a795b0f2201a26f758301b56ffbc52d021e158f1365d8be22fa6d7"; // 应配置在 application.yml 中 private final long expiration = 86400000 * 7; // 24小时 /** * 生成一个新的 JWT Token - * * @param username 用户名 * @param roles 用户角色(可选) * @return 返回生成的 JWT Token 字符串 From b03f1d33fe945217b08fc07265912d7823f189d4 Mon Sep 17 00:00:00 2001 From: Van0313 <60689272+Van0313@users.noreply.github.com> Date: Tue, 17 Jun 2025 23:31:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BD=95=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/van/business/util/WxMessageConsumer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cn/van/business/util/WxMessageConsumer.java b/src/main/java/cn/van/business/util/WxMessageConsumer.java index d744fb1..4197a1b 100644 --- a/src/main/java/cn/van/business/util/WxMessageConsumer.java +++ b/src/main/java/cn/van/business/util/WxMessageConsumer.java @@ -98,7 +98,7 @@ public class WxMessageConsumer { if (chatRoom_xb.containsKey(fromWxid)) { logger.info("线报群消息"); - jdUtils.xb(msg, fromWxid); + //jdUtils.xb(msg, fromWxid); return; } // 录单群