Merge remote-tracking branch '群晖/master'
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
107
src/main/java/cn/van/business/erp/request/HttpTest.java
Normal file
107
src/main/java/cn/van/business/erp/request/HttpTest.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
// }
|
||||
//}
|
||||
@@ -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 字符串
|
||||
|
||||
@@ -98,7 +98,7 @@ public class WxMessageConsumer {
|
||||
|
||||
if (chatRoom_xb.containsKey(fromWxid)) {
|
||||
logger.info("线报群消息");
|
||||
jdUtils.xb(msg, fromWxid);
|
||||
//jdUtils.xb(msg, fromWxid);
|
||||
return;
|
||||
}
|
||||
// 录单群
|
||||
|
||||
Reference in New Issue
Block a user