提交 7895e848 authored 作者: 吕本才's avatar 吕本才 提交者: Coding

Accept Merge Request #80: (qa -> master)

Merge Request: 增加网页授权的参数redirectUri Created By: @吕本才 Accepted By: @吕本才 URL: https://g-pkkp8204.coding.net/p/wangxiaolu-sfa/d/wangxiaolu-sfa-auth/git/merge/80
...@@ -5,11 +5,12 @@ import com.google.gson.JsonParser; ...@@ -5,11 +5,12 @@ import com.google.gson.JsonParser;
import com.lark.oapi.Client; import com.lark.oapi.Client;
import com.lark.oapi.core.request.RequestOptions; import com.lark.oapi.core.request.RequestOptions;
import com.lark.oapi.core.utils.Jsons; import com.lark.oapi.core.utils.Jsons;
import com.lark.oapi.okhttp.*;
import com.lark.oapi.service.authen.v1.model.GetUserInfoResp; import com.lark.oapi.service.authen.v1.model.GetUserInfoResp;
import com.lark.oapi.service.authen.v1.model.GetUserInfoRespBody; import com.lark.oapi.service.authen.v1.model.GetUserInfoRespBody;
import com.sfa.common.core.exception.auth.NotLoginException; import com.sfa.common.core.exception.auth.NotLoginException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.*; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
...@@ -22,7 +23,9 @@ import java.util.HashMap; ...@@ -22,7 +23,9 @@ import java.util.HashMap;
@Slf4j @Slf4j
@Component @Component
public class FeiShuUtil { public class FeiShuUtil {
//飞书获取用户信息,注意值:最后的斜杆
@Value("${feishu.redirectUri:http://localhost:81/}")
private String redirectUri;
/** /**
* 根据用户的登录临时code获取useraccessToken * 根据用户的登录临时code获取useraccessToken
*/ */
...@@ -32,14 +35,17 @@ public class FeiShuUtil { ...@@ -32,14 +35,17 @@ public class FeiShuUtil {
bodyMap.put("grant_type", "authorization_code"); bodyMap.put("grant_type", "authorization_code");
bodyMap.put("client_id", "cli_a7dbe3ec7d9e5013"); bodyMap.put("client_id", "cli_a7dbe3ec7d9e5013");
bodyMap.put("client_secret", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo"); bodyMap.put("client_secret", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo");
bodyMap.put("redirect_uri", redirectUri);
bodyMap.put("code", code); bodyMap.put("code", code);
OkHttpClient client = new OkHttpClient(); OkHttpClient client = new OkHttpClient();
RequestBody body = RequestBody.create(JSONObject.toJSONString(bodyMap), MediaType.get("application/json")); RequestBody body = RequestBody.create(MediaType.get("application/json"), JSONObject.toJSONString(bodyMap));
Request build = new Request.Builder().url("https://open.feishu.cn/open-apis/authen/v2/oauth/token").addHeader("Content-Type", "application/json; charset=utf-8").post(body).build(); Request build = new Request.Builder().url("https://open.feishu.cn/open-apis/authen/v2/oauth/token").addHeader("Content-Type", "application/json; charset=utf-8").post(body).build();
Response execute = client.newCall(build).execute(); Response execute = client.newCall(build).execute();
JSONObject rj = JSONObject.parseObject(execute.body().string()); JSONObject rj = JSONObject.parseObject(execute.body().string());
if (!rj.containsKey("access_token")){ if (!rj.containsKey("access_token")){
log.error("飞书用户获取失败!",rj.toString());
throw new NotLoginException("飞书用户获取失败"); throw new NotLoginException("飞书用户获取失败");
} }
return rj.getString("access_token"); return rj.getString("access_token");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论