企业端添加请求头

wushunjie
杜函宇 4 months ago
parent a10c439860
commit 68c0ec566b

@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@ -50,7 +51,7 @@ public class SmsEnterChange {
}
//查询复审的所有用户
SysUser user1 = new SysUser();
user.setDeptId(101L);
user1.setDeptId(101L);
Long count1 = iBmsDeclarationRecordsService.lambdaQuery().eq(BmsDeclarationRecords::getStatus, 2).count();
if(count1>0){
List<SysUser> list2 = sysUserMapper.selectUserList(user1);
@ -61,7 +62,7 @@ public class SmsEnterChange {
}
//查询终审的所有用户
SysUser user2 = new SysUser();
user.setDeptId(103L);
user2.setDeptId(103L);
Long count2 = iBmsDeclarationRecordsService.lambdaQuery().eq(BmsDeclarationRecords::getStatus, 3).count();
if(count2>0){
List<SysUser> list3 = sysUserMapper.selectUserList(user2);

@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Base64;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
@ -65,7 +66,8 @@ public class SingleLoginController {
@Resource
private BmsEnterpriseBasicInfoMapper bmsEnterpriseBasicInfoMapper;
@Value("${enterpriseAppId}")
private String enterpriseAppId;
/**
*
@ -76,7 +78,7 @@ public class SingleLoginController {
@GetMapping("/login")
public void login(HttpServletResponse response) throws IOException {
//变成参数模式,appid 用于校验提交的来源地址,生产环境会校验,试用环境暂不校验
String scUrl = "clientUrl=" + URLEncoder.encode(returnUrl, "UTF-8") + "?appid=BwAWS8uh";
String scUrl = "clientUrl=" + URLEncoder.encode(returnUrl, "UTF-8") + "?appid="+enterpriseAppId;
//加密后的客户端地址
scUrl = Base64.getEncoder().encodeToString(scUrl.getBytes());
//最终跳转地址
@ -84,7 +86,10 @@ public class SingleLoginController {
// 添加请求头
response.setHeader("Content-Type", "application/json");
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);
}
@ -98,7 +103,9 @@ public class SingleLoginController {
@GetMapping("/getInfo")
public AjaxResult getInfo(@RequestParam("clientToken") String clientToken) throws Exception {
String url = infoUrl + "?clienttoken=" + clientToken;
HttpResponse response = HttpUtil.createGet(url).execute();
HttpResponse response = HttpUtil.createGet(url)
// .addHeaders(singleLoginService.generationHeader())
.execute();
String responseBody = null;
// 获取响应状态码
int statusCode = response.getStatus();
@ -148,7 +155,9 @@ public class SingleLoginController {
@GetMapping("/enterpriseLogout")
public AjaxResult enterpriseLogout(@RequestParam("clienttoken") String clienttoken) {
String url = logoutUrl + "?clienttoken=" + clienttoken;
HttpResponse execute = HttpUtil.createGet(url).execute();
HttpResponse execute = HttpUtil.createGet(url)
// .addHeaders(singleLoginService.generationHeader())
.execute();
String str;
// 获取响应状态码
int statusCode = execute.getStatus();
@ -160,4 +169,5 @@ public class SingleLoginController {
return AjaxResult.success(str);
}
}

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

@ -1,5 +1,8 @@
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.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
@ -12,6 +15,7 @@ import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.framework.security.context.AuthenticationContextHolder;
import com.ruoyi.framework.web.service.TokenService;
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.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Value;
@ -22,6 +26,9 @@ import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
/**
@ -46,6 +53,12 @@ public class SingleLoginServiceImpl implements SingleLoginService {
@Value("${isTiming}")
private Boolean isTiming;
@Value("${enterpriseAppId}")
private String enterpriseAppId;
/**
* token
*/
@Override
public String singleLogin(String userName, String nickName, Long id, String userType,String phone) {
// 用户验证
@ -103,5 +116,23 @@ public class SingleLoginServiceImpl implements SingleLoginService {
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;
}
}

@ -62,8 +62,8 @@ spring:
config:
multi-statement-allow: true
#自己客户端地址
returnUrl: http://39.101.188.84:9999/demo/JinJiHu
#returnUrl: http://192.168.0.114:81
#returnUrl: http://39.101.188.84:9999/demo/JinJiHu
returnUrl: http://192.168.0.110:80
#定时任务更新企业信息和联系人的开启
isTiming: false
@ -85,6 +85,8 @@ server:
# Tomcat启动初始化的线程数默认值10
min-spare: 100
#企业端测试环境应用系统编号
enterpriseAppId: BwAWS8uh
#企业端单点登陆url
url: https://qytt.sipac.gov.cn/api/usercenter/User/ssoLogin
#企业端用户信息url

@ -114,6 +114,8 @@ returnUrl: https://idp.sipac.gov.cn/bms
#定时任务更新企业信息和联系人的开启
isTiming: true
#企业端正式环境应用系统编号
enterpriseAppId: 03f70874-39e9-11ef-bbd6-fa163e2b2e10
#企业端单点登陆url
url: https://qytt.sipac.gov.cn/api/usercenter/User/ssoLogin
#企业端用户信息url

@ -108,6 +108,7 @@ xss:
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
#企业端退出登录url
logoutUrl: https://qytt.sipac.gov.cn/api/usercenter/User/ssoLogOut
#政务端clientId
@ -122,7 +123,6 @@ getInfoId: https://qyt.sipac.gov.cn/enterprise-gateway/sipsg-enterprise/sys/thir
getAllInfo: http://uid.sipac.gov.cn/open/api/identity/data/FindUserById
#法人库-企业联络人员(统一社会信用代码)和法人库-法人基本信息(统一社会信用代码)生产环境
enterpriseUrl: http://172.21.10.46/api/invoke
#自己客户端地址
returnUrl: https://idp.sipac.gov.cn/bms

Loading…
Cancel
Save