修改企业端单点登录

wushunjie
吴顺杰 11 months ago
parent cf31a4415e
commit b191d6140b

@ -21,7 +21,7 @@ public interface BmsEnterpriseBasicInfoMapper extends BaseMapper<BmsEnterpriseBa
* @param bmsEnterpriseBasicInfo * @param bmsEnterpriseBasicInfo
* @return * @return
*/ */
public Page<BmsEnterpriseBasicInfo> page(Page<BmsEnterpriseBasicInfo> page,@Param("req") BmsEnterpriseBasicInfo bmsEnterpriseBasicInfo); public Page<BmsEnterpriseBasicInfo> page(Page<BmsEnterpriseBasicInfo> page, @Param("req") BmsEnterpriseBasicInfo bmsEnterpriseBasicInfo);
/** /**
@ -36,8 +36,17 @@ public interface BmsEnterpriseBasicInfoMapper extends BaseMapper<BmsEnterpriseBa
* *
*/ */
List<BmsEnterpriseBasicInfo> workSearch(@Param("req") EnterpriseInfoWorkRequest enterpriseInfoWorkRequest); List<BmsEnterpriseBasicInfo> workSearch(@Param("req") EnterpriseInfoWorkRequest enterpriseInfoWorkRequest);
/** /**
* id * id
*/ */
BmsEnterpriseBasicInfo selectGetCreditCode(String getCreditCode); BmsEnterpriseBasicInfo selectGetCreditCode(String getCreditCode);
/**
*
*
* @param uscc
* @return
*/
BmsEnterpriseBasicInfo findByQytyxydm(@Param("uscc") String uscc);
} }

