🔧Chore: 暂存
This commit is contained in:
@@ -1,8 +0,0 @@
|
|||||||
package cn.hezhaohui.common;
|
|
||||||
|
|
||||||
public class CardConstant {
|
|
||||||
|
|
||||||
public static final String CARD_WEATHER_ID = "AAqxas5etOJDx";
|
|
||||||
public static final String CARD_WEATHER_VERSION = "1.0.5";
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package cn.hezhaohui.common;
|
||||||
|
|
||||||
|
public enum CardEnum {
|
||||||
|
CARD_WEATHER("AAqxas5etOJDx", "1.0.5");
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
private final String versionName;
|
||||||
|
|
||||||
|
CardEnum(String id, String versionName) {
|
||||||
|
this.id = id;
|
||||||
|
this.versionName = versionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersionName() {
|
||||||
|
return versionName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,12 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hezhaohui</groupId>
|
||||||
|
<artifactId>weather</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.larksuite.oapi</groupId>
|
<groupId>com.larksuite.oapi</groupId>
|
||||||
<artifactId>oapi-sdk</artifactId>
|
<artifactId>oapi-sdk</artifactId>
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package cn.hezhaohui.lark;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
import static cn.hezhaohui.lark.handler.EventListener.larkClientStart;
|
import static cn.hezhaohui.lark.handler.EventListener.larkClientStart;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ComponentScan(basePackages = "cn.hezhaohui")
|
||||||
public class Application {
|
public class Application {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cn.hezhaohui.lark.util;
|
package cn.hezhaohui.lark.util;
|
||||||
|
|
||||||
import cn.hezhaohui.common.AppConstant;
|
import cn.hezhaohui.common.AppConstant;
|
||||||
|
import cn.hezhaohui.common.CardEnum;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
@@ -52,7 +53,45 @@ public class LarkUtil {
|
|||||||
System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
|
System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendCard(String cardId, String dataJson) {
|
public static void sendCard(CardEnum cardEnum, Object object) throws Exception {
|
||||||
// TODO
|
// 构建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;
|
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.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
class LarkUtilTest {
|
class LarkUtilTest {
|
||||||
|
@Resource
|
||||||
|
private SpringContextUtil springContextUtil;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sendText() throws Exception {
|
void sendText() throws Exception {
|
||||||
LarkUtil.sendText("你好");
|
LarkUtil.sendText("你好");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sendCard() throws Exception {
|
||||||
|
LarkUtil.sendCard(CardEnum.CARD_WEATHER, WeatherUtil.getWeather());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user