8 changed files with 332 additions and 48 deletions
@ -0,0 +1,48 @@ |
|||||
|
package com.zdxt.code.controller; |
||||
|
|
||||
|
import cn.hutool.core.util.IdUtil; |
||||
|
import com.zdxt.code.utils.HttpUtil; |
||||
|
import com.zdxt.code.utils.IdCardCryptoUtil; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Controller; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@RequestMapping("/siq") |
||||
|
@Controller |
||||
|
public class TestSIQController { |
||||
|
|
||||
|
@Value("${siq.code}") |
||||
|
private String code; |
||||
|
|
||||
|
@Value("${siq.secretKey}") |
||||
|
private String secretKey; |
||||
|
|
||||
|
@GetMapping("/getToken") |
||||
|
@ResponseBody |
||||
|
public void getToken(String userId,String userName){ |
||||
|
Map<String,Object> heardMap = new HashMap<>(); |
||||
|
Map<String,Object> paramsMap = new HashMap<>(); |
||||
|
try { |
||||
|
//加密后的
|
||||
|
System.out.println(secretKey); |
||||
|
String userIdCode = IdCardCryptoUtil.symmetricEncryptIdCard(secretKey, userId); |
||||
|
String userNameCode = IdCardCryptoUtil.symmetricEncryptIdCard(secretKey, userName); |
||||
|
System.out.println(userIdCode); |
||||
|
System.out.println(userNameCode);; |
||||
|
heardMap.put("x-auth-channel", IdUtil.simpleUUID()); |
||||
|
heardMap.put("x-auth-app-code",code); |
||||
|
// paramsMap.put("userId",userIdCode);
|
||||
|
// paramsMap.put("userName",userNameCode);
|
||||
|
String s = IdCardCryptoUtil.httpSendPost("http://egbpub.siqhz.com/egb/api/thirdauth/pub/auth/token", |
||||
|
userIdCode,userNameCode,code); |
||||
|
System.out.println(s); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,75 @@ |
|||||
|
package com.zdxt.code.controller; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.zdxt.code.domain.SiqLogin; |
||||
|
import com.zdxt.code.service.ThirdLoginService; |
||||
|
import com.zdxt.code.utils.HttpUtil; |
||||
|
import com.zdxt.code.utils.IdCardCryptoUtil; |
||||
|
import com.zdxt.common.ZDResponse; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Controller; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 第三方登录控制层 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Controller |
||||
|
@RequestMapping("/thirdLogin") |
||||
|
public class ThirdLoginController { |
||||
|
|
||||
|
|
||||
|
@Value("${siq.code}") |
||||
|
private String code; |
||||
|
|
||||
|
@Value("${siq.secretKey}") |
||||
|
private String secretKey; |
||||
|
|
||||
|
@Value("${siq.siqUrl}") |
||||
|
private String siqUrl; |
||||
|
|
||||
|
@Autowired |
||||
|
private ThirdLoginService thirdLoginService; |
||||
|
|
||||
|
/** |
||||
|
* 深i企用户登录 |
||||
|
* @param siqLogin |
||||
|
*/ |
||||
|
@PostMapping("/siqLogin") |
||||
|
@ResponseBody |
||||
|
public ZDResponse siqLogin(@RequestBody SiqLogin siqLogin){ |
||||
|
//敏感信息加密
|
||||
|
String userIdCode = IdCardCryptoUtil.symmetricEncryptIdCard(secretKey, siqLogin.getUserId()); |
||||
|
String userNameCode = IdCardCryptoUtil.symmetricEncryptIdCard(secretKey, siqLogin.getUserName()); |
||||
|
|
||||
|
//获取登录的token
|
||||
|
String token = IdCardCryptoUtil.httpSendPost(siqUrl + "/pub/auth/token", userIdCode, userNameCode, code); |
||||
|
Map<String, String> params = new HashMap<>(); |
||||
|
log.info("获取用户登录令牌:{}",token); |
||||
|
String secret = IdCardCryptoUtil.symmetricEncryptIdCard(secretKey, token); |
||||
|
params.put("accessKeySign",secret); |
||||
|
params.put("appCode",code); |
||||
|
String userInfo = null; |
||||
|
try { |
||||
|
userInfo = HttpUtil.HttpSendPost(siqUrl + "/pub/auth/getUserInfo", params, null, null); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
JSONObject jsonObject = JSONObject.parseObject(userInfo); |
||||
|
log.info("用户信息:{}",jsonObject.toJSONString()); |
||||
|
//添加深i企用户
|
||||
|
thirdLoginService.addSiqUser(jsonObject); |
||||
|
//添加深i企用户关联企业信息
|
||||
|
thirdLoginService.addSiqUserCompany(jsonObject); |
||||
|
|
||||
|
return thirdLoginService.siqLogin(jsonObject); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
package com.zdxt.code.domain; |
||||
|
|
||||
|
public class SiqLogin { |
||||
|
|
||||
|
/** |
||||
|
* 用户ID |
||||
|
*/ |
||||
|
private String userId; |
||||
|
|
||||
|
/** |
||||
|
* 用户姓名 |
||||
|
*/ |
||||
|
private String userName; |
||||
|
|
||||
|
public String getUserId() { |
||||
|
return userId; |
||||
|
} |
||||
|
|
||||
|
public void setUserId(String userId) { |
||||
|
this.userId = userId; |
||||
|
} |
||||
|
|
||||
|
public String getUserName() { |
||||
|
return userName; |
||||
|
} |
||||
|
|
||||
|
public void setUserName(String userName) { |
||||
|
this.userName = userName; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
package com.zdxt.code.service; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.zdxt.common.ZDResponse; |
||||
|
|
||||
|
/** |
||||
|
* 第三方登录业务层 |
||||
|
*/ |
||||
|
public interface ThirdLoginService { |
||||
|
|
||||
|
/** |
||||
|
* 深i企登录 |
||||
|
*/ |
||||
|
ZDResponse siqLogin(JSONObject jsonObject); |
||||
|
|
||||
|
/** |
||||
|
* 添加深i企用户 |
||||
|
* @param jsonObject |
||||
|
* @return |
||||
|
*/ |
||||
|
Boolean addSiqUser(JSONObject jsonObject); |
||||
|
|
||||
|
/** |
||||
|
* 添加深i企 |
||||
|
* @param jsonObject |
||||
|
* @return |
||||
|
*/ |
||||
|
Boolean addSiqUserCompany(JSONObject jsonObject); |
||||
|
|
||||
|
void siqTestLogin(String userId,String userName); |
||||
|
} |
||||
@ -0,0 +1,136 @@ |
|||||
|
package com.zdxt.code.service.impl; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.zdxt.auth.dto.UserBean; |
||||
|
import com.zdxt.auth.feign.UserApi; |
||||
|
import com.zdxt.code.domain.EnterpriseInformation; |
||||
|
import com.zdxt.code.service.IEnforcementRegistrationService; |
||||
|
import com.zdxt.code.service.IEnterpriseInformationService; |
||||
|
import com.zdxt.code.service.ThirdLoginService; |
||||
|
import com.zdxt.code.utils.HttpUtil; |
||||
|
import com.zdxt.code.utils.IdCardCryptoUtil; |
||||
|
import com.zdxt.common.ZDResponse; |
||||
|
import com.zdxt.common.util.DateUtils; |
||||
|
import com.zdxt.common.util.UserConstants; |
||||
|
import com.zdxt.domain.auth.User; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.apache.shiro.SecurityUtils; |
||||
|
import org.apache.shiro.authc.UsernamePasswordToken; |
||||
|
import org.apache.shiro.subject.Subject; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Service |
||||
|
public class ThirdLoginServiceImpl implements ThirdLoginService { |
||||
|
|
||||
|
|
||||
|
@Value("${siq.code}") |
||||
|
private String code; |
||||
|
|
||||
|
@Value("${siq.secretKey}") |
||||
|
private String secretKey; |
||||
|
|
||||
|
@Value("${siq.siqUrl}") |
||||
|
private String siqUrl; |
||||
|
|
||||
|
@Autowired |
||||
|
private UserApi userApi; |
||||
|
|
||||
|
@Autowired |
||||
|
private IEnterpriseInformationService enterpriseInformationService; |
||||
|
|
||||
|
@Override |
||||
|
public ZDResponse siqLogin(JSONObject jsonObject) { |
||||
|
|
||||
|
try { |
||||
|
//查询登录用户
|
||||
|
UserBean user = userApi.getUserByUserLoginName(jsonObject.getString("account")); |
||||
|
//本系统令牌
|
||||
|
UsernamePasswordToken sysToken = new UsernamePasswordToken(user.getLoginName(), user.getPassword(), false); |
||||
|
Subject subject = SecurityUtils.getSubject(); |
||||
|
subject.login(sysToken); |
||||
|
return ZDResponse.success("登录成功",user); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean addSiqUser(JSONObject jsonObject) { |
||||
|
if(UserConstants.USER_NAME_NOT_UNIQUE.equals(userApi.checkLoginNameUnique(jsonObject.getString("account")))){ |
||||
|
//新增用户信息
|
||||
|
UserBean userBean = new UserBean(); |
||||
|
//设置默认用户权限,权限为默认值
|
||||
|
userBean.setRoleId(178L); |
||||
|
//用户姓名
|
||||
|
userBean.setUserName(jsonObject.getString("contactName")); |
||||
|
//登录账号
|
||||
|
userBean.setLoginName(jsonObject.getString("account")); |
||||
|
//手机号码
|
||||
|
userBean.setPhonenumber(IdCardCryptoUtil.symmetricDecryptIdCard(secretKey,jsonObject.getString("account"))); |
||||
|
//设置为默认密码
|
||||
|
userBean.setPassword("123456"); |
||||
|
userBean.setCreateTime(DateUtils.getNowDate()); |
||||
|
// userBean.setUserId(Long.valueOf(userId));
|
||||
|
//部门ID设置为默认值
|
||||
|
userBean.setDeptId(405L); |
||||
|
|
||||
|
return userApi.insertUser(userBean) > 0 ? Boolean.TRUE : Boolean.FALSE; |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Boolean addSiqUserCompany(JSONObject jsonObject) { |
||||
|
//判断当前登录人是否已经在本系统中登记了企业信息
|
||||
|
EnterpriseInformation enterpriseInformation1 = new EnterpriseInformation(); |
||||
|
enterpriseInformation1.setEnterpriseNumber(jsonObject.getString("corpCid")); |
||||
|
List<EnterpriseInformation> enterpriseInformations = enterpriseInformationService.selectEnterpriseInformationList(enterpriseInformation1); |
||||
|
if(enterpriseInformations.size() == 0){ |
||||
|
//保存企业信息
|
||||
|
EnterpriseInformation enterpriseInformation = new EnterpriseInformation(); |
||||
|
//企业统一信用代码
|
||||
|
enterpriseInformation.setEnterpriseNumber(jsonObject.getString("corpCid")); |
||||
|
//企业名称
|
||||
|
enterpriseInformation.setEnterpriseName(jsonObject.getString("corpName")); |
||||
|
//经营范围
|
||||
|
enterpriseInformation.setBusinessScope(jsonObject.getString("businessScope")); |
||||
|
//注册地址
|
||||
|
enterpriseInformation.setEnterpriseAddress(jsonObject.getString("regLocation")); |
||||
|
//注册资金
|
||||
|
enterpriseInformation.setRegisteredCapital(jsonObject.getString("regCapital")); |
||||
|
//企业联系人电话
|
||||
|
enterpriseInformation.setEnterpriseTel(jsonObject.getString("contactTel")); |
||||
|
//企业法人
|
||||
|
enterpriseInformation.setLegalPerson(jsonObject.getString("legalPersonName")); |
||||
|
//营业时间
|
||||
|
//开始时间
|
||||
|
String termStart = jsonObject.getString("termStart"); |
||||
|
//结束时间 返回为空表示为永久
|
||||
|
String termEnd = jsonObject.getString("termEnd"); |
||||
|
//营业时间
|
||||
|
enterpriseInformation.setOperatingTerm(termStart+ "-" +termEnd); |
||||
|
|
||||
|
return enterpriseInformationService.insertEnterpriseInformation(enterpriseInformation) > 0 |
||||
|
? Boolean.TRUE : Boolean.FALSE; |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void siqTestLogin(String userId, String userName) { |
||||
|
//查询登录用户
|
||||
|
UserBean user = userApi.getUserByUserLoginName(userName); |
||||
|
//本系统令牌
|
||||
|
UsernamePasswordToken sysToken = new UsernamePasswordToken(user.getLoginName(), "123456", false); |
||||
|
Subject subject = SecurityUtils.getSubject(); |
||||
|
subject.login(sysToken); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue