1 Star 0 Fork 7

梵希_小二 / 飞书服务端SDK java

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
AuthenSample.java 4.51 KB
一键复制 编辑 原始数据 按行查看 历史
zhaomingqiang 提交于 2021-03-22 13:30 . fix service authen
package com.larksuite.oapi.sample.api;
import com.larksuite.oapi.core.AppSettings;
import com.larksuite.oapi.core.Config;
import com.larksuite.oapi.core.api.BatchReqCall;
import com.larksuite.oapi.core.api.ReqCallResult;
import com.larksuite.oapi.core.api.request.Request;
import com.larksuite.oapi.core.api.response.Response;
import com.larksuite.oapi.core.utils.Jsons;
import com.larksuite.oapi.sample.config.Configs;
import com.larksuite.oapi.service.authen.v1.AuthenService;
import com.larksuite.oapi.service.authen.v1.model.AuthenAccessTokenReqBody;
import com.larksuite.oapi.service.authen.v1.model.AuthenRefreshAccessTokenReqBody;
import com.larksuite.oapi.service.authen.v1.model.UserAccessTokenInfo;
import com.larksuite.oapi.service.authen.v1.model.UserInfo;
import java.util.List;
import java.util.concurrent.ExecutionException;
public class AuthenSample {
// for Cutome APP(自建应用)
private static final AppSettings appSettings = Config.getInternalAppSettingsByEnv();
// config with redis store
private static final Config config = Configs.getConfigWithRedisStore("https://open.feishu.cn", appSettings);
// private static final Config config = Configs.getConfig("https://open.feishu.cn", appSettings);
// private static final Config config = Configs.getConfig(Domain.FeiShu, appSettings);
public static void main(String[] args) throws Exception {
testAccessToken();
//testFreshAccessToken();
//testUserInfo();
}
private static void testAccessToken() throws Exception {
AuthenService service = new AuthenService(config);
AuthenAccessTokenReqBody body = new AuthenAccessTokenReqBody();
body.setGrantType("authorization_code");
body.setCode("lYuFiIZKtOuKd4zrLO8soc");
AuthenService.AuthenAccessTokenReqCall reqCall = service.getAuthens().accessToken(body);
Response<UserAccessTokenInfo> response = reqCall.execute();
System.out.println(Jsons.DEFAULT_GSON.toJson(response));
System.out.println(Jsons.DEFAULT_GSON.toJson(response.getData()));
System.out.println(response.getRequestID());
}
private static void testFreshAccessToken() throws Exception {
AuthenService service = new AuthenService(config);
AuthenRefreshAccessTokenReqBody body = new AuthenRefreshAccessTokenReqBody();
body.setGrantType("refresh_token");
body.setRefreshToken("[refresh_token]");
AuthenService.AuthenRefreshAccessTokenReqCall reqCall = service.getAuthens().refreshAccessToken(body);
Response<UserAccessTokenInfo> response = reqCall.execute();
System.out.println(Jsons.DEFAULT_GSON.toJson(response));
System.out.println(response.getRequestID());
}
private static void testUserInfo() throws Exception {
AuthenService service = new AuthenService(config);
AuthenService.AuthenUserInfoReqCall reqCall = service.getAuthens().userInfo(Request.setUserAccessToken("u-7B5D40vAJryhYyf6eigcxf"));
Response<UserInfo> response = reqCall.execute();
System.out.println(Jsons.DEFAULT_GSON.toJson(response.getData()));
System.out.println(response.getRequestID());
}
private static void batchAccessToken() {
AuthenService service = new AuthenService(config);
AuthenAccessTokenReqBody body = new AuthenAccessTokenReqBody();
body.setCode("[code]");
body.setGrantType("authorization_code");
AuthenService.AuthenAccessTokenReqCall reqCall1 = service.getAuthens().accessToken(body);
AuthenService.AuthenAccessTokenReqCall reqCall2 = service.getAuthens().accessToken(body);
BatchReqCall<AuthenAccessTokenReqBody, UserAccessTokenInfo> batchReqCall = new BatchReqCall<>(reqCall1, reqCall2);
try {
List<ReqCallResult<AuthenAccessTokenReqBody, UserAccessTokenInfo>> reqCallResults = batchReqCall.call();
for (ReqCallResult<AuthenAccessTokenReqBody, UserAccessTokenInfo> reqCallResult : reqCallResults) {
if (reqCallResult.getException() != null) {
System.out.println(reqCallResult.getException().getMessage());
return;
}
System.out.println(reqCallResult.getResponse().getRequestID());
System.out.println(reqCallResult.getResponse().getHTTPStatusCode());
System.out.println(Jsons.DEFAULT_GSON.toJson(reqCallResult.getResponse()));
}
} catch (ExecutionException | InterruptedException apiException) {
apiException.printStackTrace();
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kubuto/oapi-sdk-java.git
git@gitee.com:kubuto/oapi-sdk-java.git
kubuto
oapi-sdk-java
飞书服务端SDK java
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891