提交 8413a978 authored 作者: 000516's avatar 000516

修改qa\master配置文件

package com.sfa.auth; package com.sfa.auth;
import com.sfa.common.security.annotation.EnableRyFeignClients;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import com.sfa.common.security.annotation.EnableRyFeignClients; import org.springframework.context.annotation.ComponentScan;
/** /**
* 认证授权中心 * 认证授权中心
* *
* @author ruoyi * @author ruoyi
*/ */
@ComponentScan(basePackages = {"com.sfa.common.core.utils.sdk","com.sfa.auth"})
@EnableRyFeignClients @EnableRyFeignClients
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class }) @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
public class SfaAuthApplication public class SfaAuthApplication
......
...@@ -3,7 +3,8 @@ package com.sfa.auth.controller; ...@@ -3,7 +3,8 @@ package com.sfa.auth.controller;
import com.lark.oapi.service.authen.v1.model.GetUserInfoRespBody; import com.lark.oapi.service.authen.v1.model.GetUserInfoRespBody;
import com.sfa.auth.form.LoginBody; import com.sfa.auth.form.LoginBody;
import com.sfa.auth.service.SysLoginService; import com.sfa.auth.service.SysLoginService;
import com.sfa.auth.util.FeiShuUtil;
import com.sfa.common.core.utils.sdk.FeiShuUtil;
import com.sfa.common.security.service.TokenService; import com.sfa.common.security.service.TokenService;
import com.sfa.system.api.model.LoginUser; import com.sfa.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -29,9 +30,15 @@ public class FsTokenController { ...@@ -29,9 +30,15 @@ public class FsTokenController {
@PostMapping("/fs/login") @PostMapping("/fs/login")
public Map<String, Object> login(@RequestBody LoginBody form){ public Map<String, Object> login(@RequestBody LoginBody form){
String userAccessToken = feiShuUtil.createUserAccessToken(form.getCode()); String userAccessToken = feiShuUtil.createUserAccessToken(form.getCode(),FeiShuUtil.APP_LUZX);
GetUserInfoRespBody fsUserInfo = feiShuUtil.getUserInfo(userAccessToken); GetUserInfoRespBody fsUserInfo = feiShuUtil.getUserInfo(userAccessToken,FeiShuUtil.APP_LUZX);
LoginUser userInfo = sysLoginService.fsLogin(fsUserInfo.getEmployeeNo()); LoginUser userInfo = sysLoginService.fsLogin(fsUserInfo.getEmployeeNo());
return tokenService.createToken(userInfo); return tokenService.createToken(userInfo);
} }
@PostMapping("/fs/lb_login")
public GetUserInfoRespBody lbLogin(@RequestBody LoginBody form){
String userAccessToken = feiShuUtil.createUserAccessToken(form.getCode(),FeiShuUtil.APP_LBXY);
GetUserInfoRespBody fsUserInfo = feiShuUtil.getUserInfo(userAccessToken,FeiShuUtil.APP_LBXY);
return fsUserInfo;
}
} }
package com.sfa.auth.util; //package com.sfa.auth.util;
//
import com.alibaba.fastjson2.JSONObject; //import com.alibaba.fastjson2.JSONObject;
import com.google.gson.JsonParser; //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.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.enums.ECode; //import com.sfa.common.core.enums.ECode;
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 org.springframework.beans.factory.annotation.Value; //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;
//
/** ///**
* @author : liqiulin // * @author : liqiulin
* @date : 2024-12-06 16 // * @date : 2024-12-06 16
* @describe : // * @describe :
*/ // */
@Slf4j //@Slf4j
@Component //@Component
public class FeiShuUtil { //public class FeiShuUtil {
//飞书获取用户信息,注意值:最后的斜杆 // //飞书获取用户信息,注意值:最后的斜杆
@Value("${feishu.redirectUri}") // @Value("${feishu.redirectUri}")
private String redirectUri; // private String redirectUri;
/** //
* 根据用户的登录临时code获取useraccessToken // /**
*/ // * 根据用户的登录临时code获取useraccessToken
public String createUserAccessToken(String code) { // * 应用:链路中心
try { // */
HashMap<String, String> bodyMap = new HashMap<>(); // public String createUserAccessToken(String code) {
bodyMap.put("grant_type", "authorization_code"); // try {
bodyMap.put("client_id", "cli_a7dbe3ec7d9e5013"); // HashMap<String, String> bodyMap = new HashMap<>();
bodyMap.put("client_secret", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo"); // bodyMap.put("grant_type", "authorization_code");
bodyMap.put("redirect_uri", redirectUri); // bodyMap.put("client_id", "cli_a7dbe3ec7d9e5013");
// bodyMap.put("client_secret", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo");
bodyMap.put("code", code); // bodyMap.put("redirect_uri", redirectUri);
//
OkHttpClient client = new OkHttpClient(); // bodyMap.put("code", code);
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(); // OkHttpClient client = new OkHttpClient();
Response execute = client.newCall(build).execute(); // RequestBody body = RequestBody.create(MediaType.get("application/json"), JSONObject.toJSONString(bodyMap));
JSONObject rj = JSONObject.parseObject(execute.body().string()); // 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();
if (!rj.containsKey("access_token")){ // Response execute = client.newCall(build).execute();
log.error("飞书用户获取失败!",rj.toString()); // JSONObject rj = JSONObject.parseObject(execute.body().string());
throw new NotLoginException(ECode.FEISHU_ACCESS_TOKEN_ERROR); // if (!rj.containsKey("access_token")){
} // log.error("飞书用户获取失败!",rj.toString());
return rj.getString("access_token"); // throw new NotLoginException(ECode.FEISHU_ACCESS_TOKEN_ERROR);
} catch (Exception e) { // }
throw new NotLoginException(ECode.FEISHU_ACCESS_TOKEN_ERROR); // return rj.getString("access_token");
} // } catch (Exception e) {
} // throw new NotLoginException(ECode.FEISHU_ACCESS_TOKEN_ERROR);
// }
/** // }
* 根据用户的userAccessToken获取用户信息 //
*/ // /**
public GetUserInfoRespBody getUserInfo(String userAccessToken) { // * 根据用户的userAccessToken获取用户信息
try { // */
Client client = getClient(); // public GetUserInfoRespBody getUserInfo(String userAccessToken) {
GetUserInfoResp resp = client.authen().userInfo().get(RequestOptions.newBuilder() // try {
.userAccessToken(userAccessToken) // Client client = getClient();
.build()); // GetUserInfoResp resp = client.authen().userInfo().get(RequestOptions.newBuilder()
if (!resp.success()) { // .userAccessToken(userAccessToken)
log.error(String.format("code:%s,msg:%s,reqId:%s, resp:%s", // .build());
resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), "UTF-8"))))); // if (!resp.success()) {
return null; // log.error(String.format("code:%s,msg:%s,reqId:%s, resp:%s",
} // resp.getCode(), resp.getMsg(), resp.getRequestId(), Jsons.createGSON(true, false).toJson(JsonParser.parseString(new String(resp.getRawResponse().getBody(), "UTF-8")))));
return resp.getData(); // return null;
} catch (Exception e) { // }
log.error("获取用户信息失败,停止执行!"); // return resp.getData();
return null; // } catch (Exception e) {
} // log.error("获取用户信息失败,停止执行!");
} // return null;
// }
private Client getClient() { // }
return Client.newBuilder("cli_a7dbe3ec7d9e5013", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo").build(); //
} // /**
} // * 创建飞书客户端
// * 应用:链路中心
// */
// private Client getClient() {
// return Client.newBuilder("cli_a7dbe3ec7d9e5013", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo").build();
// }
//}
...@@ -13,3 +13,5 @@ spring: ...@@ -13,3 +13,5 @@ spring:
file-extension: yaml file-extension: yaml
group: sfa group: sfa
namespace: 9fb64726-e415-43e4-9e79-9be8d2666671 namespace: 9fb64726-e415-43e4-9e79-9be8d2666671
shared-configs:
- data-id: wangxiaolu-sfa-shared.yaml
\ No newline at end of file
spring:
application:
name: wangxiaolu-sfa-auth
cloud:
nacos:
discovery:
server-addr: 192.168.100.38:8848
group: sfa
namespace: 5ae12140-31d8-490a-9798-f923cb0e30d4
config:
server-addr: 192.168.100.38:8848
file-extension: yaml
group: sfa
namespace: 5ae12140-31d8-490a-9798-f923cb0e30d4
...@@ -13,3 +13,5 @@ spring: ...@@ -13,3 +13,5 @@ spring:
file-extension: yaml file-extension: yaml
group: sfa group: sfa
namespace: e2996044-6ddc-4988-8810-602e05d01ccf namespace: e2996044-6ddc-4988-8810-602e05d01ccf
shared-configs:
- data-id: wangxiaolu-sfa-shared.yaml
...@@ -13,3 +13,5 @@ spring: ...@@ -13,3 +13,5 @@ spring:
file-extension: yaml file-extension: yaml
group: sfa group: sfa
namespace: 24aed289-30a5-4e5c-8110-1b96281d1265 namespace: 24aed289-30a5-4e5c-8110-1b96281d1265
shared-configs:
- data-id: wangxiaolu-sfa-shared.yaml
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
class="ch.qos.logback.core.rolling.RollingFileAppender"> class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder> <encoder>
<pattern>${FILE_LOG_PATTERN}</pattern> <pattern>${FILE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder> </encoder>
<file>${LOG_PATH}/${MODEL_NAME}-today.log</file> <file>${LOG_PATH}/${MODEL_NAME}-today.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
...@@ -56,6 +57,7 @@ ...@@ -56,6 +57,7 @@
class="ch.qos.logback.core.rolling.RollingFileAppender"> class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder> <encoder>
<pattern>${FILE_LOG_PATTERN}</pattern> <pattern>${FILE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder> </encoder>
<file>${LOG_PATH}/${MODEL_NAME}-error-today.log</file> <file>${LOG_PATH}/${MODEL_NAME}-error-today.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论