赞
踩
具体步骤
1.引入jar
-
- <dependency>
- <groupId>com.larksuite.oapi</groupId>
- <artifactId>oapi-sdk</artifactId>
- <version>2.0.31</version>
- </dependency>
- <dependency>
- <groupId>com.larksuite.oapi</groupId>
- <artifactId>oapi-sdk-apache-httpclient</artifactId>
- <version>1.0.1-snapshot</version>
- </dependency>
2.直接上代码
注意:accesstoken是用户的token,查询只能查询自己的任务,另外完成任务只能完成自己的任务,appid和appsecret需要替换为自己的应用
- package com.xxx.controller.interview;
-
- import com.lark.oapi.Client;
- import com.lark.oapi.core.request.RequestOptions;
- import com.lark.oapi.core.utils.Jsons;
- import com.lark.oapi.service.task.v1.model.*;
-
- public class Test {
-
- public static void main(String[] args) throws Exception {
-
-
- // 构建client
- Client client = Client.newBuilder("appid", "appsecret").build();
-
- for (int a = 0; a < 100; a++) {
- // 创建请求对象
- ListTaskReq req = ListTaskReq.newBuilder()
- .pageSize(100)
- .taskCompleted(false)
- .userIdType("open_id")
- .build();
-
- // 发起请求
- ListTaskResp resp = client.task().task().list(req, RequestOptions.newBuilder()
- .userAccessToken("accesstoken")
- .build());
-
- // 处理服务端错误
- if(!resp.success()) {
- System.out.println(String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
-
- }else {
- Task[] items = resp.getData().getItems();
- for (int i = 0; i < items.length; i++) {
- Task item = items[i];
- String id = item.getId();
-
- //完成任务
- // 创建请求对象
- CompleteTaskReq req2 = CompleteTaskReq.newBuilder()
- .taskId(id)
- .build();
-
- // 发起请求
- CompleteTaskResp complete = client.task().task().complete(req2, RequestOptions.newBuilder()
- .userAccessToken("accesstoken")
- .build());
-
- // 处理服务端错误
- if(!complete.success()) {
- System.out.println(String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
- return;
- }else{
- //
- }
-
- // 业务数据处理
- System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
-
- }
- }
-
- // 业务数据处理
- System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。