|
|
|
@ -9,9 +9,15 @@ import cn.hutool.crypto.digest.DigestUtil;
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
|
import com.ruoyi.gysl.entity.BasicInformation;
|
|
|
|
|
import com.ruoyi.gysl.login.dto.response.UserMainResponse;
|
|
|
|
|
import com.ruoyi.gysl.login.dto.response.UserResponse;
|
|
|
|
|
import com.ruoyi.gysl.login.service.LoginTokenService;
|
|
|
|
|
import com.ruoyi.gysl.service.BasicInformationService;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
@ -38,7 +44,6 @@ import java.util.Map;
|
|
|
|
|
@RequestMapping("/system/singlelogin")
|
|
|
|
|
public class SingleLoginController {
|
|
|
|
|
|
|
|
|
|
private static final String BOUNDARY = "----WebKitFormBoundary7MA4YWxkTrZu0gW"; // 边界字符串(需唯一)
|
|
|
|
|
|
|
|
|
|
@Value("${url}")
|
|
|
|
|
private String url;
|
|
|
|
@ -62,6 +67,9 @@ public class SingleLoginController {
|
|
|
|
|
@Value("${enterpriseAppsecret}")
|
|
|
|
|
private String enterpriseAppsecret;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private BasicInformationService basicInformationService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 统一登陆
|
|
|
|
|
*/
|
|
|
|
@ -69,7 +77,7 @@ public class SingleLoginController {
|
|
|
|
|
@GetMapping("/login")
|
|
|
|
|
public void login(HttpServletResponse response) throws IOException {
|
|
|
|
|
//变成参数模式,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());
|
|
|
|
|
//最终跳转地址
|
|
|
|
@ -89,44 +97,42 @@ public class SingleLoginController {
|
|
|
|
|
@ApiOperation(value = "获取用户信息", response = UserResponse.class)
|
|
|
|
|
@GetMapping("/getInfo")
|
|
|
|
|
public AjaxResult getInfo(String clientToken) throws Exception {
|
|
|
|
|
String url = infoUrl + "?clienttoken=" + clientToken;
|
|
|
|
|
HttpResponse response = HttpRequest.get(URLEncoder.encode(url, "UTF-8"))
|
|
|
|
|
HttpResponse response = HttpRequest.get(infoUrl)
|
|
|
|
|
.form("clienttoken", clientToken)
|
|
|
|
|
.addHeaders(generationHeader())
|
|
|
|
|
.execute();
|
|
|
|
|
System.out.println(url);
|
|
|
|
|
System.out.println("appid:"+enterpriseAppId);
|
|
|
|
|
System.out.println("time:"+generationHeader().get("time"));
|
|
|
|
|
System.out.println("sign:"+generationHeader().get("sign"));
|
|
|
|
|
System.out.println(response.body());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// String responseBody;
|
|
|
|
|
// 获取响应状态码
|
|
|
|
|
// int statusCode = response.getStatus();
|
|
|
|
|
// if (statusCode == 200) {
|
|
|
|
|
// // 获取响应内容
|
|
|
|
|
// responseBody = response.body();
|
|
|
|
|
// JSONObject jsonObj = JSONUtil.parseObj(responseBody);
|
|
|
|
|
// JSONObject dataObj = jsonObj.getJSONObject("data");
|
|
|
|
|
// //判断是法人用户
|
|
|
|
|
// if ("ep".equals(dataObj.get("usertype"))) {
|
|
|
|
|
// JSONObject mainobj = dataObj.getJSONObject("mainbody");
|
|
|
|
|
// UserResponse res = JSONUtil.toBean(dataObj, UserResponse.class);
|
|
|
|
|
// UserMainResponse req = JSONUtil.toBean(mainobj, UserMainResponse.class);
|
|
|
|
|
// String token = loginTokenService.singleLogin(req.getUscc(), req.getEpname(),
|
|
|
|
|
// "02", null, null);
|
|
|
|
|
// res.setToken(token);
|
|
|
|
|
// res.setMain(req);
|
|
|
|
|
// return AjaxResult.success(res);
|
|
|
|
|
// } else {
|
|
|
|
|
// log.error(response.body());
|
|
|
|
|
// throw new ServiceException("该用户不是企业法人");
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// log.error(response.body());
|
|
|
|
|
// throw new ServiceException("未知异常请联系管理员");
|
|
|
|
|
// }
|
|
|
|
|
return null;
|
|
|
|
|
String responseBody;
|
|
|
|
|
int statusCode = response.getStatus();
|
|
|
|
|
if (statusCode == 200) {
|
|
|
|
|
// 获取响应内容
|
|
|
|
|
responseBody = response.body();
|
|
|
|
|
JSONObject jsonObj = JSONUtil.parseObj(responseBody);
|
|
|
|
|
JSONObject dataObj = jsonObj.getJSONObject("data");
|
|
|
|
|
//判断是法人用户
|
|
|
|
|
if ("ep".equals(dataObj.get("usertype"))) {
|
|
|
|
|
JSONObject mainobj = dataObj.getJSONObject("mainbody");
|
|
|
|
|
UserResponse res = JSONUtil.toBean(dataObj, UserResponse.class);
|
|
|
|
|
UserMainResponse req = JSONUtil.toBean(mainobj, UserMainResponse.class);
|
|
|
|
|
Long count = basicInformationService.lambdaQuery()
|
|
|
|
|
.eq(BasicInformation::getTyshxydm, req.getUscc())
|
|
|
|
|
.or()
|
|
|
|
|
.eq(BasicInformation::getXmfrdwxz, req.getEpname()).count();
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
String token = loginTokenService.singleLogin(req.getUscc(), req.getEpname(),
|
|
|
|
|
"02", null, null);
|
|
|
|
|
res.setToken(token);
|
|
|
|
|
res.setMain(req);
|
|
|
|
|
return AjaxResult.success(res);
|
|
|
|
|
}else {
|
|
|
|
|
throw new ServiceException("贵公司无需参与苏州工业园区工业上楼相关填报工作。系统将即刻为您返回企业服务综合平台界面,以便您处理其他业务事宜!");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new ServiceException("该用户不是企业法人");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new ServiceException("未知异常请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|