通过访问钉钉开放API来实现访问日志信息,很简单。
package dataBackup;
import java.util.concurrent.TimeUnit;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.request.OapiReportListRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.dingtalk.api.response.OapiReportListResponse;
import com.taobao.api.ApiException;
public class dataBackup {
public static void main(String []args) throws ApiException {
//获取accessToken实现免登陆
DefaultDingTalkClient cli = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
OapiGettokenRequest req = new OapiGettokenRequest();
req.setAppkey("appkey");
req.setAppsecret("appsecret");
req.setHttpMethod("GET");
OapiGettokenResponse res = cli.execute(req);
String accessToken = res.getAccessToken();
//获取当天日志信息
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/report/list");
OapiReportListRequest request = new OapiReportListRequest();
request.setTemplateName("日报");
request.setStartTime(System.currentTimeMillis()-TimeUnit.DAYS.toMillis(10));
request.setEndTime(System.currentTimeMillis());
request.setCursor(0L);
request.setSize(10L);
OapiReportListResponse response = client.execute(request, accessToken);
//解码获取的日志json格式文件
String logInfo = response.getBody();
System.out.println(logInfo);
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。