doum
昨天 2f3221b7c90d5663fdb312653a2d188bc4628370
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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();
    }
 
 
 
}