parent
10824d0a70
commit
02ed694178
After Width: | Height: | Size: 87 KiB |
@ -0,0 +1,61 @@
|
|||||||
|
package com.ruoyi.flyingbook.LarkHelper;
|
||||||
|
|
||||||
|
import com.lark.oapi.service.drive.v1.enums.ParentTypeEnum;
|
||||||
|
import com.lark.oapi.service.drive.v1.model.UploadAllFileReq;
|
||||||
|
import com.lark.oapi.service.drive.v1.model.UploadAllFileReqBody;
|
||||||
|
import com.lark.oapi.service.drive.v1.model.UploadAllFileResp;
|
||||||
|
import com.lark.oapi.service.drive.v1.model.UploadAllFileRespBody;
|
||||||
|
import com.ruoyi.flyingbook.domain.lark.LarkFileRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuxiangyong
|
||||||
|
* @create 2023-03-12 18:10
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class LarkFileHelper extends LarkHelper {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
LarkFileHelper fileHelper = new LarkFileHelper();
|
||||||
|
LarkFileRequest fileRequest = new LarkFileRequest(appId, secret, new File(""), "text.pdf", 1024,"adwd");
|
||||||
|
UploadAllFileRespBody resp = fileHelper.uploadFile(fileRequest);
|
||||||
|
int i = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传附件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public UploadAllFileRespBody uploadFile(LarkFileRequest request) {
|
||||||
|
try {
|
||||||
|
UploadAllFileResp uploadAllFileResp = buildClient(request)
|
||||||
|
.drive()
|
||||||
|
.file()
|
||||||
|
.uploadAll(
|
||||||
|
UploadAllFileReq.newBuilder()
|
||||||
|
.uploadAllFileReqBody(
|
||||||
|
UploadAllFileReqBody.newBuilder()
|
||||||
|
.file(request.getFile())
|
||||||
|
.fileName(request.getFileName())
|
||||||
|
.parentNode(request.getParentNode())
|
||||||
|
.parentType(ParentTypeEnum.EXPLORER.getValue())
|
||||||
|
.size(request.getFileSize())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
if (uploadAllFileResp.getCode() == 0){
|
||||||
|
return uploadAllFileResp.getData();
|
||||||
|
}else {
|
||||||
|
throw new RuntimeException(uploadAllFileResp.getMsg());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,46 +0,0 @@
|
|||||||
package com.ruoyi.flyingbook.controller;
|
|
||||||
import com.lark.oapi.service.drive.v1.DriveService;
|
|
||||||
import com.lark.oapi.service.drive.v1.model.P2FileBitableFieldChangedV1;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.lark.oapi.core.utils.Jsons;
|
|
||||||
import com.lark.oapi.event.EventDispatcher;
|
|
||||||
import com.lark.oapi.sdk.servlet.ext.ServletAdapter;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
public class EventControllers {
|
|
||||||
|
|
||||||
|
|
||||||
//1. 注册消息处理器
|
|
||||||
private final EventDispatcher EVENT_DISPATCHER = EventDispatcher.newBuilder("xJJE7c2rlHzDCk2uPZk77fQNJFtXgTW3",
|
|
||||||
"ND2ANZB8F7NplUqcrmKD530lDRFssNWJ")
|
|
||||||
.onP2FileBitableFieldChangedV1(new DriveService.P2FileBitableFieldChangedV1Handler(){
|
|
||||||
@Override
|
|
||||||
public void handle(P2FileBitableFieldChangedV1 p2FileBitableFieldChangedV1) throws Exception {
|
|
||||||
System.out.println(Jsons.DEFAULT.toJson(p2FileBitableFieldChangedV1));
|
|
||||||
System.out.println(p2FileBitableFieldChangedV1.getRequestId());
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
//2. 注入 ServletAdapter 实例
|
|
||||||
@Autowired
|
|
||||||
private ServletAdapter servletAdapter;
|
|
||||||
|
|
||||||
|
|
||||||
//3. 创建路由处理器
|
|
||||||
@PostMapping("/approval2")
|
|
||||||
public void event(HttpServletRequest request, HttpServletResponse response)
|
|
||||||
throws Throwable {
|
|
||||||
//3.1 回调扩展包提供的事件回调处理器
|
|
||||||
servletAdapter.handleEvent(request, response, EVENT_DISPATCHER);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.ruoyi.flyingbook.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.lark.oapi.card.CardActionHandler;
|
||||||
|
import com.lark.oapi.card.model.CardAction;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.lark.oapi.core.utils.Jsons;
|
||||||
|
import com.lark.oapi.sdk.servlet.ext.ServletAdapter;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
public class RobotController {
|
||||||
|
|
||||||
|
|
||||||
|
//1. 注册卡片处理器
|
||||||
|
private final CardActionHandler CARD_ACTION_HANDLER = CardActionHandler.newBuilder("xJJE7c2rlHzDCk2uPZk77fQNJFtXgTW3", "ND2ANZB8F7NplUqcrmKD530lDRFssNWJ",
|
||||||
|
new CardActionHandler.ICardHandler() {
|
||||||
|
@Override
|
||||||
|
public Object handle(CardAction cardAction) {
|
||||||
|
System.out.println(JSONObject.toJSONString(cardAction));
|
||||||
|
return cardAction.getChallenge();
|
||||||
|
}
|
||||||
|
}).build();
|
||||||
|
@Autowired
|
||||||
|
private ServletAdapter servletAdapter;
|
||||||
|
|
||||||
|
//3. 注册服务路由
|
||||||
|
@RequestMapping("/robot/callback")
|
||||||
|
public void card(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws Throwable {
|
||||||
|
//3.1 回调扩展包卡片行为处理回调
|
||||||
|
servletAdapter.handleCardAction(request, response, CARD_ACTION_HANDLER);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.ruoyi.flyingbook.domain.lark;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yuxiangyong
|
||||||
|
* @create 2023-03-18 1:05
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class LarkFileRequest extends LarkRequest{
|
||||||
|
|
||||||
|
|
||||||
|
private File file;
|
||||||
|
private String fileName;
|
||||||
|
private Integer fileSize;
|
||||||
|
private String parentNode;
|
||||||
|
|
||||||
|
public LarkFileRequest(String appId, String appSecret, File file, String fileName, Integer fileSize, String parentNode) {
|
||||||
|
super(appId, appSecret);
|
||||||
|
this.file = file;
|
||||||
|
this.fileName = fileName;
|
||||||
|
this.fileSize = fileSize;
|
||||||
|
this.parentNode = parentNode;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue