|
|
@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
package UnitTest;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
|
|
|
|
|
import com.dingtalk.api.DingTalkClient;
|
|
|
|
|
|
|
|
import com.dingtalk.api.request.OapiGettokenRequest;
|
|
|
|
|
|
|
|
import com.dingtalk.api.response.OapiGettokenResponse;
|
|
|
|
|
|
|
|
import com.taobao.api.ApiException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TestDingTalk {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String corpId = "ding0b95901147fc6be0f2c783f7214b6d69";
|
|
|
|
|
|
|
|
public static final long agentId = 2619270936L;
|
|
|
|
|
|
|
|
public static final String appKey = "dingr94qyhpr8bflyxqz";
|
|
|
|
|
|
|
|
public static final String appSecret = "hnxZ93QqkGJpRyBziaR2vlbOPZo1U9eeqj73DfFuFnIxIUHNPbMR2DkIol9oGteh";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
功能:获取钉钉的Token,有效期7200秒,即2小时,每小时最好重新获取一次
|
|
|
|
|
|
|
|
作者:黄海
|
|
|
|
|
|
|
|
时间:2023-06-06
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String getToken() throws ApiException {
|
|
|
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
|
|
|
|
|
|
|
|
OapiGettokenRequest request = new OapiGettokenRequest();
|
|
|
|
|
|
|
|
request.setAppkey(appKey);
|
|
|
|
|
|
|
|
request.setAppsecret(appSecret);
|
|
|
|
|
|
|
|
request.setHttpMethod("GET");
|
|
|
|
|
|
|
|
OapiGettokenResponse response = client.execute(request);
|
|
|
|
|
|
|
|
return response.getBody();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args_) throws Exception {
|
|
|
|
|
|
|
|
System.out.println(getToken());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|