|
@@ -1,17 +1,22 @@
|
|
|
package com.ym.mec.auth.web.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huifu.adapay.core.util.StringUtil;
|
|
|
+import com.ym.mec.auth.api.dto.SysUserInfo;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.auth.service.SysRoleService;
|
|
|
import com.ym.mec.auth.service.SysUserRoleService;
|
|
|
import com.ym.mec.auth.service.SysUserService;
|
|
|
import com.ym.mec.auth.service.TenantInfoService;
|
|
|
import com.ym.mec.auth.api.dto.SysUserQueryInfo;
|
|
|
+import com.ym.mec.auth.web.controller.queryInfo.QRLoginDto;
|
|
|
import com.ym.mec.common.controller.BaseController;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.common.entity.ImResult;
|
|
|
import com.ym.mec.common.entity.ImUserModel;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.QueryInfo;
|
|
|
+import com.ym.mec.common.redis.service.RedisCache;
|
|
|
import com.ym.mec.common.security.AuthUser;
|
|
|
import com.ym.mec.common.security.SecurityConstants;
|
|
|
import com.ym.mec.common.security.SecurityUtils;
|
|
@@ -24,16 +29,28 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Base64;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@RestController()
|
|
|
@RequestMapping("user")
|
|
@@ -52,6 +69,10 @@ public class UserController extends BaseController {
|
|
|
private IdGeneratorService smsCodeService;
|
|
|
@Autowired
|
|
|
private TenantInfoService tenantInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCache<String,Object> redisCache;
|
|
|
+
|
|
|
@Value("${message.debugMode}")
|
|
|
private boolean debugMode;
|
|
|
@Autowired
|
|
@@ -377,4 +398,95 @@ public class UserController extends BaseController {
|
|
|
public HttpResponseResult<List<SysUser>> page(@RequestBody SysUserQueryInfo queryInfo) {
|
|
|
return succeed(sysUserService.queryEmployeeList(queryInfo));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/open/getQRLoginCode")
|
|
|
+ @ApiOperation(value = "获取二维码登录code(不需要鉴权)")
|
|
|
+ public HttpResponseResult<String> getQRLoginCode(String clientId) {
|
|
|
+
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+
|
|
|
+ QRLoginDto qrLoginDto = new QRLoginDto();
|
|
|
+ qrLoginDto.setCode(uuid);
|
|
|
+ qrLoginDto.setClientId(clientId);
|
|
|
+ redisCache.put(uuid,qrLoginDto,50*60);
|
|
|
+ return succeed(uuid);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/open/pollingQRLoginCode")
|
|
|
+ @ApiOperation(value = "前端轮询登录(不需要鉴权)")
|
|
|
+ public HttpResponseResult<QRLoginDto> pollingQRLoginCode(@ApiParam(value = "二维码登录code", required = true) @RequestParam("code") String code) {
|
|
|
+ if (StringUtil.isEmpty(code)) {
|
|
|
+ throw new BizException("登录失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ Object obj = redisCache.get(code);
|
|
|
+ if (null != obj) {
|
|
|
+ QRLoginDto dto = (QRLoginDto) obj;
|
|
|
+ dto.setUserInfo(null);
|
|
|
+ return succeed(dto);
|
|
|
+ } else {
|
|
|
+ QRLoginDto qrLoginDto = new QRLoginDto();
|
|
|
+ qrLoginDto.setExpireFlag(true);
|
|
|
+ return succeed(qrLoginDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = "/qrLogin")
|
|
|
+ @ApiOperation(value = "二维码登录-扫码")
|
|
|
+ public HttpResponseResult<QRLoginDto> qrLogin(
|
|
|
+ @ApiParam(value = "二维码登录code", required = true) @RequestParam("code") String code
|
|
|
+ ) throws IOException {
|
|
|
+ AuthUser authUser = SecurityUtils.getUser();
|
|
|
+ if (authUser == null) {
|
|
|
+ throw new BizException("请先登录");
|
|
|
+ }
|
|
|
+ SysUser sysUser = sysUserService.get(authUser.getUserId());
|
|
|
+
|
|
|
+
|
|
|
+ Object data = redisCache.get(code);
|
|
|
+ if (null == data) {
|
|
|
+ QRLoginDto qrLoginDto = new QRLoginDto();
|
|
|
+ qrLoginDto.setExpireFlag(true);
|
|
|
+ return succeed(qrLoginDto);
|
|
|
+ }
|
|
|
+ redisCache.put(code,data,50*60);
|
|
|
+ return succeed( (QRLoginDto) data);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = "/doQrLogin")
|
|
|
+ @ApiOperation(value = "二维码登录-确认登录")
|
|
|
+ public HttpResponseResult<QRLoginDto> doQrLogin(
|
|
|
+ @ApiParam(value = "二维码登录code", required = true) @RequestParam("code") String code
|
|
|
+ ) {
|
|
|
+ AuthUser authUser = SecurityUtils.getUser();
|
|
|
+ if (authUser == null) {
|
|
|
+ throw new BizException("请先登录");
|
|
|
+ }
|
|
|
+ SysUser sysUser = sysUserService.get(authUser.getUserId());
|
|
|
+
|
|
|
+ Object data = redisCache.get(code);
|
|
|
+ if (null == data) {
|
|
|
+ QRLoginDto qrLoginDto = new QRLoginDto();
|
|
|
+ qrLoginDto.setExpireFlag(true);
|
|
|
+ return succeed(qrLoginDto);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ SysUserInfo userInfo = sysUserService.queryUserInfoByPhone(sysUser.getPhone());
|
|
|
+ QRLoginDto dto = (QRLoginDto) data;
|
|
|
+ dto.setUserInfo(userInfo);
|
|
|
+
|
|
|
+
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+ dto.setPrivateKey(uuid);
|
|
|
+ redisCache.put(code,dto,50*60);
|
|
|
+
|
|
|
+ dto.setUserInfo(null);
|
|
|
+
|
|
|
+ return succeed(dto);
|
|
|
+ }
|
|
|
+
|
|
|
}
|