From e6111188c1c5a30a88f3906015a2e10bd8b025fd Mon Sep 17 00:00:00 2001 From: wonder Date: Sun, 26 Oct 2025 16:34:16 +0800 Subject: [PATCH] =?UTF-8?q?=20=E2=9C=A8Feat:=20=E8=8F=9C=E5=8D=95=E6=9D=BF?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stardewvalley/lark/card/CardTemplate.java | 7 +- .../util/lark/EventListener.java | 6 + .../stardewvalley/util/lark/LarkUtil.java | 162 ++++++++++++++++++ 3 files changed, 173 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/wonderland/stardewvalley/lark/card/CardTemplate.java b/src/main/java/com/wonderland/stardewvalley/lark/card/CardTemplate.java index 2a1653d..7643312 100644 --- a/src/main/java/com/wonderland/stardewvalley/lark/card/CardTemplate.java +++ b/src/main/java/com/wonderland/stardewvalley/lark/card/CardTemplate.java @@ -5,8 +5,11 @@ import lombok.Getter; @Getter public enum CardTemplate { CARD_TEMPLATE_WEATHER("AAqxas5etOJDx", "1.0.5"), - CARD_TEMPLATE_FARM("AAqxaYo9rbXPa", "1.0.7"), - CARD_TEMPLATE_FISH("AAqxauQ2FQuSF", "1.0.3"); + CARD_TEMPLATE_FARM("AAqxaYo9rbXPa", "1.0.8"), + CARD_TEMPLATE_FISH("AAqxauQ2FQuSF", "1.0.4"), + CARD_TEMPLATE_MINE("AAqxarffytU2e", "1.0.4"), + CARD_TEMPLATE_HELP("AAqxaCRidel6g", "1.0.5"), + CARD_TEMPLATE_LUCK("AAqxaScwjaUB3", "1.0.2"); private String cardId; private String version; diff --git a/src/main/java/com/wonderland/stardewvalley/util/lark/EventListener.java b/src/main/java/com/wonderland/stardewvalley/util/lark/EventListener.java index 00c6266..9852ba5 100644 --- a/src/main/java/com/wonderland/stardewvalley/util/lark/EventListener.java +++ b/src/main/java/com/wonderland/stardewvalley/util/lark/EventListener.java @@ -40,6 +40,12 @@ public class EventListener { LarkUtil.sendFarmCard(); } else if (eventKey.equals("fish")) { LarkUtil.sendFishCard(); + } else if (eventKey.equals("mine")) { + LarkUtil.sendMineCard(); + } else if (eventKey.equals("help")) { + LarkUtil.sendHelpCard(); + } else if (eventKey.equals("luck")) { + LarkUtil.sendLuckCard(); } System.out.printf("[ onP2BotMenuV6 access ], data: %s\n", Jsons.DEFAULT.toJson(event.getEvent())); diff --git a/src/main/java/com/wonderland/stardewvalley/util/lark/LarkUtil.java b/src/main/java/com/wonderland/stardewvalley/util/lark/LarkUtil.java index af9354e..c30c5ca 100644 --- a/src/main/java/com/wonderland/stardewvalley/util/lark/LarkUtil.java +++ b/src/main/java/com/wonderland/stardewvalley/util/lark/LarkUtil.java @@ -237,4 +237,166 @@ public class LarkUtil { // 业务数据处理 System.out.println(Jsons.DEFAULT.toJson(resp.getData())); } + + public static void sendMineCard() throws Exception { + // 构建client + Client client = Client.newBuilder(LarkConstant.APP_ID, LarkConstant.APP_SECRET).build(); + + // 生成uuid + String uuid = IdUtil.randomUUID().toString(); + + // 卡片参数 +// String textParam = JSONUtil.toJsonStr(weather); +// log.info(textParam); + + + // 构建卡片:对于不同的卡片,只需要给出不同的 模板id 版本号 变量字段 + + + + Map templateData = new HashMap<>(); + templateData.put("template_id", CardTemplate.CARD_TEMPLATE_MINE.getCardId()); + templateData.put("template_version_name", CardTemplate.CARD_TEMPLATE_MINE.getVersion()); +// templateData.put("template_variable", ""); +// String jsonCardContent = Jsons.DEFAULT.toJson(templateData); + + Map jsonContent = new HashMap<>(); + jsonContent.put("data", templateData); + jsonContent.put("type", "template"); + String json = Jsons.DEFAULT.toJson(jsonContent); + + log.info(json); + + // 创建请求对象 + CreateMessageReq req = CreateMessageReq.newBuilder() + .receiveIdType("open_id") + .createMessageReqBody(CreateMessageReqBody.newBuilder() + .receiveId(LarkConstant.USER_OPEN_ID) + .msgType("interactive") + .content(json) + .uuid(uuid) + .build()) + .build(); + + // 发起请求 + CreateMessageResp resp = client.im().v1().message().create(req); + + // 处理服务端错误 + if(!resp.success()) { + System.out.println(String.format("code:%s,msg:%s,reqId:%s, resp:%s", + resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), StandardCharsets.UTF_8))))); + return; + } + + // 业务数据处理 + System.out.println(Jsons.DEFAULT.toJson(resp.getData())); + } + + public static void sendHelpCard() throws Exception { + // 构建client + Client client = Client.newBuilder(LarkConstant.APP_ID, LarkConstant.APP_SECRET).build(); + + // 生成uuid + String uuid = IdUtil.randomUUID().toString(); + + // 卡片参数 +// String textParam = JSONUtil.toJsonStr(weather); +// log.info(textParam); + + + // 构建卡片:对于不同的卡片,只需要给出不同的 模板id 版本号 变量字段 + + + + Map templateData = new HashMap<>(); + templateData.put("template_id", CardTemplate.CARD_TEMPLATE_HELP.getCardId()); + templateData.put("template_version_name", CardTemplate.CARD_TEMPLATE_HELP.getVersion()); +// templateData.put("template_variable", ""); +// String jsonCardContent = Jsons.DEFAULT.toJson(templateData); + + Map jsonContent = new HashMap<>(); + jsonContent.put("data", templateData); + jsonContent.put("type", "template"); + String json = Jsons.DEFAULT.toJson(jsonContent); + + log.info(json); + + // 创建请求对象 + CreateMessageReq req = CreateMessageReq.newBuilder() + .receiveIdType("open_id") + .createMessageReqBody(CreateMessageReqBody.newBuilder() + .receiveId(LarkConstant.USER_OPEN_ID) + .msgType("interactive") + .content(json) + .uuid(uuid) + .build()) + .build(); + + // 发起请求 + CreateMessageResp resp = client.im().v1().message().create(req); + + // 处理服务端错误 + if(!resp.success()) { + System.out.println(String.format("code:%s,msg:%s,reqId:%s, resp:%s", + resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), StandardCharsets.UTF_8))))); + return; + } + + // 业务数据处理 + System.out.println(Jsons.DEFAULT.toJson(resp.getData())); + } + + public static void sendLuckCard() throws Exception { + // 构建client + Client client = Client.newBuilder(LarkConstant.APP_ID, LarkConstant.APP_SECRET).build(); + + // 生成uuid + String uuid = IdUtil.randomUUID().toString(); + + // 卡片参数 +// String textParam = JSONUtil.toJsonStr(weather); +// log.info(textParam); + + + // 构建卡片:对于不同的卡片,只需要给出不同的 模板id 版本号 变量字段 + + + + Map templateData = new HashMap<>(); + templateData.put("template_id", CardTemplate.CARD_TEMPLATE_LUCK.getCardId()); + templateData.put("template_version_name", CardTemplate.CARD_TEMPLATE_LUCK.getVersion()); +// templateData.put("template_variable", ""); +// String jsonCardContent = Jsons.DEFAULT.toJson(templateData); + + Map jsonContent = new HashMap<>(); + jsonContent.put("data", templateData); + jsonContent.put("type", "template"); + String json = Jsons.DEFAULT.toJson(jsonContent); + + log.info(json); + + // 创建请求对象 + CreateMessageReq req = CreateMessageReq.newBuilder() + .receiveIdType("open_id") + .createMessageReqBody(CreateMessageReqBody.newBuilder() + .receiveId(LarkConstant.USER_OPEN_ID) + .msgType("interactive") + .content(json) + .uuid(uuid) + .build()) + .build(); + + // 发起请求 + CreateMessageResp resp = client.im().v1().message().create(req); + + // 处理服务端错误 + if(!resp.success()) { + System.out.println(String.format("code:%s,msg:%s,reqId:%s, resp:%s", + resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), StandardCharsets.UTF_8))))); + return; + } + + // 业务数据处理 + System.out.println(Jsons.DEFAULT.toJson(resp.getData())); + } }