|
@@ -20,6 +20,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -44,6 +46,13 @@ public class DingThirdTokenService {
|
|
|
return new Client(config);
|
|
|
}
|
|
|
|
|
|
+ public static com.aliyun.dingtalkcontact_1_0.Client createClient_1_0() throws Exception {
|
|
|
+ Config config = new Config();
|
|
|
+ config.protocol = "https";
|
|
|
+ config.regionId = "central";
|
|
|
+ return new com.aliyun.dingtalkcontact_1_0.Client(config);
|
|
|
+ }
|
|
|
+
|
|
|
public GetUserTokenResponse getUserAccessToken(String code) {
|
|
|
GetUserTokenResponse userToken = null;
|
|
|
try {
|
|
@@ -112,17 +121,6 @@ public class DingThirdTokenService {
|
|
|
return corpAccessToken;
|
|
|
}
|
|
|
|
|
|
- public Object q() {
|
|
|
- DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/service/get_corp_token");
|
|
|
- OapiServiceGetCorpTokenRequest req = new OapiServiceGetCorpTokenRequest();
|
|
|
- req.setAuthCorpid("dingc365fcxxxx");
|
|
|
- try {
|
|
|
- OapiServiceGetCorpTokenResponse execute = client.execute(req, dingAppConfig.getAppKey(), dingAppConfig.getAppSecret(), "suiteTicket");
|
|
|
- } catch (ApiException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
//服务商获取第三方应用授权企业的access_token
|
|
|
public String getThirdCorpAccessToken(String corpId) {
|
|
@@ -212,12 +210,6 @@ public class DingThirdTokenService {
|
|
|
return ssoUserInfoWithOptions;
|
|
|
}
|
|
|
|
|
|
- public com.aliyun.dingtalkcontact_1_0.Client createClient_1_0() throws Exception {
|
|
|
- Config config = new Config();
|
|
|
- config.protocol = "https";
|
|
|
- config.regionId = "central";
|
|
|
- return new com.aliyun.dingtalkcontact_1_0.Client(config);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* @description: 获取用户通讯录个人信息
|
|
@@ -253,6 +245,8 @@ public class DingThirdTokenService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /****************************************************企业应用授权***********************************************************/
|
|
|
+
|
|
|
//获取第三方企业应用的suite_access_token
|
|
|
public OapiServiceGetSuiteTokenResponse getSuiteToken(String corpId) {
|
|
|
OapiServiceGetSuiteTokenResponse rsp = null;
|
|
@@ -316,28 +310,101 @@ public class DingThirdTokenService {
|
|
|
}
|
|
|
return rsp;
|
|
|
}
|
|
|
-//
|
|
|
-// public OapiServiceGetUnactiveCorpResponse getUnactiveCorpResponseetUnactiveCorpResponse(Long appId,String suiteAccessToken) {
|
|
|
-// OapiServiceGetUnactiveCorpResponse rsp = null;
|
|
|
-// try {
|
|
|
-// DingTalkClient client = new DefaultDingTalkClient(
|
|
|
-// "https://oapi.dingtalk.com/service/get_unactive_corp?suite_access_token="+suiteAccessToken+"");
|
|
|
-// OapiServiceGetUnactiveCorpRequest req = new OapiServiceGetUnactiveCorpRequest();
|
|
|
-// req.setAppId(appId);
|
|
|
-// rsp = client.execute(req);
|
|
|
-// } catch (TeaException err) {
|
|
|
-// if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
-// // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
-// log.error("getAccessToken failed", err.message);
|
|
|
-// }
|
|
|
-// } catch (Exception _err) {
|
|
|
-// TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
-// if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
-// // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
-// log.error("getAccessToken failed", err.message);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return rsp;
|
|
|
-// }
|
|
|
|
|
|
+ //获取应用未激活的企业列表
|
|
|
+ public OapiServiceGetUnactiveCorpResponse getUnactiveCorpResponse(Long appId, String suiteAccessToken) {
|
|
|
+ OapiServiceGetUnactiveCorpResponse rsp = null;
|
|
|
+ try {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient(
|
|
|
+ "https://oapi.dingtalk.com/service/get_unactive_corp?suite_access_token=" + suiteAccessToken + "");
|
|
|
+ OapiServiceGetUnactiveCorpRequest req = new OapiServiceGetUnactiveCorpRequest();
|
|
|
+ req.setAppId(appId);
|
|
|
+ rsp = client.execute(req);
|
|
|
+ } catch (TeaException err) {
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
+ log.error("getAccessToken failed", err.message);
|
|
|
+ }
|
|
|
+ } catch (Exception _err) {
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
+ log.error("getAccessToken failed", err.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rsp;
|
|
|
+ }
|
|
|
+
|
|
|
+ //重新授权未激活应用的企业
|
|
|
+ public OapiServiceReauthCorpResponse getReauthCorpResponse(String appId, String suiteAccessToken, List<String> corpidList) {
|
|
|
+ OapiServiceReauthCorpResponse rsp = null;
|
|
|
+ try {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/service/reauth_corp?suite_access_token=" + suiteAccessToken + "");
|
|
|
+ OapiServiceReauthCorpRequest req = new OapiServiceReauthCorpRequest();
|
|
|
+ req.setAppId(appId);
|
|
|
+ req.setCorpidList(corpidList);
|
|
|
+ rsp = client.execute(req);
|
|
|
+ } catch (TeaException err) {
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
+ log.error("getAccessToken failed", err.message);
|
|
|
+ }
|
|
|
+ } catch (Exception _err) {
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
+ log.error("getAccessToken failed", err.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rsp;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取企业开通应用后的授权信息
|
|
|
+ public GetAuthInfoResponse getAuthInfoResponse(String corpId, String xAcsDingtalkAccessToken) {
|
|
|
+ GetAuthInfoResponse rsp = null;
|
|
|
+ String redisKeyPrefix = Constants.DAILY_DING_AUTH + corpId + ":";
|
|
|
+ // 从持久化存储中读取
|
|
|
+ try {
|
|
|
+ GetAuthInfoHeaders getAuthInfoHeaders = new GetAuthInfoHeaders();
|
|
|
+ getAuthInfoHeaders.xAcsDingtalkAccessToken = xAcsDingtalkAccessToken;
|
|
|
+ GetAuthInfoRequest getAuthInfoRequest = new GetAuthInfoRequest()
|
|
|
+ .setAuthCorpId(corpId);
|
|
|
+ // 第三方企业应用的填写应用SuiteKey和SuiteSecret。
|
|
|
+ // 定制应用填写应用的CustomKey和CustomSecret。
|
|
|
+ rsp = this.createClient2_1_0().getAuthInfoWithOptions(getAuthInfoRequest, getAuthInfoHeaders, new RuntimeOptions());
|
|
|
+ } catch (TeaException err) {
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
+ log.error("getAccessToken failed", err.message);
|
|
|
+ }
|
|
|
+ } catch (Exception _err) {
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
+ log.error("getAccessToken failed", err.message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rsp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /***********************************************************************************/
|
|
|
+ //获取jsapiTicket
|
|
|
+ public CreateJsapiTicketResponse createJsapiTicketResponse(String xAcsDingtalkAccessToken) {
|
|
|
+ CreateJsapiTicketResponse rsp = null;
|
|
|
+ try {
|
|
|
+ com.aliyun.dingtalkoauth2_1_0.models.CreateJsapiTicketHeaders createJsapiTicketHeaders = new com.aliyun.dingtalkoauth2_1_0.models.CreateJsapiTicketHeaders();
|
|
|
+ createJsapiTicketHeaders.xAcsDingtalkAccessToken = xAcsDingtalkAccessToken;
|
|
|
+ rsp = this.createClient2_1_0().createJsapiTicketWithOptions(createJsapiTicketHeaders, new RuntimeOptions());
|
|
|
+ } catch (TeaException err) {
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
+ }
|
|
|
+ } catch (Exception _err) {
|
|
|
+ TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
+ if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
+ // err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return rsp;
|
|
|
+ }
|
|
|
}
|