@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@ -35,7 +34,7 @@ public class SmsEnterChange {
@Value("${isTiming}") @Value("${isTiming}")
private Boolean isTiming; private Boolean isTiming;
// 每三小时执行一次 // 每三小时执行一次
@Scheduled(cron = "0 0 */3 * * *") @Scheduled(cron = "0 0 */12 * * *")
private void runTask() { private void runTask() {
if(isTiming){ if(isTiming){
//查询初审的所有用户 //查询初审的所有用户

@ -5,11 +5,11 @@ package com.ruoyi.jjh.declaration.single.controller;
* @since 2024/5/22 15:50 * @since 2024/5/22 15:50
*/ */
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
@ -32,7 +32,10 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -44,14 +47,13 @@ import java.util.concurrent.TimeUnit;
@RequestMapping("/system/singlelogin") @RequestMapping("/system/singlelogin")
public class SingleLoginController { public class SingleLoginController {
private static final Logger log = LoggerFactory.getLogger(SingleLoginController.class); private static final Logger log = LoggerFactory.getLogger(SingleLoginController.class);
@Value("${url}") @Value("${url}")
private String url; private String url;
@Value("${infoUrl}") @Value("${infoUrl}")
private String infoUrl; private String infoUrl;
@Value("${logoutUrl}") @Value("${logoutUrl}")
private String logoutUrl; private String logoutUrl;
@ -69,16 +71,17 @@ public class SingleLoginController {
@Value("${enterpriseAppId}") @Value("${enterpriseAppId}")
private String enterpriseAppId; private String enterpriseAppId;
@Value("${enterpriseAppsecret}")
private String enterpriseAppsecret;
/** /**
* *
*
* @return
*/ */
@ApiOperation("统一登陆") @ApiOperation("统一登陆")
@GetMapping("/login") @GetMapping("/login")
public void login(HttpServletResponse response) throws IOException { public void login(HttpServletResponse response) throws IOException {
//变成参数模式,appid 用于校验提交的来源地址,生产环境会校验,试用环境暂不校验 //变成参数模式,appid 用于校验提交的来源地址,生产环境会校验,试用环境暂不校验
String scUrl = "clientUrl=" + URLEncoder.encode(returnUrl, "UTF-8") + "?appid="+enterpriseAppId; String scUrl = "clientUrl=" + URLEncoder.encode(returnUrl, "UTF-8") + "?appid=" + enterpriseAppId;
//加密后的客户端地址 //加密后的客户端地址
scUrl = Base64.getEncoder().encodeToString(scUrl.getBytes()); scUrl = Base64.getEncoder().encodeToString(scUrl.getBytes());
//最终跳转地址 //最终跳转地址
@ -86,10 +89,6 @@ public class SingleLoginController {
// 添加请求头 // 添加请求头
response.setHeader("Content-Type", "application/json"); response.setHeader("Content-Type", "application/json");
response.setHeader("X-Requested-With", "XMLHttpRequest"); response.setHeader("X-Requested-With", "XMLHttpRequest");
// Map<String, String> stringStringMap = singleLoginService.generationHeader();
// response.setHeader("time",stringStringMap.get("time"));
// response.setHeader("appid",stringStringMap.get("appid"));
// response.setHeader("sign",stringStringMap.get("sign"));
response.sendRedirect(jumpurl); response.sendRedirect(jumpurl);
} }
@ -97,16 +96,16 @@ public class SingleLoginController {
/** /**
* *
* *
* @return * @return
*/ */
@ApiOperation(value = "获取用户信息",response = UserResponse.class) @ApiOperation(value = "获取用户信息", response = UserResponse.class)
@GetMapping("/getInfo") @GetMapping("/getInfo")
public AjaxResult getInfo(@RequestParam("clientToken") String clientToken) throws Exception { public AjaxResult getInfo(String clientToken) throws Exception {
String url = infoUrl + "?clienttoken=" + clientToken; HttpResponse response = HttpUtil.createGet(infoUrl)
HttpResponse response = HttpUtil.createGet(url) .form("clienttoken", clientToken)
// .addHeaders(singleLoginService.generationHeader()) // .addHeaders(generationHeader())
.execute(); .execute();
String responseBody = null; String responseBody;
// 获取响应状态码 // 获取响应状态码
int statusCode = response.getStatus(); int statusCode = response.getStatus();
if (statusCode == 200) { if (statusCode == 200) {
@ -119,30 +118,28 @@ public class SingleLoginController {
// 将用户信息存储到Redis中 // 将用户信息存储到Redis中
String key = "user:" + clientToken; String key = "user:" + clientToken;
//判断是法人用户 //判断是法人用户
if("ep".equals(dataObj.get("usertype"))){ if ("ep".equals(dataObj.get("usertype"))) {
JSONObject mainobj = dataObj.getJSONObject("mainbody"); JSONObject mainobj = dataObj.getJSONObject("mainbody");
UserResponse res = JSONUtil.toBean(dataObj, UserResponse.class); UserResponse res = JSONUtil.toBean(dataObj, UserResponse.class);
UserMainResponse req = JSONUtil.toBean(mainobj, UserMainResponse.class); UserMainResponse req = JSONUtil.toBean(mainobj, UserMainResponse.class);
//如果在企业库里面找不到该企业就返回错误 //如果在企业库里面找不到该企业就返回错误
QueryWrapper<BmsEnterpriseBasicInfo> queryWrapper = new QueryWrapper<>(); BmsEnterpriseBasicInfo bmsEnterpriseBasicInfo = bmsEnterpriseBasicInfoMapper.findByQytyxydm(req.getUscc());
queryWrapper.eq("tyshxydm", req.getUscc());
BmsEnterpriseBasicInfo bmsEnterpriseBasicInfo = bmsEnterpriseBasicInfoMapper.selectOne(queryWrapper);
Long id; Long id;
if (bmsEnterpriseBasicInfo == null) { if (bmsEnterpriseBasicInfo == null) {
throw new ServiceException("该企业不在库!请稍后再试!"); throw new ServiceException("该企业不在库!请稍后再试!");
}else { } else {
id = bmsEnterpriseBasicInfo.getId(); id = bmsEnterpriseBasicInfo.getId();
} }
// 设置过期时间为8小时 // 设置过期时间为8小时
String token = singleLoginService.singleLogin(req.getUscc(),req.getEpname(),id,"01",null); String token = singleLoginService.singleLogin(req.getUscc(), req.getEpname(), id, "01", null);
res.setToken(token); res.setToken(token);
res.setMain(req); res.setMain(req);
redisCache.setCacheObject(key, res, expirationSeconds, TimeUnit.MINUTES); redisCache.setCacheObject(key, res, expirationSeconds, TimeUnit.MINUTES);
return AjaxResult.success(res); return AjaxResult.success(res);
}else { } else {
log.error(response.body()); log.error(response.body());
throw new ServiceException("未知异常请联系管理员"); throw new ServiceException("该用户不是企业法人");
} }
} else { } else {
log.error(response.body()); log.error(response.body());
@ -150,24 +147,44 @@ public class SingleLoginController {
} }
} }
/**
* 退
*
* @param clienttoken clienttoken
* @return
*/
@ApiOperation(value = "退出登录") @ApiOperation(value = "退出登录")
@GetMapping("/enterpriseLogout") @GetMapping("/enterpriseLogout")
public AjaxResult enterpriseLogout(@RequestParam("clienttoken") String clienttoken) { public AjaxResult enterpriseLogout(@RequestParam("clienttoken") String clienttoken) {
String url = logoutUrl + "?clienttoken=" + clienttoken; String url = logoutUrl + "?clienttoken=" + clienttoken;
HttpResponse execute = HttpUtil.createGet(url) HttpResponse execute = HttpUtil.createGet(url)
// .addHeaders(singleLoginService.generationHeader()) // .addHeaders(generationHeader())
.execute(); .execute();
String str; String str;
// 获取响应状态码 // 获取响应状态码
int statusCode = execute.getStatus(); int statusCode = execute.getStatus();
if(statusCode==200){ if (statusCode == 200) {
str = "退出成功"; str = "退出成功";
}else { } else {
str = "退出失败"; str = "退出失败";
} }
return AjaxResult.success(str); return AjaxResult.success(str);
} }
/**
*
*
* @return
*/
private Map<String, String> generationHeader() {
// 定义时间格式化器
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
String format = LocalDateTime.now().format(formatter);
//正式端需要请求头
HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
headers.put("appid", enterpriseAppId);
headers.put("time", format);
headers.put("sign", DigestUtil.md5Hex(enterpriseAppId + enterpriseAppsecret + format));
return headers;
}
} }

@ -1,9 +1,8 @@
package com.ruoyi.jjh.declaration.single.service; package com.ruoyi.jjh.declaration.single.service;
import java.util.Map;
/** /**
* *
*
* @author du * @author du
* @since 2024/6/4 15:16 * @since 2024/6/4 15:16
*/ */
@ -12,11 +11,6 @@ public interface SingleLoginService {
/** /**
* token * token
*/ */
String singleLogin(String userName,String nickName,Long id,String userType,String phone); String singleLogin(String userName, String nickName, Long id, String userType, String phone);
/**
*
* @return
*/
Map<String,String> generationHeader();
} }

@ -1,8 +1,5 @@
package com.ruoyi.jjh.declaration.single.service.impl; package com.ruoyi.jjh.declaration.single.service.impl;
import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.json.JSONUtil;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.domain.model.LoginUser;
@ -15,7 +12,6 @@ import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.security.context.AuthenticationContextHolder; import com.ruoyi.framework.security.context.AuthenticationContextHolder;
import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.jjh.declaration.single.service.SingleLoginService; import com.ruoyi.jjh.declaration.single.service.SingleLoginService;
import com.ruoyi.jjh.declaration.single.util.HMAC256Config;
import com.ruoyi.jjh.ent.service.SmsAlertsService; import com.ruoyi.jjh.ent.service.SmsAlertsService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -26,9 +22,6 @@ import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -53,14 +46,11 @@ public class SingleLoginServiceImpl implements SingleLoginService {
@Value("${isTiming}") @Value("${isTiming}")
private Boolean isTiming; private Boolean isTiming;
@Value("${enterpriseAppId}")
private String enterpriseAppId;
/** /**
* token * token
*/ */
@Override @Override
public String singleLogin(String userName, String nickName, Long id, String userType,String phone) { public String singleLogin(String userName, String nickName, Long id, String userType, String phone) {
// 用户验证 // 用户验证
Authentication authentication; Authentication authentication;
try { try {
@ -70,11 +60,11 @@ public class SingleLoginServiceImpl implements SingleLoginService {
user.setPassword("admin123"); user.setPassword("admin123");
user.setPhonenumber(phone); user.setPhonenumber(phone);
Long[] roles = new Long[1]; Long[] roles = new Long[1];
if("01".equals(userType)){ if ("01".equals(userType)) {
roles[0]=101L; roles[0] = 101L;
}else if("02".equals(userType)){ } else if ("02".equals(userType)) {
//在这里可以判断具体要给什么权限 要给dept部门id //在这里可以判断具体要给什么权限 要给dept部门id
roles[0]=102L; roles[0] = 102L;
user.setDeptId(100L); user.setDeptId(100L);
user.setZwuser(userName); user.setZwuser(userName);
} }
@ -83,12 +73,11 @@ public class SingleLoginServiceImpl implements SingleLoginService {
user.setUserType(userType); user.setUserType(userType);
user.setEnterpriseId(id); user.setEnterpriseId(id);
//如果用户名也就是信用代码没有重复的就新增用户 //如果用户名也就是信用代码没有重复的就新增用户
if (userService.checkUserNameUnique(user)) if (userService.checkUserNameUnique(user)) {
{
user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
userService.insertUser(user); userService.insertUser(user);
if("02".equals(userType)&isTiming){ if ("02".equals(userType) & isTiming) {
if(user.getPhonenumber()!=null){ if (user.getPhonenumber() != null) {
smsAlertsService.addSsmPhone(user.getPhonenumber()); smsAlertsService.addSsmPhone(user.getPhonenumber());
} }
} }
@ -116,23 +105,5 @@ public class SingleLoginServiceImpl implements SingleLoginService {
return String.valueOf(token.get("access_token")); return String.valueOf(token.get("access_token"));
} }
/**
*
* @return
*/
@Override
public Map<String, String> generationHeader() {
// 定义时间格式化器
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
String format = LocalDateTime.now().format(formatter);
//正式端需要请求头
HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
headers.put("appid", enterpriseAppId);
headers.put("time", format);
headers.put("sign", DigestUtil.md5Hex(enterpriseAppId+"03f71c58-39e9-11ef-bbd6-fa163e2b2e10"+format));
return headers;
}
} }

@ -6,10 +6,10 @@ spring:
druid: druid:
# 主库数据源 # 主库数据源
master: master:
# url: jdbc:mysql://localhost:3306/jingji_hu?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # url: jdbc:mysql://localhost:3306/jingji_hu?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://39.101.188.84:3307/jingji_hu?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://39.101.188.84:3307/jingji_hu?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
# password: root # password: root
password: Admin123@ password: Admin123@
# 从库数据源 # 从库数据源
slave: slave:
@ -87,6 +87,8 @@ server:
#企业端测试环境应用系统编号 #企业端测试环境应用系统编号
enterpriseAppId: BwAWS8uh enterpriseAppId: BwAWS8uh
# 应用私钥
enterpriseAppsecret: 03f70874-39e9-11ef-bbd6-fa163e2b2e10
#企业端单点登陆url #企业端单点登陆url
url: https://qytt.sipac.gov.cn/api/usercenter/User/ssoLogin url: https://qytt.sipac.gov.cn/api/usercenter/User/ssoLogin
#企业端用户信息url #企业端用户信息url
@ -102,7 +104,7 @@ paramType: cs
smsV: oVFPU1y1wYJIatvqrGoTAE5ycguUyjaY smsV: oVFPU1y1wYJIatvqrGoTAE5ycguUyjaY
#工单编号 #工单编号
code: SC24071600001 code: SC24071600001
#PaaSID #短信PaaSID
paaSID: xdfwy paaSID: xdfwy
#短信token #短信token
smsToken: iM89cd4b0cGNVYAqKu7jl7EONyHgTa0N smsToken: iM89cd4b0cGNVYAqKu7jl7EONyHgTa0N

@ -116,10 +116,14 @@ isTiming: true
#企业端正式环境应用系统编号 #企业端正式环境应用系统编号
enterpriseAppId: 03f70874-39e9-11ef-bbd6-fa163e2b2e10 enterpriseAppId: 03f70874-39e9-11ef-bbd6-fa163e2b2e10
# 应用私钥
enterpriseAppsecret: 03f70874-39e9-11ef-bbd6-fa163e2b2e10
#企业端单点登陆url #企业端单点登陆url
url: https://qytt.sipac.gov.cn/api/usercenter/User/ssoLogin url: https://qytt.sipac.gov.cn/api/usercenter/User/ssoLogin
#url: http://114.216.202.175:8008/api/usercenter/User/ssoLogin
#企业端用户信息url #企业端用户信息url
infoUrl: https://qytt.sipac.gov.cn/api/usercenter/User/getInfo infoUrl: https://qytt.sipac.gov.cn/api/usercenter/User/getInfo
#infoUrl: http://114.216.202.175:8008/api/usercenter/User/getInfo
#短信发送接口 #短信发送接口
smsSend: http://zwyyone.sipac.gov.cn/ebus/szyqznzs/dx smsSend: http://zwyyone.sipac.gov.cn/ebus/szyqznzs/dx
@ -131,7 +135,7 @@ paramType: zs
smsV: 3b3jaDmYcf87Mk7NqEmzis=3AaaFeYmV4DIf smsV: 3b3jaDmYcf87Mk7NqEmzis=3AaaFeYmV4DIf
#工单编号 #工单编号
code: SC24071600001 code: SC24071600001
#PaaSID #短信PaaSID
paaSID: xdfwy paaSID: xdfwy
#短信token #短信token
smsToken: iM89cd4b0cGNVYAqKu7jl7EONyHgTa0N smsToken: iM89cd4b0cGNVYAqKu7jl7EONyHgTa0N

@ -34,7 +34,7 @@ spring:
# 国际化资源文件路径 # 国际化资源文件路径
basename: i18n/messages basename: i18n/messages
profiles: profiles:
active: druid active: internet
# 文件上传 # 文件上传
servlet: servlet:
multipart: multipart:

@ -31,4 +31,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where> </where>
</select> </select>
<select id="findByQytyxydm" resultType="com.ruoyi.jjh.declaration.entity.BmsEnterpriseBasicInfo">
select *
from bms_enterprise_basic_info
where tyshxydm = #{uscc}
</select>
</mapper> </mapper>
Loading…
Cancel
Save