飞书机器人提醒 切换为机器人一对一私聊发送消息
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
212a22f17a
commit
f0e6ec42ec
@ -0,0 +1,59 @@
|
|||||||
|
package com.ruoyi.flyingbook.LarkHelper;
|
||||||
|
|
||||||
|
import com.lark.oapi.service.im.v1.enums.CreateMessageReceiveIdTypeEnum;
|
||||||
|
import com.lark.oapi.service.im.v1.model.CreateMessageReq;
|
||||||
|
import com.lark.oapi.service.im.v1.model.CreateMessageReqBody;
|
||||||
|
import com.lark.oapi.service.im.v1.model.CreateMessageResp;
|
||||||
|
import com.lark.oapi.service.im.v1.model.CreateMessageRespBody;
|
||||||
|
import com.ruoyi.flyingbook.domain.lark.LarkRobotRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuxiangyong
|
||||||
|
* @create 2023-03-12 18:10
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class LarkRobotHelper extends LarkHelper{
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
LarkRobotHelper robotHelper = new LarkRobotHelper();
|
||||||
|
LarkRobotRequest larkRobotRequest = new LarkRobotRequest(appId, secret, "ou_cd09481727e91fce1f12b7b0ed1500d2", "text", "{\"text\":\"test content\"}");
|
||||||
|
CreateMessageRespBody resp = robotHelper.sendUserMessage(larkRobotRequest);
|
||||||
|
int i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取行详情
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateMessageRespBody sendUserMessage(LarkRobotRequest request) {
|
||||||
|
try {
|
||||||
|
CreateMessageResp createMessageResp = buildClient(request)
|
||||||
|
.im()
|
||||||
|
.message()
|
||||||
|
.create(
|
||||||
|
CreateMessageReq.newBuilder()
|
||||||
|
.createMessageReqBody(CreateMessageReqBody.newBuilder()
|
||||||
|
.msgType(request.getMsgType())
|
||||||
|
.content(request.getContent())
|
||||||
|
.receiveId(request.getReceiveId())
|
||||||
|
.uuid(request.getUuid())
|
||||||
|
.build())
|
||||||
|
.receiveIdType(CreateMessageReceiveIdTypeEnum.OPEN_ID)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
if (createMessageResp.getCode() == 0){
|
||||||
|
return createMessageResp.getData();
|
||||||
|
}else {
|
||||||
|
throw new RuntimeException(createMessageResp.getMsg());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.ruoyi.flyingbook.domain.lark;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuxiangyong
|
||||||
|
* @create 2023-03-18 1:05
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class LarkRobotRequest extends LarkRequest{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唯一即可
|
||||||
|
*/
|
||||||
|
private String uuid;
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
*/
|
||||||
|
private String msgType;
|
||||||
|
/**
|
||||||
|
* 接收人id
|
||||||
|
*/
|
||||||
|
private String receiveId;
|
||||||
|
|
||||||
|
public LarkRobotRequest(String appId, String appSecret) {
|
||||||
|
super(appId, appSecret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LarkRobotRequest(String appId, String appSecret, String receiveId,String msgType,String content) {
|
||||||
|
super(appId, appSecret);
|
||||||
|
this.receiveId = receiveId;
|
||||||
|
this.msgType = msgType;
|
||||||
|
this.content = content;
|
||||||
|
this.uuid = String.valueOf(new Date().getTime());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue