🔧Chore: 暂存
This commit is contained in:
@@ -17,6 +17,12 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hezhaohui</groupId>
|
||||
<artifactId>weather</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.larksuite.oapi</groupId>
|
||||
<artifactId>oapi-sdk</artifactId>
|
||||
|
||||
@@ -2,10 +2,12 @@ package cn.hezhaohui.lark;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
import static cn.hezhaohui.lark.handler.EventListener.larkClientStart;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages = "cn.hezhaohui")
|
||||
public class Application {
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(Application.class, args);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.hezhaohui.lark.util;
|
||||
|
||||
import cn.hezhaohui.common.AppConstant;
|
||||
import cn.hezhaohui.common.CardEnum;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.google.gson.JsonParser;
|
||||
@@ -52,7 +53,45 @@ public class LarkUtil {
|
||||
System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
|
||||
}
|
||||
|
||||
public static void sendCard(String cardId, String dataJson) {
|
||||
// TODO
|
||||
public static void sendCard(CardEnum cardEnum, Object object) throws Exception {
|
||||
// 构建client
|
||||
Client client = Client.newBuilder(AppConstant.APP_ID, AppConstant.APP_SECRET).build();
|
||||
|
||||
// Json 包装
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("template_id", cardEnum.getId());
|
||||
data.put("template_version_name", cardEnum.getVersionName());
|
||||
if (object != null) {
|
||||
data.put("template_variable", object);
|
||||
|
||||
}
|
||||
Map<String, Object> content = new HashMap<>();
|
||||
content.put("type", "template");
|
||||
content.put("data", data);
|
||||
|
||||
|
||||
// 创建请求对象
|
||||
CreateMessageReq req = CreateMessageReq.newBuilder()
|
||||
.receiveIdType("open_id")
|
||||
.createMessageReqBody(CreateMessageReqBody.newBuilder()
|
||||
.receiveId(AppConstant.APP_USER_OPEN_ID)
|
||||
.msgType("interactive")
|
||||
.content(JSONUtil.toJsonStr(content))
|
||||
.uuid(IdUtil.randomUUID())
|
||||
.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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
package cn.hezhaohui.lark.util;
|
||||
|
||||
|
||||
import cn.hezhaohui.common.CardEnum;
|
||||
import cn.hezhaohui.util.SpringContextUtil;
|
||||
import cn.hezhaohui.util.WeatherUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class LarkUtilTest {
|
||||
@Resource
|
||||
private SpringContextUtil springContextUtil;
|
||||
|
||||
@Test
|
||||
void sendText() throws Exception {
|
||||
LarkUtil.sendText("你好");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendCard() throws Exception {
|
||||
LarkUtil.sendCard(CardEnum.CARD_WEATHER, WeatherUtil.getWeather());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user