代码拉取完成,页面将自动刷新
同步操作将从 CodeJason/飞书服务端SDK java 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package com.larksuite.oapi.example;
import com.larksuite.oapi.core.Config;
import com.larksuite.oapi.core.Context;
import com.larksuite.oapi.core.event.DefaultHandler;
import com.larksuite.oapi.core.event.Event;
import com.larksuite.oapi.core.event.EventServlet;
import com.larksuite.oapi.core.utils.Jsons;
import com.larksuite.oapi.service.application.v1.ApplicationService;
import com.larksuite.oapi.service.application.v1.model.AppOpenEvent;
import com.larksuite.oapi.service.application.v1.model.AppStatusChangeEvent;
import com.larksuite.oapi.service.contact.v3.ContactService;
import com.larksuite.oapi.service.contact.v3.model.UserCreatedEvent;
import com.larksuite.oapi.service.contact.v3.model.UserUpdatedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.servlet.annotation.WebServlet;
import java.util.Map;
// "Developer Console" -> "Event Subscriptions", setting Request URL: https://domain/webhook/event
// Inherit EventServlet
@WebServlet("/webhook/event")
public class EventController extends EventServlet {
private static final Logger log = LoggerFactory.getLogger(EventController.class);
// Provide the config instance through InitConfig.java and inject the config instance through dependency
public EventController(Config config) {
super(config);
}
@PostConstruct
public void init() {
Event.setTypeHandler(this.getConfig(), "app_open", new DefaultHandler() {
@Override
public void Handle(Context context, Map<String, Object> event) throws Exception {
// Print the request ID of the request
log.info("requestId:{}", context.getRequestID());
// Print event
log.info("event:{}", event);
}
});
Event.setTypeHandler(this.getConfig(), "user.created_v2", (context, event) -> {
log.info("requestId:{}", context.getRequestID());
log.info("event:{}", event);
});
ApplicationService applicationService = new ApplicationService(this.getConfig());
applicationService.setAppOpenEventHandler(new ApplicationService.AppOpenEventHandler() {
@Override
public void Handle(Context context, AppOpenEvent event) throws Exception {
log.info("requestId:{}", context.getRequestID());
log.info("event:{}", Jsons.DEFAULT_GSON.toJson(event));
}
});
applicationService.setAppStatusChangeEventHandler(new ApplicationService.AppStatusChangeEventHandler() {
@Override
public void Handle(Context context, AppStatusChangeEvent event) throws Exception {
log.info("requestId:{}", context.getRequestID());
log.info("event:{}", Jsons.DEFAULT_GSON.toJson(event));
}
});
ContactService contactService = new ContactService(this.getConfig());
contactService.setUserCreatedEventHandler(new ContactService.UserCreatedEventHandler() {
@Override
public void Handle(Context context, UserCreatedEvent event) throws Exception {
log.info("requestId:{}", context.getRequestID());
log.info("event:{}", Jsons.DEFAULT_GSON.toJson(event));
}
});
contactService.setUserUpdatedEventHandler(new ContactService.UserUpdatedEventHandler() {
@Override
public void Handle(Context context, UserUpdatedEvent event) throws Exception {
log.info("requestId:{}", context.getRequestID());
log.info("event:{}", Jsons.DEFAULT_GSON.toJson(event));
}
});
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。