单点登录处理
This commit is contained in:
parent
e1197aedc1
commit
bd16ff1485
|
|
@ -55,12 +55,7 @@
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.bonus.sgzb</groupId>
|
|
||||||
<artifactId>sgzb-modules-system</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
package com.bonus.sgzb.auth;
|
package com.bonus.sgzb.auth;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import com.bonus.sgzb.common.security.annotation.EnableRyFeignClients;
|
import com.bonus.sgzb.common.security.annotation.EnableRyFeignClients;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 认证授权中心
|
* 认证授权中心
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,12 @@ package com.bonus.sgzb.auth.controller;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.bonus.sgzb.auth.form.AuthenticationLoginFrom;
|
|
||||||
import com.bonus.sgzb.auth.form.LoginResultForm;
|
|
||||||
import com.bonus.sgzb.auth.service.NwUserLoginService;
|
|
||||||
import com.bonus.sgzb.common.core.constant.CacheConstants;
|
import com.bonus.sgzb.common.core.constant.CacheConstants;
|
||||||
import com.bonus.sgzb.common.redis.service.RedisService;
|
import com.bonus.sgzb.common.redis.service.RedisService;
|
||||||
import com.bonus.sgzb.system.api.RemoteUserService;
|
import com.bonus.sgzb.system.api.RemoteUserService;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisConnectionUtils;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import com.bonus.sgzb.auth.form.LoginBody;
|
import com.bonus.sgzb.auth.form.LoginBody;
|
||||||
import com.bonus.sgzb.auth.form.RegisterBody;
|
import com.bonus.sgzb.auth.form.RegisterBody;
|
||||||
|
|
@ -44,9 +40,6 @@ public class TokenController {
|
||||||
@Resource
|
@Resource
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private NwUserLoginService nwUserLoginService;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RemoteUserService remoteUserService;
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
|
@ -65,20 +58,6 @@ public class TokenController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("微服务平台认证接口")
|
|
||||||
@PostMapping(value = "/onlineApprove")
|
|
||||||
public R<?> onlineApprove(@RequestBody AuthenticationLoginFrom loginForm) {
|
|
||||||
if (loginForm == null || StringUtils.isBlank(loginForm.getType())) {
|
|
||||||
return R.fail("参数异常");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return nwUserLoginService.onlineApprove(loginForm);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("微服务平台认证登陆 异常: ", e);
|
|
||||||
return R.fail("微服务平台认证失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//App端登录
|
//App端登录
|
||||||
@PostMapping("loginApp")
|
@PostMapping("loginApp")
|
||||||
public R<?> loginApp(@RequestBody LoginBody form) {
|
public R<?> loginApp(@RequestBody LoginBody form) {
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
package com.bonus.sgzb.auth.form;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author:梁超
|
|
||||||
* @date:2024/1/26 - 14:02
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public enum OnlineApproveEnum {
|
|
||||||
WECHAT(3, NwLoginConstants.wechatAppId, NwLoginConstants.wechatAppsecret);
|
|
||||||
|
|
||||||
|
|
||||||
private final Integer code;
|
|
||||||
private final String appId;
|
|
||||||
private final String appsecret;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -25,9 +25,3 @@ spring:
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
|
||||||
|
|
||||||
onlineApprove: /lbcloud-oauth/oauth/token
|
|
||||||
wechatAppId: hYmcqenX
|
|
||||||
wechatAppsecret: ff36270b4bfac1cc366bb2f969798f2d94cfe58d
|
|
||||||
getNowPersonDetailData: /lbcloud-user/user/queryLoginUserInfo
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,11 @@ import com.bonus.sgzb.system.api.domain.SysDept;
|
||||||
import com.bonus.sgzb.system.api.domain.SysRole;
|
import com.bonus.sgzb.system.api.domain.SysRole;
|
||||||
import com.bonus.sgzb.system.api.domain.SysUser;
|
import com.bonus.sgzb.system.api.domain.SysUser;
|
||||||
import com.bonus.sgzb.system.api.model.LoginUser;
|
import com.bonus.sgzb.system.api.model.LoginUser;
|
||||||
|
import com.bonus.sgzb.system.domain.AuthenticationLoginFrom;
|
||||||
import com.bonus.sgzb.system.service.*;
|
import com.bonus.sgzb.system.service.*;
|
||||||
|
import com.bonus.sgzb.system.service.impl.NwUserLoginService;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
@ -41,6 +45,7 @@ import java.util.stream.Collectors;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/user")
|
@RequestMapping("/user")
|
||||||
|
@Slf4j
|
||||||
public class SysUserController extends BaseController
|
public class SysUserController extends BaseController
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -67,6 +72,9 @@ public class SysUserController extends BaseController
|
||||||
@Resource
|
@Resource
|
||||||
private RemoteUserService remoteUserService;
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NwUserLoginService nwUserLoginService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户列表
|
* 获取用户列表
|
||||||
*/
|
*/
|
||||||
|
|
@ -386,4 +394,19 @@ public class SysUserController extends BaseController
|
||||||
public AjaxResult getUserByRoleList(SysUser sysUser) {
|
public AjaxResult getUserByRoleList(SysUser sysUser) {
|
||||||
return success(userService.getUserByRoleList(sysUser));
|
return success(userService.getUserByRoleList(sysUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("微服务平台认证接口")
|
||||||
|
@PostMapping(value = "/onlineApprove")
|
||||||
|
public R<?> onlineApprove(@RequestBody AuthenticationLoginFrom loginForm) {
|
||||||
|
if (loginForm == null || StringUtils.isBlank(loginForm.getType())) {
|
||||||
|
return R.fail("参数异常");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return nwUserLoginService.onlineApprove(loginForm);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("微服务平台认证登陆 异常: ", e);
|
||||||
|
return R.fail("微服务平台认证失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bonus.sgzb.auth.form;
|
package com.bonus.sgzb.system.domain;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bonus.sgzb.auth.form;
|
package com.bonus.sgzb.system.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bonus.sgzb.auth.form;
|
package com.bonus.sgzb.system.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bonus.sgzb.auth.form;
|
package com.bonus.sgzb.system.domain;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bonus.sgzb.auth.form;
|
package com.bonus.sgzb.system.domain;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -47,8 +47,15 @@ public class NwLoginConstants {
|
||||||
|
|
||||||
public static String wechatAppId;
|
public static String wechatAppId;
|
||||||
|
|
||||||
|
//访问地址
|
||||||
|
public static String baseUrl;
|
||||||
public static String wechatAppsecret;
|
public static String wechatAppsecret;
|
||||||
|
|
||||||
|
@Value("${baseUrl}")
|
||||||
|
public void setBaseUrl(String baseUrl) {
|
||||||
|
NwLoginConstants.baseUrl = baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
@Value("${getNowPersonDetailData}")
|
@Value("${getNowPersonDetailData}")
|
||||||
public void setGetNowPersonDetailData(String getNowPersonDetailData) {
|
public void setGetNowPersonDetailData(String getNowPersonDetailData) {
|
||||||
NwLoginConstants.getNowPersonDetailData = getNowPersonDetailData;
|
NwLoginConstants.getNowPersonDetailData = getNowPersonDetailData;
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.bonus.sgzb.system.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:梁超
|
||||||
|
* @date:2024/1/26 - 14:02
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class OnlineApprove {
|
||||||
|
// WECHAT(3, NwLoginConstants.wechatAppId, NwLoginConstants.wechatAppsecret);
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
private String appId;
|
||||||
|
private String appsecret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,121 @@
|
||||||
|
package com.bonus.sgzb.system.domain;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caoxianfei
|
||||||
|
* @Version 1.0
|
||||||
|
* @date 2021-08-13 10:07
|
||||||
|
*/
|
||||||
|
public class RespLoginData<T> {
|
||||||
|
|
||||||
|
protected String code;
|
||||||
|
protected String message;
|
||||||
|
protected String msg;
|
||||||
|
protected String status;
|
||||||
|
protected Boolean success;
|
||||||
|
protected List<T> dataList;
|
||||||
|
protected T data;
|
||||||
|
|
||||||
|
public RespLoginData(){
|
||||||
|
}
|
||||||
|
|
||||||
|
public RespLoginData(String str, Class<T> clazz) {
|
||||||
|
if (StringUtils.isNotBlank(str)) {
|
||||||
|
JSONObject json = JSON.parseObject(str);
|
||||||
|
this.code = json.getString("code");
|
||||||
|
this.message = json.getString("message");
|
||||||
|
this.status = json.getString("status");
|
||||||
|
this.msg = json.getString("msg");
|
||||||
|
this.success = Boolean.parseBoolean(json.getString("success"));
|
||||||
|
if (null != clazz) {
|
||||||
|
if (json.get("data") != null && StringUtils.isNotBlank(json.getString("data"))) {
|
||||||
|
try{
|
||||||
|
this.data = JSONObject.parseObject(json.getString("data"), clazz);
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.dataList = JSONObject.parseArray(json.getString("data"), clazz);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
this.data = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* this.data = (T)JSONObject.parseObject(json.getString("data"), Boolean.class);*/
|
||||||
|
this.data = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RespLoginData(String code, String message, String msg, String status, Boolean success, T data, List<T> dataList) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.msg = msg;
|
||||||
|
this.status = status;
|
||||||
|
this.success = success;
|
||||||
|
this.data = data;
|
||||||
|
this.dataList = dataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getSuccess() {
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccess(Boolean success) {
|
||||||
|
this.success = success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> getDataList() {
|
||||||
|
return dataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataList(List<T> dataList) {
|
||||||
|
this.dataList = dataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(T data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.bonus.sgzb.auth.form;
|
package com.bonus.sgzb.system.domain;
|
||||||
|
|
||||||
import com.bonus.sgzb.common.core.web.domain.BaseEntity;
|
import com.bonus.sgzb.common.core.web.domain.BaseEntity;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
@ -2,12 +2,15 @@ package com.bonus.sgzb.system.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.bonus.sgzb.system.api.domain.SysUser;
|
import com.bonus.sgzb.system.api.domain.SysUser;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户 业务层
|
* 用户 业务层
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@Mapper
|
||||||
public interface ISysUserService
|
public interface ISysUserService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,13 +45,6 @@ public interface ISysUserService
|
||||||
*/
|
*/
|
||||||
public SysUser selectUserByUserName(String userName);
|
public SysUser selectUserByUserName(String userName);
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过用户名和手机号查询用户
|
|
||||||
* @param userName
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public SysUser selectUserByUserNameAndPhone(String userName,String phoneNum);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID查询用户
|
* 通过用户ID查询用户
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
package com.bonus.sgzb.auth.service;
|
package com.bonus.sgzb.system.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.bonus.sgzb.auth.form.*;
|
|
||||||
import com.bonus.sgzb.auth.utils.HttpUtils;
|
|
||||||
import com.bonus.sgzb.common.core.domain.R;
|
import com.bonus.sgzb.common.core.domain.R;
|
||||||
import com.bonus.sgzb.system.api.domain.SysUser;
|
import com.bonus.sgzb.system.api.domain.SysUser;
|
||||||
|
import com.bonus.sgzb.system.domain.*;
|
||||||
import com.bonus.sgzb.system.service.ISysUserService;
|
import com.bonus.sgzb.system.service.ISysUserService;
|
||||||
|
import com.bonus.sgzb.system.util.HttpUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
|
|
@ -21,6 +21,7 @@ import java.util.Map;
|
||||||
* @date:2024/1/26 - 13:25
|
* @date:2024/1/26 - 13:25
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Component
|
||||||
public class NwUserLoginService {
|
public class NwUserLoginService {
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,7 +45,7 @@ public class NwUserLoginService {
|
||||||
if (StringUtils.isBlank(code)) {
|
if (StringUtils.isBlank(code)) {
|
||||||
return R.fail("参数code不能为空");
|
return R.fail("参数code不能为空");
|
||||||
}
|
}
|
||||||
// WECHAT(3, LoginConstants.wechatAppId, LoginConstants.wechatAppsecret),
|
|
||||||
LoginResultForm loginResultForm = new LoginResultForm();
|
LoginResultForm loginResultForm = new LoginResultForm();
|
||||||
loginResultForm.setReturnUrl(redirectUrl);
|
loginResultForm.setReturnUrl(redirectUrl);
|
||||||
loginResultForm.setAccountType(null);
|
loginResultForm.setAccountType(null);
|
||||||
|
|
@ -53,7 +54,11 @@ public class NwUserLoginService {
|
||||||
reqMap.set(NwLoginConstants.CODE, code);
|
reqMap.set(NwLoginConstants.CODE, code);
|
||||||
reqMap.set(NwLoginConstants.GRANT_TYPE, grantType);
|
reqMap.set(NwLoginConstants.GRANT_TYPE, grantType);
|
||||||
reqMap.set(NwLoginConstants.SCOPE, NwLoginConstants.SCOPE_ALL);
|
reqMap.set(NwLoginConstants.SCOPE, NwLoginConstants.SCOPE_ALL);
|
||||||
Map<String, Object> resultMap = HttpUtils.postFormForOauth2(NwLoginConstants.onlineApprove, reqMap, null, OnlineApproveEnum.WECHAT);
|
OnlineApprove onlineApprove = new OnlineApprove();
|
||||||
|
onlineApprove.setCode(3);
|
||||||
|
onlineApprove.setAppId(NwLoginConstants.wechatAppId);
|
||||||
|
onlineApprove.setAppsecret(NwLoginConstants.wechatAppsecret);
|
||||||
|
Map<String, Object> resultMap = HttpUtils.postFormForOauth2(NwLoginConstants.onlineApprove, reqMap, null, onlineApprove);
|
||||||
log.info("微服务平台认证, 调用南网用户中心, result: {}", JSON.toJSONString(resultMap));
|
log.info("微服务平台认证, 调用南网用户中心, result: {}", JSON.toJSONString(resultMap));
|
||||||
if (StringUtils.isNotEmpty((String) resultMap.get(NwLoginConstants.CODE))) {
|
if (StringUtils.isNotEmpty((String) resultMap.get(NwLoginConstants.CODE))) {
|
||||||
String Code = resultMap.get(NwLoginConstants.CODE).toString();
|
String Code = resultMap.get(NwLoginConstants.CODE).toString();
|
||||||
|
|
@ -65,7 +70,7 @@ public class NwUserLoginService {
|
||||||
//查询登陆用户详细信息 不脱敏查询
|
//查询登陆用户详细信息 不脱敏查询
|
||||||
HashMap<String, String> requestMap = new HashMap<>();
|
HashMap<String, String> requestMap = new HashMap<>();
|
||||||
requestMap.put("cancelDesensitization", "true");
|
requestMap.put("cancelDesensitization", "true");
|
||||||
RespLoginData<LoginUserInfoRespDTO> loginUserInfoRespData = HttpUtils.postForm(NwLoginConstants.getNowPersonDetailData, null, (String) resultMap.get("access_token"), LoginUserInfoRespDTO.class, requestMap, OnlineApproveEnum.WECHAT);
|
RespLoginData<LoginUserInfoRespDTO> loginUserInfoRespData = HttpUtils.postForm(NwLoginConstants.getNowPersonDetailData, null, (String) resultMap.get("access_token"), LoginUserInfoRespDTO.class, requestMap, onlineApprove);
|
||||||
log.info("查询登陆用户详细信息, 调用南网用户中心, result: {}", JSON.toJSONString(loginUserInfoRespData));
|
log.info("查询登陆用户详细信息, 调用南网用户中心, result: {}", JSON.toJSONString(loginUserInfoRespData));
|
||||||
if (!NwLoginConstants.HTTP_RESPONSE_CODE_200.equals(loginUserInfoRespData.getCode())) {
|
if (!NwLoginConstants.HTTP_RESPONSE_CODE_200.equals(loginUserInfoRespData.getCode())) {
|
||||||
return R.fail(loginUserInfoRespData.getCode() + loginUserInfoRespData.getMessage() + loginResultForm);
|
return R.fail(loginUserInfoRespData.getCode() + loginUserInfoRespData.getMessage() + loginResultForm);
|
||||||
|
|
@ -76,42 +81,40 @@ public class NwUserLoginService {
|
||||||
String nickName = loginUserInfoRespDTO.getNickName();
|
String nickName = loginUserInfoRespDTO.getNickName();
|
||||||
String email = loginUserInfoRespDTO.getEmail();
|
String email = loginUserInfoRespDTO.getEmail();
|
||||||
String sex = loginUserInfoRespDTO.getSex();
|
String sex = loginUserInfoRespDTO.getSex();
|
||||||
|
String headPortrait = loginUserInfoRespDTO.getHeadPortrait();
|
||||||
//根据用户名和手机号查询用户
|
String psCode = loginUserInfoRespDTO.getPsCode();
|
||||||
|
String status = loginUserInfoRespDTO.getStatus();
|
||||||
|
String loginIp = loginUserInfoRespDTO.getLoginIp();
|
||||||
|
String loginTime = loginUserInfoRespDTO.getLoginTime().toString();
|
||||||
|
String createUserName = loginUserInfoRespDTO.getCreateUserName();
|
||||||
|
String createTime = loginUserInfoRespDTO.getCreateTime();
|
||||||
|
String updateUserName = loginUserInfoRespDTO.getUpdateUserName();
|
||||||
|
String updateTime = loginUserInfoRespDTO.getUpdateTime();
|
||||||
|
//根据用户名查询用户
|
||||||
SysUser sysUser = userService.selectUserByUserName(userName);
|
SysUser sysUser = userService.selectUserByUserName(userName);
|
||||||
if (null == sysUser) {
|
if (null == sysUser) {
|
||||||
|
return R.fail(401,"该用户不存在,请先注册");
|
||||||
//未找到该用户,新增该用户
|
//未找到该用户,新增该用户
|
||||||
SysUser user = new SysUser();
|
/* SysUser user = new SysUser();
|
||||||
user.setUserName(userName);
|
user.setUserName(userName);
|
||||||
user.setNickName(nickName);
|
user.setNickName(nickName);
|
||||||
user.setEmail(email);
|
user.setEmail(email);
|
||||||
user.setPhonenumber(mobilePhone);
|
user.setPhonenumber(mobilePhone);
|
||||||
user.setPhonenumber(sex);
|
user.setSex(sex);
|
||||||
user.setPhonenumber(sex);
|
user.setAvatar(headPortrait);
|
||||||
|
user.setPassword(psCode);
|
||||||
|
if ("ENABLE".equals(status)){
|
||||||
|
user.setStatus("0");
|
||||||
|
}else {
|
||||||
|
user.setStatus("1");
|
||||||
}
|
}
|
||||||
/* if (null == userAccount) {
|
user.setLoginIp(loginIp);
|
||||||
RegisterForms registerForms = new RegisterForms();
|
user.setLoginDate(DateUtil.parse(loginTime,"yyyy-MM-dd HH:mm:ss"));
|
||||||
registerForms.setPlatformId(CodeConstants.PLATFORM_ID);
|
user.setCreateBy(createUserName);
|
||||||
registerForms.setIsPersonal(AccountRegisterEnum.IS_PERSONAL.getCode());
|
user.setCreateTime(DateUtil.parse(createTime,"yyyy-MM-dd HH:mm:ss"));
|
||||||
registerForms.setUserAccount(loginUserInfoRespDTO.getUserAccount());
|
user.setUpdateBy(updateUserName);
|
||||||
registerForms.setMobilePhone(mobilePhone);
|
user.setUpdateTime(DateUtil.parse(updateTime,"yyyy-MM-dd HH:mm:ss"));*/
|
||||||
nwRegisterService.personRegisters(registerForms, userExternalId, loginUserInfoRespDTO.getUserName());
|
|
||||||
userAccount = userAccountService.queryUserAccountByExternalId(CodeConstants.PLATFORM_ID, userExternalId);
|
|
||||||
if (null == userAccount) {
|
|
||||||
return RespData.error(ExceptionDict.LOGIN_SMS_FAILED_CODE, ExceptionDict.LOGIN_SMS_FAILED_MSG, loginResultForm);
|
|
||||||
} else if (UserStatusEnum.DISABLE.getCode().equals(userAccount.getUserStatus())) {
|
|
||||||
return RespData.error(ExceptionDict.LOGIN_DISABLE_USER_CODE, ExceptionDict.LOGIN_DISABLE_USER_MSG, loginResultForm);
|
|
||||||
}
|
}
|
||||||
} else {
|
return R.ok(sysUser);
|
||||||
if (UserStatusEnum.DISABLE.getCode().equals(userAccount.getUserStatus())) {
|
|
||||||
return RespData.error(ExceptionDict.LOGIN_DISABLE_USER_CODE, ExceptionDict.LOGIN_DISABLE_USER_MSG, loginResultForm);
|
|
||||||
}
|
|
||||||
// 维护南网关联外键
|
|
||||||
this.jointNwUserId(loginUserInfoRespDTO, userAccount);
|
|
||||||
}
|
|
||||||
return getLoginResultFormRespData(loginResultForm, resultMap, userAccount, nwAppEnum.getCode());
|
|
||||||
}*/
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -114,11 +114,6 @@ public class SysUserServiceImpl implements ISysUserService
|
||||||
return userMapper.selectUserByUserName(userName);
|
return userMapper.selectUserByUserName(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public SysUser selectUserByUserNameAndPhone(String userName, String phoneNum) {
|
|
||||||
return userMapper.selectUserByUserName(userName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户ID查询用户
|
* 通过用户ID查询用户
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package com.bonus.sgzb.auth.utils;
|
package com.bonus.sgzb.system.util;
|
||||||
|
|
||||||
import com.bonus.sgzb.auth.form.OnlineApproveEnum;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.bonus.sgzb.auth.form.RespLoginData;
|
|
||||||
import com.bonus.sgzb.common.core.utils.StringUtils;
|
import com.bonus.sgzb.common.core.utils.StringUtils;
|
||||||
|
import com.bonus.sgzb.system.domain.NwLoginConstants;
|
||||||
|
import com.bonus.sgzb.system.domain.OnlineApprove;
|
||||||
|
import com.bonus.sgzb.system.domain.RespLoginData;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
@ -15,6 +17,7 @@ import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 集成南网注册登陆工具
|
* 集成南网注册登陆工具
|
||||||
|
*
|
||||||
* @author caoxianfei
|
* @author caoxianfei
|
||||||
* @Version 1.0
|
* @Version 1.0
|
||||||
* @date 2021-08-13 0:14
|
* @date 2021-08-13 0:14
|
||||||
|
|
@ -23,14 +26,14 @@ import java.util.Set;
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
|
|
||||||
public static Map<String, Object> postFormForOauth2(String url, Object params, Map<String, String> map, OnlineApproveEnum onlineApproveEnum) {
|
public static Map<String, Object> postFormForOauth2(String url, Object params, Map<String, String> map, OnlineApprove onlineApprove) throws Exception {
|
||||||
log.info("进入post请求,入参为 url={},params={}", url, params);
|
log.info("进入post请求,入参为 url={},params={}", url, params);
|
||||||
String finalUrl = LoginConstants.baseUrl + url;
|
String finalUrl = NwLoginConstants.baseUrl + url;
|
||||||
String body;
|
String body;
|
||||||
try {
|
try {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
headers.setBasicAuth(nwAppEnum.getAppId(), nwAppEnum.getAppsecret());
|
headers.setBasicAuth(onlineApprove.getAppId(), onlineApprove.getAppsecret());
|
||||||
HttpEntity<Object> request = new HttpEntity<>(params, headers);
|
HttpEntity<Object> request = new HttpEntity<>(params, headers);
|
||||||
if (Objects.nonNull(map)) {
|
if (Objects.nonNull(map)) {
|
||||||
StringBuffer path = new StringBuffer("?");
|
StringBuffer path = new StringBuffer("?");
|
||||||
|
|
@ -45,7 +48,7 @@ public class HttpUtils {
|
||||||
log.info("finalUrl={},出参为,body={}", finalUrl, body);
|
log.info("finalUrl={},出参为,body={}", finalUrl, body);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("HttpUtils.postForm exception: ", e);
|
log.error("HttpUtils.postForm exception: ", e);
|
||||||
throw new UserException("500", "Http请求错误");
|
throw new Exception("Http请求错误");
|
||||||
}
|
}
|
||||||
return JSON.parseObject(body, Map.class);
|
return JSON.parseObject(body, Map.class);
|
||||||
}
|
}
|
||||||
|
|
@ -53,6 +56,7 @@ public class HttpUtils {
|
||||||
/**
|
/**
|
||||||
* className 传入返回对象的class
|
* className 传入返回对象的class
|
||||||
* 传入的兑现必须 继承 BaseLoginEntity
|
* 传入的兑现必须 继承 BaseLoginEntity
|
||||||
|
*
|
||||||
* @param url
|
* @param url
|
||||||
* @param params
|
* @param params
|
||||||
* @param token
|
* @param token
|
||||||
|
|
@ -60,17 +64,17 @@ public class HttpUtils {
|
||||||
* @param map post请求如果路径上上有拼接参数,传入map 字段为key 值为value
|
* @param map post请求如果路径上上有拼接参数,传入map 字段为key 值为value
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static RespLoginData postForm(String url, Object params, String token, Class className, Map<String, String> map, OnlineApproveEnum onlineApproveEnum) throws Exception {
|
public static RespLoginData postForm(String url, Object params, String token, Class className, Map<String, String> map, OnlineApprove onlineApprove) throws Exception {
|
||||||
log.info("进入post请求,入参为 url={},params={},token={}", url, params, token);
|
log.info("进入post请求,入参为 url={},params={},token={}", url, params, token);
|
||||||
String finalUrl = LoginConstants.baseUrl + url;
|
String finalUrl = NwLoginConstants.baseUrl + url;
|
||||||
String body;
|
String body;
|
||||||
try {
|
try {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
if(StringUtils.isBlank(token)){
|
if (StringUtils.isBlank(token)) {
|
||||||
headers.setBasicAuth(nwAppEnum.getAppId(), nwAppEnum.getAppsecret());
|
headers.setBasicAuth(onlineApprove.getAppId(), onlineApprove.getAppsecret());
|
||||||
}else {
|
} else {
|
||||||
headers.setBearerAuth(token);
|
headers.setBearerAuth(token);
|
||||||
}
|
}
|
||||||
HttpEntity<Object> request = new HttpEntity<>(params, headers);
|
HttpEntity<Object> request = new HttpEntity<>(params, headers);
|
||||||
|
|
@ -36,3 +36,10 @@ spring:
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
|
||||||
|
|
||||||
|
onlineApprove: /lbcloud-oauth/oauth/token
|
||||||
|
wechatAppId: crhmaxnE
|
||||||
|
wechatAppsecret: 3893e6ed90d325f00e34583dd970a56580c05549
|
||||||
|
getNowPersonDetailData: /lbcloud-user/user/queryLoginUserInfo
|
||||||
|
baseUrl: https://test-sso.csgmall.com.cn
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue