Browse Source

飞书登录

syh 5 years ago
parent
commit
a06ee744ac

+ 0 - 3
feishu-sdk/src/main/java/cn/feishu/sdk/Test.java

@@ -2,13 +2,10 @@ package cn.feishu.sdk;
 
 import cn.feishu.sdk.provider.AuthProvider;
 
-import java.io.UnsupportedEncodingException;
-
 public class Test {
     public static void main(String[] args){
         AuthProvider authProvider = new AuthProvider();
         try {
-//            authProvider.getAuthUrl("state");
             authProvider.getAppAccessToken();
             authProvider.getTenantAccessToken();
         } catch (Exception e) {

+ 27 - 0
feishu-sdk/src/main/java/cn/feishu/sdk/provider/AuthProvider.java

@@ -4,15 +4,30 @@ import cn.feishu.sdk.common.ApiConstant;
 import cn.feishu.sdk.util.HttpUtil;
 import cn.feishu.sdk.util.PropertiesUtils;
 import com.alibaba.fastjson.JSONObject;
+
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URLEncoder;
 
 public class AuthProvider {
+    /**
+     *  获取授权url
+     * @param state
+     * @return
+     * @throws UnsupportedEncodingException
+     * @throws MalformedURLException
+     */
     public String getAuthUrl(String state) throws UnsupportedEncodingException, MalformedURLException {
         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);
     }
+
+    /**
+     * 根据code
+     * @param code
+     * @return
+     * @throws Exception
+     */
     public JSONObject getAccessToken(String code) throws Exception {
         JSONObject params = new JSONObject();
         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);
     }
 
+    /**
+     * 获取企业自建应用token信息
+     * 调用接口获取应用资源时使用
+     * @return
+     * @throws Exception
+     */
     public String getAppAccessToken() throws Exception {
         JSONObject params = new JSONObject();
         params.put("app_id",ApiConstant.FEISHU_APP_ID);
@@ -47,6 +68,12 @@ public class AuthProvider {
         }
     }
 
+    /**
+     * 获取企业自建应用租户token
+     * 调用接口获取企业资源时使用
+     * @return
+     * @throws Exception
+     */
     public String getTenantAccessToken() throws Exception {
         JSONObject params = new JSONObject();
         params.put("app_id",ApiConstant.FEISHU_APP_ID);

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java

@@ -65,6 +65,11 @@ public class LoginController {
     private ISysDepartService sysDepartService;
     @Autowired
     private ICtopCorpWexinUserService ctopCorpWexinUserService;
+    @GetMapping("feishu/auth")
+    public String feishuAuth(String code){
+
+        return "";
+    }
 
     @RequestMapping(value = "/wxlogin", method = RequestMethod.POST)
     @ApiOperation("企业微信登录接口")