添加日志
parent
b436c8d59d
commit
eb321aba7c
|
@ -4,6 +4,7 @@ import com.bocloud.sms.entity.AccountSecurity;
|
|||
import com.bocloud.sms.entity.SystemConfig;
|
||||
import com.bocloud.sms.entity.TenantAccount;
|
||||
import com.bocloud.sms.interfaces.TenantService;
|
||||
import com.bocloud.sms.interfaces.TrxService;
|
||||
import com.bocloud.sms.interfaces.UserService;
|
||||
import com.bocloud.sms.model.LoginModel;
|
||||
import com.bocloud.sms.repository.SystemConfigRepository;
|
||||
|
@ -49,6 +50,7 @@ public class LoginController {
|
|||
private final SystemConfigRepository systemConfigRepository;
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
private final LockFactory lockFactory;
|
||||
private final TrxService trxService;
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
|
@ -68,6 +70,8 @@ public class LoginController {
|
|||
log.info("开始调用UserService");
|
||||
GeneralResult<Map<String, Object>> loginResult = userService
|
||||
.login(account, password, request.getSession().getId(), IpTool.getIP(request), loginModel.getIsManager());
|
||||
log.info("请求方ip地址trx:" + trxService.getRequestIpAddress(request));
|
||||
log.info("请求方ip地址:" + IpTool.getIP(request));
|
||||
log.info("结束调用UserService");
|
||||
if (loginResult.isFailed()) {
|
||||
if (null == loginResult.getData()) {
|
||||
|
|
|
@ -36,7 +36,8 @@ public class TrxController {
|
|||
@Operation(summary = "用户登录")
|
||||
public GeneralResult<String> getAuthToken(@RequestBody TrxAuthModel trxAuthModel,
|
||||
HttpServletRequest request) {
|
||||
trxAuthModel.setClientIp(request.getRemoteAddr());
|
||||
String ipAddress = trxService.getRequestIpAddress(request);
|
||||
trxAuthModel.setClientIp(ipAddress);
|
||||
GeneralResult generalResult = trxService.getAuthToken(trxAuthModel);
|
||||
return generalResult;
|
||||
}
|
||||
|
@ -45,7 +46,8 @@ public class TrxController {
|
|||
@Operation(summary = "天融信用户登出")
|
||||
public GeneralResult<String> logout(@RequestBody TrxAuthModel trxAuthModel,
|
||||
HttpServletRequest request) {
|
||||
trxAuthModel.setClientIp(request.getRemoteAddr());
|
||||
String ipAddress = trxService.getRequestIpAddress(request);
|
||||
trxAuthModel.setClientIp(ipAddress);
|
||||
GeneralResult generalResult = trxService.logout(trxAuthModel);
|
||||
return generalResult;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.bocloud.sms.interfaces;
|
|||
|
||||
import com.bocloud.sms.model.TrxAuthModel;
|
||||
import com.megatron.common.model.GeneralResult;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
public interface TrxService {
|
||||
GeneralResult getRandomstr(String ngxCookie);
|
||||
|
@ -9,4 +10,6 @@ public interface TrxService {
|
|||
GeneralResult getAuthToken(TrxAuthModel trxAuthModel);
|
||||
|
||||
GeneralResult logout(TrxAuthModel trxAuthModel);
|
||||
|
||||
String getRequestIpAddress(HttpServletRequest request);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.megatron.common.encrypt.AESEncryptor;
|
|||
import com.megatron.common.encrypt.Encryptor;
|
||||
import com.megatron.common.model.GeneralResult;
|
||||
import com.megatron.common.model.RequestContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -61,10 +62,10 @@ public class TrxServiceImpl implements TrxService {
|
|||
paramsMap.put("ngx_cookie", ngxCookie);
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
log.info("调用天融信获取随机字符串接口, url:" + url + ", 参数:" + JSONObject.toJSONString(paramsMap));
|
||||
HttpResponse response = HttpRequest.get(url)
|
||||
.addHeaders(paramsMap)
|
||||
.execute();
|
||||
HttpRequest httpRequest = HttpRequest.get(url)
|
||||
.addHeaders(paramsMap);
|
||||
log.info("调用天融信获取随机字符串接口, url:" + httpRequest.getUrl() + "请求头:" + JSONObject.toJSONString(httpRequest.headers()));
|
||||
HttpResponse response = httpRequest.execute();
|
||||
result = JSONObject.parseObject(response.body());
|
||||
if ("-1".equals(result.getString("result"))) {
|
||||
return new GeneralResult(false, "获取随机数失败" + result.getString("errmsg"));
|
||||
|
@ -233,4 +234,21 @@ public class TrxServiceImpl implements TrxService {
|
|||
return appModules;
|
||||
}
|
||||
|
||||
public String getRequestIpAddress(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("X-Real-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue