|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.rongwei.bscommon.sys.feign.LoginAuth;
|
|
|
import com.rongwei.bscommon.sys.feign.RwAdminServerFeignService;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxLoginService;
|
|
|
import com.rongwei.bscommon.sys.utils.CxConstants;
|
|
@@ -12,19 +13,29 @@ import com.rongwei.commonservice.service.RedisService;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysUserDo;
|
|
|
import com.rongwei.rwadmincommon.system.domain.UserLoginVo;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysUserService;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.JwtAuthenticationRequest;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
+import java.net.URI;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author zhuang
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ZhcxLoginServiceImpl implements ZhcxLoginService {
|
|
|
|
|
|
@Autowired
|
|
@@ -33,6 +44,18 @@ public class ZhcxLoginServiceImpl implements ZhcxLoginService {
|
|
|
private RwAdminServerFeignService rwAdminServerFeignService;
|
|
|
@Autowired
|
|
|
private SysUserService sysUserService;
|
|
|
+ @Autowired
|
|
|
+ private LoginAuth loginAuth;
|
|
|
+ @Value("${sso.getTokenUrl}")
|
|
|
+ private String tokenUrl;
|
|
|
+ @Value("${sso.getUserInfoUrl}")
|
|
|
+ private String userUrl;
|
|
|
+ @Value("${sso.appid}")
|
|
|
+ private String appid;
|
|
|
+ @Value("${sso.appKey}")
|
|
|
+ private String appKey;
|
|
|
+ @Value("${sso.grantType}")
|
|
|
+ private String grantType;
|
|
|
|
|
|
@Override
|
|
|
public R loginIn(Map<String, Object> map) {
|
|
@@ -73,6 +96,9 @@ public class ZhcxLoginServiceImpl implements ZhcxLoginService {
|
|
|
if(StringUtils.isNotBlank(remark)){
|
|
|
contains = "skip".equals(sysUserDo.getRemark());
|
|
|
}
|
|
|
+ SysUserVo sysUserVo = new SysUserVo();
|
|
|
+ BeanUtils.copyProperties(sysUserDo, sysUserVo);
|
|
|
+ sysUserService.getUserRoleOrgPer(sysUserVo);
|
|
|
if(exist || contains){
|
|
|
Object yzmObj = redisService.getRedisCatchObj(CxConstants.LOGIN_SEND_CODE_PREFIX+loginType + account);
|
|
|
if(ObjectUtil.isEmpty(yzmObj) && !contains){
|
|
@@ -101,4 +127,65 @@ public class ZhcxLoginServiceImpl implements ZhcxLoginService {
|
|
|
return R.error("未获取到验证码或验证码已过期,请获取验证码");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R loginSso(String rid) {
|
|
|
+ Map<String, Object> loginMap = new HashMap<>(4);
|
|
|
+ if(StringUtils.isNotBlank(rid)){
|
|
|
+ try {
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(tokenUrl)
|
|
|
+ .queryParam("app_id", appid)
|
|
|
+ .queryParam("grant_type", grantType)
|
|
|
+ .queryParam("app_key", appKey)
|
|
|
+ .queryParam("code", rid);
|
|
|
+ URI uri = builder.build().toUri();
|
|
|
+ log.info("获取振华token远程地址:" + uri);
|
|
|
+ String result = restTemplate.getForObject(uri, String.class);
|
|
|
+ log.info("获取振华token远程调用返回结果:" + result);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ String access_token = jsonObject.getString("access_token");
|
|
|
+ String uid = jsonObject.getString("uid");
|
|
|
+ UriComponentsBuilder builder2 = UriComponentsBuilder.fromHttpUrl(userUrl)
|
|
|
+ .queryParam("app_id", appid)
|
|
|
+ .queryParam("uid", uid)
|
|
|
+ .queryParam("access_token", access_token);
|
|
|
+ URI uri2 = builder2.build().toUri();
|
|
|
+ log.info("获取振华用户信息远程调用地址:" + uri2);
|
|
|
+ String body = restTemplate.getForObject(uri2, String.class);
|
|
|
+ log.info("获取振华用户信息远程调用返回结果:" + body);
|
|
|
+ JSONObject info = JSONObject.parseObject(body);
|
|
|
+ if(info.getString("code").equals("200")){
|
|
|
+ JSONObject data = info.getJSONObject("data");
|
|
|
+ log.info("获取振华用户信息返回结果:" + data);
|
|
|
+ String mobile = data.getString("mobile");
|
|
|
+ LambdaQueryWrapper<SysUserDo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.and(i -> i.eq(SysUserDo::getMobile, mobile));
|
|
|
+ SysUserDo sysUserDo = sysUserService.getOne(queryWrapper);
|
|
|
+ if (sysUserDo != null) {
|
|
|
+ JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest(sysUserDo.getId(), sysUserDo.getAccount(), sysUserDo.getName());
|
|
|
+ jwtAuthenticationRequest.setExpire(-1);
|
|
|
+ Map<String, Object> tokenmap = loginAuth.getTokenInfo(jwtAuthenticationRequest);
|
|
|
+ String token = (String) tokenmap.get("token");
|
|
|
+ if ("ServerAbnormal".equals(token)) {
|
|
|
+ throw new Exception("认证服务异常");
|
|
|
+ }
|
|
|
+ //用户
|
|
|
+ SysUserVo sysUserVo = new SysUserVo();
|
|
|
+ BeanUtils.copyProperties(sysUserDo, sysUserVo);
|
|
|
+ sysUserService.getUserRoleOrgPer(sysUserVo);
|
|
|
+
|
|
|
+ loginMap.put("token", token);
|
|
|
+ loginMap.put("userInfo", sysUserVo);
|
|
|
+ //redis缓存登录用户信息
|
|
|
+ redisService.setLoginUser(token, sysUserVo);
|
|
|
+ return R.ok(loginMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
}
|