|
@@ -4,15 +4,30 @@ import cn.feishu.sdk.common.ApiConstant;
|
|
import cn.feishu.sdk.util.HttpUtil;
|
|
import cn.feishu.sdk.util.HttpUtil;
|
|
import cn.feishu.sdk.util.PropertiesUtils;
|
|
import cn.feishu.sdk.util.PropertiesUtils;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.MalformedURLException;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
public class AuthProvider {
|
|
public class AuthProvider {
|
|
|
|
+ /**
|
|
|
|
+ * 获取授权url
|
|
|
|
+ * @param state
|
|
|
|
+ * @return
|
|
|
|
+ * @throws UnsupportedEncodingException
|
|
|
|
+ * @throws MalformedURLException
|
|
|
|
+ */
|
|
public String getAuthUrl(String state) throws UnsupportedEncodingException, MalformedURLException {
|
|
public String getAuthUrl(String state) throws UnsupportedEncodingException, MalformedURLException {
|
|
String redirectUri = PropertiesUtils.getConfig("callback_url");
|
|
String redirectUri = PropertiesUtils.getConfig("callback_url");
|
|
return HttpUtil.feishuGetRequestString(ApiConstant.FEISHU_API_URL+ApiConstant.AUTH_INDEX+"?redirect_uri="+ URLEncoder.encode(redirectUri,"UTF-8")+"&app_id="+ApiConstant.FEISHU_APP_ID+"&state="+state);
|
|
return HttpUtil.feishuGetRequestString(ApiConstant.FEISHU_API_URL+ApiConstant.AUTH_INDEX+"?redirect_uri="+ URLEncoder.encode(redirectUri,"UTF-8")+"&app_id="+ApiConstant.FEISHU_APP_ID+"&state="+state);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据code
|
|
|
|
+ * @param code
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
public JSONObject getAccessToken(String code) throws Exception {
|
|
public JSONObject getAccessToken(String code) throws Exception {
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
params.put("app_access_token",getAppAccessToken());
|
|
params.put("app_access_token",getAppAccessToken());
|
|
@@ -35,6 +50,12 @@ public class AuthProvider {
|
|
return HttpUtil.feishuGetRequest("Bearer user_access_token",ApiConstant.FEISHU_API_URL+ApiConstant.USER_INFO,params);
|
|
return HttpUtil.feishuGetRequest("Bearer user_access_token",ApiConstant.FEISHU_API_URL+ApiConstant.USER_INFO,params);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取企业自建应用token信息
|
|
|
|
+ * 调用接口获取应用资源时使用
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
public String getAppAccessToken() throws Exception {
|
|
public String getAppAccessToken() throws Exception {
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
params.put("app_id",ApiConstant.FEISHU_APP_ID);
|
|
params.put("app_id",ApiConstant.FEISHU_APP_ID);
|
|
@@ -47,6 +68,12 @@ public class AuthProvider {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取企业自建应用租户token
|
|
|
|
+ * 调用接口获取企业资源时使用
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
public String getTenantAccessToken() throws Exception {
|
|
public String getTenantAccessToken() throws Exception {
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
params.put("app_id",ApiConstant.FEISHU_APP_ID);
|
|
params.put("app_id",ApiConstant.FEISHU_APP_ID);
|