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

修改qa\master配置文件

package com.sfa.auth;
import com.sfa.common.security.annotation.EnableRyFeignClients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import com.sfa.common.security.annotation.EnableRyFeignClients;
import org.springframework.context.annotation.ComponentScan;
/**
* 认证授权中心
*
* @author ruoyi
*/
@ComponentScan(basePackages = {"com.sfa.common.core.utils.sdk","com.sfa.auth"})
@EnableRyFeignClients
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
public class SfaAuthApplication
......
......@@ -3,7 +3,8 @@ package com.sfa.auth.controller;
import com.lark.oapi.service.authen.v1.model.GetUserInfoRespBody;
import com.sfa.auth.form.LoginBody;
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.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -29,9 +30,15 @@ public class FsTokenController {
@PostMapping("/fs/login")
public Map<String, Object> login(@RequestBody LoginBody form){
String userAccessToken = feiShuUtil.createUserAccessToken(form.getCode());
GetUserInfoRespBody fsUserInfo = feiShuUtil.getUserInfo(userAccessToken);
String userAccessToken = feiShuUtil.createUserAccessToken(form.getCode(),FeiShuUtil.APP_LUZX);
GetUserInfoRespBody fsUserInfo = feiShuUtil.getUserInfo(userAccessToken,FeiShuUtil.APP_LUZX);
LoginUser userInfo = sysLoginService.fsLogin(fsUserInfo.getEmployeeNo());
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;
import com.alibaba.fastjson2.JSONObject;
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.enums.ECode;
import com.sfa.common.core.exception.auth.NotLoginException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.HashMap;
/**
* @author : liqiulin
* @date : 2024-12-06 16
* @describe :
*/
@Slf4j
@Component
public class FeiShuUtil {
//飞书获取用户信息,注意值:最后的斜杆
@Value("${feishu.redirectUri}")
private String redirectUri;
/**
* 根据用户的登录临时code获取useraccessToken
*/
public String createUserAccessToken(String code) {
try {
HashMap<String, String> bodyMap = new HashMap<>();
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(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(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) {
try {
Client client = getClient();
GetUserInfoResp resp = client.authen().userInfo().get(RequestOptions.newBuilder()
.userAccessToken(userAccessToken)
.build());
if (!resp.success()) {
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 null;
}
return resp.getData();
} catch (Exception e) {
log.error("获取用户信息失败,停止执行!");
return null;
}
}
private Client getClient() {
return Client.newBuilder("cli_a7dbe3ec7d9e5013", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo").build();
}
}
//package com.sfa.auth.util;
//
//import com.alibaba.fastjson2.JSONObject;
//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.enums.ECode;
//import com.sfa.common.core.exception.auth.NotLoginException;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//
//import java.util.HashMap;
//
///**
// * @author : liqiulin
// * @date : 2024-12-06 16
// * @describe :
// */
//@Slf4j
//@Component
//public class FeiShuUtil {
// //飞书获取用户信息,注意值:最后的斜杆
// @Value("${feishu.redirectUri}")
// private String redirectUri;
//
// /**
// * 根据用户的登录临时code获取useraccessToken
// * 应用:链路中心
// */
// public String createUserAccessToken(String code) {
// try {
// HashMap<String, String> bodyMap = new HashMap<>();
// 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(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(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) {
// try {
// Client client = getClient();
// GetUserInfoResp resp = client.authen().userInfo().get(RequestOptions.newBuilder()
// .userAccessToken(userAccessToken)
// .build());
// if (!resp.success()) {
// 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 null;
// }
// return resp.getData();
// } catch (Exception e) {
// log.error("获取用户信息失败,停止执行!");
// return null;
// }
// }
//
// /**
// * 创建飞书客户端
// * 应用:链路中心
// */
// private Client getClient() {
// return Client.newBuilder("cli_a7dbe3ec7d9e5013", "WxiT7uIJNDbDpEGfVCXEwNNfN1A3RgUo").build();
// }
//}
......@@ -13,3 +13,5 @@ spring:
file-extension: yaml
group: sfa
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:
file-extension: yaml
group: sfa
namespace: e2996044-6ddc-4988-8810-602e05d01ccf
shared-configs:
- data-id: wangxiaolu-sfa-shared.yaml
......@@ -13,3 +13,5 @@ spring:
file-extension: yaml
group: sfa
namespace: 24aed289-30a5-4e5c-8110-1b96281d1265
shared-configs:
- data-id: wangxiaolu-sfa-shared.yaml
......@@ -40,6 +40,7 @@
class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
<file>${LOG_PATH}/${MODEL_NAME}-today.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
......@@ -56,6 +57,7 @@
class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
<file>${LOG_PATH}/${MODEL_NAME}-error-today.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论