com.hn.dingtalk.AccessTokenUtil Maven / Gradle / Ivy
package com.hn.dingtalk;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.hn.dingtalk.constant.DingConstant;
import com.hn.dingtalk.constant.DingURLConstant;
import com.hn.dingtalk.exception.DingTalkException;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
/**
* 获取access_token工具类
* @author fei
*/
@Slf4j
public class AccessTokenUtil {
public static String getToken(){
try {
DefaultDingTalkClient client = new DefaultDingTalkClient(DingURLConstant.URL_GET_TOKKEN);
OapiGettokenRequest request = new OapiGettokenRequest();
request.setAppkey(DingConstant.APPKEY);
request.setAppsecret(DingConstant.APPSECRET);
request.setHttpMethod("GET");
OapiGettokenResponse response = client.execute(request);
String accessToken = response.getAccessToken();
return accessToken;
} catch (ApiException e) {
log.error("钉钉 getAccessToken failed", e);
throw new DingTalkException("钉钉 getAccessToken failed "+e.getErrMsg());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy