提交 a6ba09e3 authored 作者: 吕本才's avatar 吕本才

增加网页授权的参数redirectUri

上级 dcddcdb7
......@@ -5,11 +5,12 @@ import com.google.gson.JsonParser;
import com.lark.oapi.Client;
import com.lark.oapi.core.request.RequestOptions;
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.GetUserInfoRespBody;
import com.sfa.common.core.exception.auth.NotLoginException;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.HashMap;
......@@ -22,7 +23,9 @@ import java.util.HashMap;
@Slf4j
@Component
public class FeiShuUtil {
//飞书获取用户信息,注意值:最后的斜杆
@Value("${feishu.redirectUri:http://localhost:81/}")
private String redirectUri;
/**
* 根据用户的登录临时code获取useraccessToken
*/
......@@ -32,14 +35,17 @@ public class FeiShuUtil {
bodyMap.put("grant_type", "authorization_code");
bodyMap.put("client_id", "cli_a7dbe3ec7d9e5013");
bodyMap.put("client_secret", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo");
bodyMap.put("redirect_uri", redirectUri);
bodyMap.put("code", code);
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();
Response execute = client.newCall(build).execute();
JSONObject rj = JSONObject.parseObject(execute.body().string());
if (!rj.containsKey("access_token")){
log.error("飞书用户获取失败!",rj.toString());
throw new NotLoginException("飞书用户获取失败");
}
return rj.getString("access_token");
......@@ -72,4 +78,4 @@ public class FeiShuUtil {
private Client getClient() {
return Client.newBuilder("cli_a7dbe3ec7d9e5013", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo").build();
}
}
\ No newline at end of file
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论