package com.doumee.core.dingTalk;
|
|
import com.dingtalk.open.app.api.GenericEventListener;
|
import com.dingtalk.open.app.api.OpenDingTalkStreamClientBuilder;
|
import com.dingtalk.open.app.api.message.GenericOpenDingTalkEvent;
|
import com.dingtalk.open.app.api.security.AuthClientCredential;
|
import com.dingtalk.open.app.stream.protocol.event.EventAckStatus;
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.core.constants.Constants;
|
import com.doumee.service.business.MemberService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
import shade.com.alibaba.fastjson2.JSONObject;
|
|
/**
|
* 钉钉 订阅事件通知
|
*
|
* @Author : Rk
|
* @create 2025/9/24 17:14
|
*/
|
@Slf4j
|
@Configuration
|
public class DingTalkStream {
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@Bean
|
public void DingTalkStreamRun() throws Exception {
|
String appKey = systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.APP_KEY).getCode();
|
String appSecret = systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.APP_SECRET).getCode();
|
|
OpenDingTalkStreamClientBuilder
|
.custom()
|
.credential(new AuthClientCredential(appKey, appSecret))
|
//注册事件监听
|
.registerAllEventListener(new GenericEventListener() {
|
@Override
|
public EventAckStatus onEvent(GenericOpenDingTalkEvent event) {
|
try {
|
//事件唯一Id
|
String eventId = event.getEventId();
|
log.error("钉钉推送事件Id:{}"+eventId);
|
//事件类型
|
String eventType = event.getEventType();
|
log.error("钉钉推送事件类型:{}"+eventType);
|
//事件产生时间
|
Long bornTime = event.getEventBornTime();
|
log.error("钉钉推送事件产生时间:{}"+bornTime);
|
//获取事件体
|
JSONObject bizData = event.getData();
|
log.error("钉钉推送事件详情:{}"+bizData);
|
|
//处理事件
|
// process(bizData);
|
//消费成功
|
return EventAckStatus.SUCCESS;
|
} catch (Exception e) {
|
//消费失败
|
return EventAckStatus.LATER;
|
}
|
}
|
})
|
.build().start();
|
}
|
|
|
|
}
|