|
|
@@ -1,13 +1,16 @@
|
|
|
package com.fs.app.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import com.fs.app.annotation.Login;
|
|
|
import com.fs.app.param.*;
|
|
|
import com.fs.app.utils.WxUtil;
|
|
|
+import com.fs.common.VerifyCodeUtil;
|
|
|
import com.fs.common.annotation.RepeatSubmit;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.service.ISmsService;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
import com.fs.core.config.WxOpenProperties;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
@@ -35,13 +38,11 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.fs.his.utils.PhoneUtil.encryptPhone;
|
|
|
+import static com.fs.his.utils.PhoneUtil.encryptPhoneOldKey;
|
|
|
|
|
|
@Api("app登录接口")
|
|
|
@RestController
|
|
|
@@ -60,6 +61,10 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISmsService smsService;
|
|
|
+
|
|
|
@ApiOperation("注册app用户")
|
|
|
@PostMapping("/register")
|
|
|
@RepeatSubmit
|
|
|
@@ -543,4 +548,125 @@ public class AppLoginController extends AppBaseController{
|
|
|
// 不存在,追加到末尾
|
|
|
return currentAppIds + "," + newAppId;
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/sendCode")
|
|
|
+ public R sendCode(@RequestBody Map<String, String> body){
|
|
|
+ String phone = body.get("phone");
|
|
|
+ String type = body.get("type");
|
|
|
+ if(StringUtils.isEmpty(type)){
|
|
|
+ return R.error("请选择验证码类型");
|
|
|
+ }
|
|
|
+
|
|
|
+// String encryptPhone = encryptPhone(phone);
|
|
|
+// List<FsUser> user = userService.selectFsUserListByPhone(encryptPhone);
|
|
|
+// if(CollectionUtil.isEmpty(user)){
|
|
|
+// user = userService.selectFsUserListByPhone(encryptPhoneOldKey(phone));
|
|
|
+// }
|
|
|
+// if (CollectionUtil.isEmpty(user)){
|
|
|
+// return R.error("此电话号码未绑定用户");
|
|
|
+// }
|
|
|
+
|
|
|
+ // 验证码 key(3分钟有效)
|
|
|
+ String smsCodeKey = "sms:code:" + phone;
|
|
|
+ // 冷却 key(60秒内不能重复发送)
|
|
|
+ String smsCooldownKey = "sms:cooldown:" + phone;
|
|
|
+
|
|
|
+ // 判断是否在 60 秒冷却期
|
|
|
+ if (redisCache.getCacheObject(smsCooldownKey) != null) {
|
|
|
+ return R.error("验证码已发送,请稍后再试");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成新验证码
|
|
|
+ String smsCode = VerifyCodeUtil.generateCode();
|
|
|
+
|
|
|
+ // 发送短信
|
|
|
+ smsService.sendCaptcha(phone, smsCode, "验证码",type);
|
|
|
+
|
|
|
+ // 缓存验证码(3分钟有效)
|
|
|
+ redisCache.setCacheObject(smsCodeKey, smsCode, 180, TimeUnit.SECONDS);
|
|
|
+ // 设置冷却时间(60秒内不能再发)
|
|
|
+ redisCache.setCacheObject(smsCooldownKey, "1", 60, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ return R.ok("验证码已发送");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/registerSendCode")
|
|
|
+ public R registerSendCode(@RequestBody Map<String, String> body){
|
|
|
+ String phone = body.get("phone");
|
|
|
+ String type = body.get("type");
|
|
|
+ if(StringUtils.isEmpty(type)){
|
|
|
+ return R.error("请选择验证码类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ String encryptPhone = encryptPhone(phone);
|
|
|
+ List<FsUser> user = userService.selectFsUserListByPhone(encryptPhone);
|
|
|
+ if(CollectionUtil.isEmpty(user)){
|
|
|
+ user = userService.selectFsUserListByPhone(encryptPhoneOldKey(phone));
|
|
|
+ }
|
|
|
+ if (!CollectionUtil.isEmpty(user)){
|
|
|
+ return R.error("此电话号码已注册");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证码 key(存验证码,3分钟有效)
|
|
|
+ String smsCodeKey = "sms:code:" + phone;
|
|
|
+ // 发送冷却 key(限制60秒内不能再次发送)
|
|
|
+ String smsCooldownKey = "sms:cooldown:" + phone;
|
|
|
+
|
|
|
+ // 判断是否在60秒冷却时间内
|
|
|
+ if (redisCache.getCacheObject(smsCooldownKey) != null) {
|
|
|
+ return R.error("验证码已发送,请稍后再试");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成新的验证码
|
|
|
+ String smsCode = VerifyCodeUtil.generateCode();
|
|
|
+
|
|
|
+ // 发送短信
|
|
|
+ smsService.sendCaptcha(phone, smsCode, "验证码",type);
|
|
|
+
|
|
|
+ // 缓存验证码(3分钟有效)
|
|
|
+ redisCache.setCacheObject(smsCodeKey, smsCode, 180, TimeUnit.SECONDS);
|
|
|
+ // 设置冷却时间(60秒内不能再发)
|
|
|
+ redisCache.setCacheObject(smsCooldownKey, "1", 60, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ return R.ok("验证码已发送");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/registerByPhone")
|
|
|
+ public R registerByPhone(@RequestBody Map<String,String> map){
|
|
|
+ String phone = map.get("phone");
|
|
|
+ String code = map.get("code");
|
|
|
+ String password = map.get("password");
|
|
|
+ String encryptPhone = encryptPhone(phone);
|
|
|
+ List<FsUser> users = userService.selectFsUserListByPhone(encryptPhone);
|
|
|
+ if (users == null || CollectionUtil.isEmpty(users)){
|
|
|
+ String s = encryptPhoneOldKey(phone);
|
|
|
+ users = userService.selectFsUserListByPhone(s);
|
|
|
+ }
|
|
|
+ if (!CollectionUtil.isEmpty(users)){
|
|
|
+ return R.error("此账号已经注册");
|
|
|
+ }
|
|
|
+ String redisCode = redisCache.getCacheObject("sms:code:" + phone);
|
|
|
+ if (StringUtils.isEmpty(redisCode)){
|
|
|
+ return R.error("验证码已过期,请重新发送");
|
|
|
+ }
|
|
|
+ if (!redisCode.equals(code)) {
|
|
|
+ return R.error("验证码错误");
|
|
|
+ }
|
|
|
+ FsUser user = new FsUser();
|
|
|
+ // 创建新用户
|
|
|
+ user.setPhone(phone);
|
|
|
+ user.setJpushId(map.get("jpushId"));
|
|
|
+ user.setSource(map.get("source"));
|
|
|
+ user.setNickName("app用户" + phone.substring(phone.length() - 4));
|
|
|
+ user.setStatus(1);
|
|
|
+ user.setAvatar("https://cos.his.cdwjyyh.com/fs/20240926/420728ee06e54575ba82665dedb4756b.png");
|
|
|
+ user.setPassword(Md5Utils.hash(password));
|
|
|
+ user.setCreateTime(new Date());
|
|
|
+ if (userService.insertFsUser(user) > 0) {
|
|
|
+ return R.ok("注册成功");
|
|
|
+ } else {
|
|
|
+ return R.error("注册失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|