|
@@ -10,7 +10,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.xjrsoft.common.annotation.XjrLog;
|
|
|
import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
import com.xjrsoft.common.enums.EnabledMark;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.model.result.R;
|
|
|
+import com.xjrsoft.common.sms.SmsCtcc;
|
|
|
import com.xjrsoft.common.sms.SmsSender;
|
|
|
import com.xjrsoft.common.utils.RedisUtil;
|
|
|
import com.xjrsoft.config.KeyCloakConfig;
|
|
@@ -53,7 +55,7 @@ public class LoginController {
|
|
|
|
|
|
private KeyCloakConfig keyCloakConfig;
|
|
|
|
|
|
- private SmsSender smsSender;
|
|
|
+ private SmsCtcc smsCtcc;
|
|
|
|
|
|
@PostMapping("/login")
|
|
|
@ApiOperation(value = "登录", notes = "传入账号:account,密码:password")
|
|
@@ -70,8 +72,8 @@ public class LoginController {
|
|
|
}
|
|
|
|
|
|
@GetMapping("/imgcaptcha")
|
|
|
- @ApiOperation(value = "图形验证码",notes = "图形验证码")
|
|
|
- public R imgCaptcha(){
|
|
|
+ @ApiOperation(value = "图形验证码", notes = "图形验证码")
|
|
|
+ public R imgCaptcha() {
|
|
|
return R.ok(loginService.imgCaptcha());
|
|
|
}
|
|
|
|
|
@@ -86,59 +88,39 @@ public class LoginController {
|
|
|
/**
|
|
|
* 发送验证码
|
|
|
*/
|
|
|
- @GetMapping("/captcha")
|
|
|
+ @PostMapping("/captcha")
|
|
|
@XjrLog(value = "发送验证码")
|
|
|
@ApiOperation(value = "发送验证码", notes = "传入账号:mobile")
|
|
|
- public R captcha(@RequestParam String mobile) {
|
|
|
- //生成六位数的字符串
|
|
|
- String code = RandomUtils.nextInt(100000, 999999) + StringPool.EMPTY;
|
|
|
-
|
|
|
- //华为短信向此手机号发送短信
|
|
|
-// SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.HUAWEI).sendMessage(mobile, code);
|
|
|
-
|
|
|
-// String result = SmsSender.getInstance().sendCaptcha(mobile, code);
|
|
|
+ public R captcha(@RequestBody @Valid CaptchaDto captchaDto) {
|
|
|
|
|
|
+// String captchaCode = redisUtil.get(captchaDto.getKey(), 0);
|
|
|
+// if (captchaCode == null) {
|
|
|
+// throw new MyException("验证码已过期,请刷新验证码!");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!captchaCode.equals(captchaDto.getCode())) {
|
|
|
+// throw new MyException("验证码不正确,请刷新验证码!");
|
|
|
+// }
|
|
|
|
|
|
- smsSender.sendCaptcha(mobile, code);
|
|
|
-// smsSender.sendNotify(mobile, null);
|
|
|
+ //生成六位数的字符串
|
|
|
+ String code = RandomUtils.nextInt(100000, 999999) + StringPool.EMPTY;
|
|
|
|
|
|
-// LinkedHashMap<String, String> map = SmsUtil.getNewMap();
|
|
|
-// map.put("code", code);
|
|
|
-//
|
|
|
-// SmsResponse smsResponse2 = SmsFactory.createSmsBlend(SupplierType.HUAWEI).sendMessage(mobile, "97c6fcf9fd0149b39c0ed0e53480116f", map);
|
|
|
+ smsCtcc.sendCaptcha(captchaDto.getMobile(), code);
|
|
|
|
|
|
- redisUtil.set(GlobalConstant.CAPTCHA + StringPool.UNDERSCORE + mobile, code, 60L);
|
|
|
return R.ok(Boolean.TRUE);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 验证码
|
|
|
+ * 验证码登录
|
|
|
*/
|
|
|
- @PostMapping("/captcha")
|
|
|
+ @PostMapping("/loginCaptcha")
|
|
|
@XjrLog(value = "验证码登录")
|
|
|
- public R loginByCaptcha(@RequestBody LoginCaptchaDto loginCaptchaDto) {
|
|
|
- String mobile = loginCaptchaDto.getMobile();
|
|
|
- String code = redisUtil.get(GlobalConstant.CAPTCHA + StringPool.UNDERSCORE + mobile);
|
|
|
- if (code != null && StringUtils.equals(code, loginCaptchaDto.getCode())) {
|
|
|
- User user = userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getMobile, mobile), false);
|
|
|
- if (user == null) {
|
|
|
- return R.error("用户不存在!");
|
|
|
- }
|
|
|
- if (user.getEnabledMark() == EnabledMark.DISABLED.getCode()) {
|
|
|
- return R.error("账户未启用");
|
|
|
- }
|
|
|
- //此登录接口登录web端
|
|
|
- StpUtil.login(user.getId(), "PC");
|
|
|
-
|
|
|
- SaSession tokenSession = StpUtil.getTokenSession();
|
|
|
- tokenSession.set(GlobalConstant.LOGIN_USER_INFO_KEY, user);
|
|
|
-
|
|
|
- Map<String, Object> vo = new HashMap<>(1);
|
|
|
- vo.put(GlobalConstant.TOKEN_KEY, StpUtil.getTokenValue());
|
|
|
-
|
|
|
- return R.ok(vo);
|
|
|
+ public R loginByCaptcha(@RequestBody LoginCaptchaDto loginCaptchaDto) throws Exception {
|
|
|
+ // 验证验证码
|
|
|
+ if (!smsCtcc.captchaVerify(loginCaptchaDto.getMobile(), loginCaptchaDto.getCode())) {
|
|
|
+ return R.error("验证码不正确!");
|
|
|
}
|
|
|
- return R.error("验证码不存在!");
|
|
|
+ return R.ok(loginService.loginByCaptcha(loginCaptchaDto));
|
|
|
}
|
|
|
|
|
|
|