✨Feat: 垂钓板块

This commit is contained in:
2025-10-26 16:21:31 +08:00
parent 5ddf362834
commit ea8c18b18b
3 changed files with 58 additions and 1 deletions
@@ -5,7 +5,8 @@ import lombok.Getter;
@Getter @Getter
public enum CardTemplate { public enum CardTemplate {
CARD_TEMPLATE_WEATHER("AAqxas5etOJDx", "1.0.5"), CARD_TEMPLATE_WEATHER("AAqxas5etOJDx", "1.0.5"),
CARD_TEMPLATE_FARM("AAqxaYo9rbXPa", "1.0.7"); CARD_TEMPLATE_FARM("AAqxaYo9rbXPa", "1.0.7"),
CARD_TEMPLATE_FISH("AAqxauQ2FQuSF", "1.0.3");
private String cardId; private String cardId;
private String version; private String version;
@@ -38,6 +38,8 @@ public class EventListener {
weatherHandle.sendCard(); weatherHandle.sendCard();
} else if (eventKey.equals("farm")) { } else if (eventKey.equals("farm")) {
LarkUtil.sendFarmCard(); LarkUtil.sendFarmCard();
} else if (eventKey.equals("fish")) {
LarkUtil.sendFishCard();
} }
System.out.printf("[ onP2BotMenuV6 access ], data: %s\n", Jsons.DEFAULT.toJson(event.getEvent())); System.out.printf("[ onP2BotMenuV6 access ], data: %s\n", Jsons.DEFAULT.toJson(event.getEvent()));
@@ -183,4 +183,58 @@ public class LarkUtil {
// 业务数据处理 // 业务数据处理
System.out.println(Jsons.DEFAULT.toJson(resp.getData())); System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
} }
public static void sendFishCard() 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<String, Object> templateData = new HashMap<>();
templateData.put("template_id", CardTemplate.CARD_TEMPLATE_FISH.getCardId());
templateData.put("template_version_name", CardTemplate.CARD_TEMPLATE_FISH.getVersion());
// templateData.put("template_variable", "");
// String jsonCardContent = Jsons.DEFAULT.toJson(templateData);
Map<String, Object> 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()));
}
} }