pj访客
This commit is contained in:
1 parent
704c8d5a5f
commit
d77922561b
5 files changed
+120
-73
No files matched your search
@@ -14,10 +14,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -59,6 +56,18 @@ public class ImageCodeEndpoint {
|
||||
captcha.out(response.getOutputStream());
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@GetMapping("/visitor/image")
|
||||
public void visitorImage(@RequestParam(value = "randomStr")String randomStr, HttpServletResponse response) {
|
||||
ArithmeticCaptcha captcha = new ArithmeticCaptcha(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);
|
||||
|
||||
String result = captcha.text();
|
||||
|
||||
redisTemplate.opsForValue()
|
||||
.set(CacheConstants.VISITOR_CODE_KEY + randomStr, result, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
|
||||
// 转换流信息写出
|
||||
captcha.out(response.getOutputStream());
|
||||
}
|
||||
/**
|
||||
* 行为 创建滑块图形验证码
|
||||
*/
|
||||
|
||||
+7
-2
@@ -20,6 +20,13 @@ public interface CacheConstants {
|
||||
*/
|
||||
String DEFAULT_CODE_KEY = "DEFAULT_CODE_KEY:";
|
||||
|
||||
String VISITOR_CODE_KEY = "visitor_code_key";
|
||||
|
||||
|
||||
String SMS_CODE_KEY = "smsCode_";
|
||||
|
||||
String SMS_VISITOR_CODE_KEY = "sms_visitor_code:";
|
||||
|
||||
/**
|
||||
* 菜单信息缓存
|
||||
*/
|
||||
@@ -147,6 +154,4 @@ public interface CacheConstants {
|
||||
/* ************************************* end 第三方对接相关 end ************************************* */
|
||||
|
||||
|
||||
/** mfa */
|
||||
String SMS_CODE_KEY="sms_code:";
|
||||
}
|
||||
@@ -13,6 +13,12 @@
|
||||
<artifactId>pjcloud-integrated-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- Token-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
<!-- 幂等插件使用 -->
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
|
||||
+75
-64
@@ -6,24 +6,33 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.constant.CacheConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.core.util.WebUtils;
|
||||
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.integrated.entity.VisitorUserEntity;
|
||||
import com.bsd.pjcloud.integrated.service.VisitorUserService;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 访客用户
|
||||
@@ -39,74 +48,76 @@ import java.util.Map;
|
||||
public class AppVisitorUserController {
|
||||
|
||||
private final VisitorUserService visitorUserService;
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param page 分页对象
|
||||
* @param visitorUser 访客用户
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "分页查询" , description = "分页查询" )
|
||||
@GetMapping("/page" )
|
||||
@PreAuthorize("@pms.hasPermission('integrated_visitorUser_view')" )
|
||||
public R getVisitorUserPage(@ParameterObject Page page, @ParameterObject VisitorUserEntity visitorUser) {
|
||||
LambdaQueryWrapper<VisitorUserEntity> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.like(StrUtil.isNotBlank(visitorUser.getRealName()),VisitorUserEntity::getRealName,visitorUser.getRealName());
|
||||
wrapper.like(StrUtil.isNotBlank(visitorUser.getPhone()),VisitorUserEntity::getPhone,visitorUser.getPhone());
|
||||
return R.ok(visitorUserService.page(page, wrapper));
|
||||
|
||||
// 登录验证
|
||||
@PostMapping("/login")
|
||||
public R<Map<String, Object>> login(
|
||||
@RequestParam String phone,
|
||||
@RequestParam String smsCode,
|
||||
@RequestParam String randomStr,
|
||||
@RequestParam(value = "realName", required = false) String realName
|
||||
) {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
// 1. 验证短信验证码
|
||||
if (verifySmsCode(phone,randomStr, smsCode)) {
|
||||
return R.failed("短信验证码错误或已过期");
|
||||
}
|
||||
|
||||
// 2. 查找或创建账户
|
||||
VisitorUserEntity account = visitorUserService.getOne(new LambdaQueryWrapper<VisitorUserEntity>().eq(VisitorUserEntity::getPhone, phone));
|
||||
account.setLastLogin(LocalDateTime.now());
|
||||
if (account == null){
|
||||
account = new VisitorUserEntity();
|
||||
account.setPhone(phone);
|
||||
account.setRealName(realName);
|
||||
account.setStatus("0");
|
||||
account.setRegisterTime(LocalDateTime.now());
|
||||
visitorUserService.save(account);
|
||||
}else {
|
||||
// 3. 检查账户状态
|
||||
if (account.getStatus().equals("1")) {
|
||||
response.put("code", 4006);
|
||||
response.put("message", "账户已被锁定,请联系管理员");
|
||||
return R.failed( response);
|
||||
}
|
||||
visitorUserService.updateById( account);
|
||||
}
|
||||
|
||||
Map<String, Object> stringStringHashMap = new HashMap<>();
|
||||
stringStringHashMap.put("phone", phone);
|
||||
stringStringHashMap.put("realName", realName);
|
||||
stringStringHashMap.put("randomStr", randomStr);
|
||||
stringStringHashMap.put("smsCode", smsCode);
|
||||
String token=Jwts.builder().setSubject(account.getId().toString())
|
||||
.setIssuedAt(new Date())
|
||||
.setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 7))
|
||||
.setClaims(stringStringHashMap).compact();
|
||||
|
||||
|
||||
response.put("code", 200);
|
||||
response.put("message", "登录成功");
|
||||
response.put("token", token);
|
||||
response.put("account", account);
|
||||
return R.ok(response);
|
||||
}
|
||||
|
||||
private boolean verifySmsCode(String phone, String randomStr, String smsCode) {
|
||||
String key = CacheConstants.SMS_VISITOR_CODE_KEY + phone + "_" + randomStr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过id查询访客用户
|
||||
* @param id id
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "通过id查询" , description = "通过id查询" )
|
||||
@GetMapping("/{id}" )
|
||||
@PreAuthorize("@pms.hasPermission('integrated_visitorUser_view')" )
|
||||
public R getById(@PathVariable("id" ) Long id) {
|
||||
return R.ok(visitorUserService.getById(id));
|
||||
private String getClientIp(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增访客用户
|
||||
* @param visitorUser 访客用户
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "新增访客用户" , description = "新增访客用户" )
|
||||
@SysLog("新增访客用户" )
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('integrated_visitorUser_add')" )
|
||||
public R save(@RequestBody VisitorUserEntity visitorUser) {
|
||||
return R.ok(visitorUserService.save(visitorUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改访客用户
|
||||
* @param visitorUser 访客用户
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "修改访客用户" , description = "修改访客用户" )
|
||||
@SysLog("修改访客用户" )
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('integrated_visitorUser_edit')" )
|
||||
public R updateById(@RequestBody VisitorUserEntity visitorUser) {
|
||||
return R.ok(visitorUserService.updateById(visitorUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除访客用户
|
||||
* @param ids id列表
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "通过id删除访客用户" , description = "通过id删除访客用户" )
|
||||
@SysLog("通过id删除访客用户" )
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@pms.hasPermission('integrated_visitorUser_del')" )
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
return R.ok(visitorUserService.removeBatchByIds(CollUtil.toList(ids)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+19
-3
@@ -7,6 +7,7 @@ import com.bsd.pjcloud.admin.api.entity.UserTrustedDeviceEntity;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteTokenService;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserTrustedDeviceService;
|
||||
import com.bsd.pjcloud.common.core.constant.CacheConstants;
|
||||
import com.bsd.pjcloud.common.core.util.DeviceFingerprintUtil;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.core.util.WebUtils;
|
||||
@@ -307,21 +308,36 @@ public class ThirdPartyOAth2Cotroller {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 诗画浦江端
|
||||
* @param mobilePhone
|
||||
* @param httpServletRequest
|
||||
* @param type 短信区分标识 if null 诗画登录短信 1 访客登录短信
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/loginSms")
|
||||
@Operation(summary = "发送登录短信")
|
||||
@SysLog("发送登录短信")
|
||||
@Inner(value = false)
|
||||
public R loginSms(@RequestParam String mobilePhone,HttpServletRequest httpServletRequest) {
|
||||
public R loginSms(@RequestParam String mobilePhone,HttpServletRequest httpServletRequest,
|
||||
@RequestParam(value = "type",required = false)Integer type) {
|
||||
Map<String, String> stringHashMap = new LinkedHashMap<>();
|
||||
String s = SmsCodeUtil.generateNumberCode(6);
|
||||
stringHashMap.put("code",s);
|
||||
stringHashMap.put("date","5");
|
||||
smsService.sendSms(mobilePhone, "20657",stringHashMap, WebUtils.getIP());
|
||||
|
||||
redisTemplate.opsForValue().set("smsCode_"+mobilePhone,s, 5, TimeUnit.MINUTES);
|
||||
|
||||
if (type == 1){
|
||||
redisTemplate.opsForValue().set(CacheConstants.SMS_VISITOR_CODE_KEY +mobilePhone,s, 5, TimeUnit.MINUTES);
|
||||
}else {
|
||||
redisTemplate.opsForValue().set(CacheConstants.SMS_CODE_KEY +mobilePhone,s, 5, TimeUnit.MINUTES);
|
||||
}
|
||||
// redisTemplate.opsForValue().set(CacheConstants.SMS_CODE_KEY +mobilePhone,s, 5, TimeUnit.MINUTES);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user