|
|
@@ -10,6 +10,7 @@ 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.exception.ServiceException;
|
|
|
import com.fs.common.service.ISmsService;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
import com.fs.core.config.WxOpenProperties;
|
|
|
@@ -300,6 +301,61 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/loginByPhone")
|
|
|
+ public R loginByPhone(@RequestBody Map<String,String> map){
|
|
|
+ String phone = map.get("phone");
|
|
|
+ String code = map.get("code");
|
|
|
+ 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("此电话号码未绑定用户");
|
|
|
+ }
|
|
|
+ if (user.size()>1){
|
|
|
+ //如果出现了一个手机号多个用户的情况,找出登陆过app的那个用户
|
|
|
+ user.removeIf(fsUser -> StringUtils.isEmpty(fsUser.getHistoryApp()));
|
|
|
+ }
|
|
|
+ String redisCode = redisCache.getCacheObject("sms:code:" + phone);
|
|
|
+ if (StringUtils.isEmpty(redisCode)){
|
|
|
+ return R.error("验证码已过期,请重新发送");
|
|
|
+ }
|
|
|
+ if (!redisCode.equals(code)) {
|
|
|
+ return R.error("验证码错误");
|
|
|
+ }
|
|
|
+ updateExistingUserJpushId(user.get(0), map.get("jpushId"));
|
|
|
+ return generateTokenAndReturn(user.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/resetPassword")
|
|
|
+ public R resetPassword(@RequestBody Map<String, String> body){
|
|
|
+ String phone = body.get("phone");
|
|
|
+ String code = body.get("code");
|
|
|
+ String newPassword = body.get("newPassword");
|
|
|
+ String confirmPassword = body.get("confirmPassword");
|
|
|
+ if (!newPassword.equals(confirmPassword)){
|
|
|
+ throw new ServiceException("两次输入密码不一致,请检查");
|
|
|
+ }
|
|
|
+ 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("此电话号码未绑定用户");
|
|
|
+ }
|
|
|
+ String redisCode = redisCache.getCacheObject("sms:code:" + phone);
|
|
|
+ if (StringUtils.isEmpty(redisCode)){
|
|
|
+ return R.error("验证码已过期,请重新发送");
|
|
|
+ }
|
|
|
+ if (!redisCode.equals(code)) {
|
|
|
+ return R.error("验证码错误");
|
|
|
+ }
|
|
|
+ String password = Md5Utils.hash(newPassword);
|
|
|
+ return userService.updatePasswordByPhone(password,encryptPhone);
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation("绑定手机号")
|
|
|
@PostMapping("/setPhone")
|
|
|
public R setPhone(@Validated @RequestBody FsUserEditPhoneParam param) {
|
|
|
@@ -456,6 +512,42 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/sendCode")
|
|
|
+ public R sendCode(@RequestBody Map<String, String> body){
|
|
|
+ String phone = body.get("phone");
|
|
|
+ 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, "验证码");
|
|
|
+
|
|
|
+ // 缓存验证码(3分钟有效)
|
|
|
+ redisCache.setCacheObject(smsCodeKey, smsCode, 180, TimeUnit.SECONDS);
|
|
|
+ // 设置冷却时间(60秒内不能再发)
|
|
|
+ redisCache.setCacheObject(smsCooldownKey, "1", 60, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ return R.ok("验证码已发送");
|
|
|
+ }
|
|
|
+
|
|
|
private List<FsUser> findUsersByPhone(String phone) {
|
|
|
// 先根据加密手机号查询用户
|
|
|
String jiami = (encryptPhone(phone));
|