|
@@ -2,6 +2,7 @@ package com.txz.cif.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
@@ -14,6 +15,7 @@ import com.txz.cif.dubbo.client.OperatingConfigDubboServiceClient;
|
|
|
import com.txz.cif.model.Account;
|
|
|
import com.txz.cif.model.User;
|
|
|
import com.txz.cif.service.AccountService;
|
|
|
+import com.txz.cif.service.CSHuaGuService;
|
|
|
import com.txz.cif.service.UserService;
|
|
|
import com.txz.cif.web.para.UserAddParam;
|
|
|
import org.slf4j.Logger;
|
|
@@ -53,6 +55,11 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|
|
@Resource
|
|
|
private OperatingConfigDubboServiceClient messageDubboServiceClient;
|
|
|
|
|
|
+ private static final String SMS_MESSAGE = "Your verification code is %s .It will expire in 5 minutes.Do not share it with anyone";
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CSHuaGuService csHuaGuService;
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean checkMail(String email) {
|
|
|
User user = findBy("email", email);
|
|
@@ -66,34 +73,38 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|
|
return String.format(RedisConstants.USER_SMS_CODE, email);
|
|
|
}
|
|
|
|
|
|
+ private String getSmsKey(String phoneNo) {
|
|
|
+ return String.format(RedisConstants.USER_SMS_LOGIN_CODE, phoneNo);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Result<Object> sendCode(String phoneNo) {
|
|
|
- String key = getKey(phoneNo);
|
|
|
+ String key = this.getSmsKey(phoneNo);
|
|
|
+ Object o = redisClient.get(key);
|
|
|
+ if (ObjectUtil.isNotEmpty(o)) {
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
String code = RandomUtil.randomNumbers(6);
|
|
|
- String subject = "来自Free City的CODE码";
|
|
|
- String content = "您的CODE为: " + code;
|
|
|
- // TODO 发短信
|
|
|
- // Result<Object> result = MailClient.send(email, subject, content, null);
|
|
|
- // if (result.isSuccess()) {
|
|
|
- // redisClient.set(key, code, 60);
|
|
|
- // }
|
|
|
- redisClient.set(key, code, 60);
|
|
|
- return Result.success(code);
|
|
|
+ if (csHuaGuService.sendValidCode(phoneNo, String.format(SMS_MESSAGE, code))) {
|
|
|
+ redisClient.set(key, code, 60 * 5);
|
|
|
+ return Result.fail();
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean checkCode(String phoneNo, String code) {
|
|
|
- if (StrUtil.equals("888888", code)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- log.error("checkCode phoneNo:" + phoneNo);
|
|
|
- log.error("checkCode code:" + code);
|
|
|
- String key = getKey(phoneNo);
|
|
|
+ // if (StrUtil.equals("888888", code)) {
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+ // log.error("checkCode phoneNo:" + phoneNo);
|
|
|
+ // log.error("checkCode code:" + code);
|
|
|
+ String key = this.getSmsKey(phoneNo);
|
|
|
Object o = redisClient.get(key);
|
|
|
- if (o != null) {
|
|
|
- log.error("checkCode o:" + o.toString());
|
|
|
+ if (ObjectUtil.isEmpty(o)) {
|
|
|
+ return false;
|
|
|
}
|
|
|
- if (o != null && StrUtil.equals(o.toString(), code)) {
|
|
|
+ if (StrUtil.equals(o.toString(), code)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
@@ -209,16 +220,18 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|
|
if (user == null) {
|
|
|
return ResultGenerator.genFailResult(ResultCode.USER_IS_NULL);
|
|
|
}
|
|
|
- //fixme 暂时跳过短验
|
|
|
- if (!verifyCode.equals("888888")) {
|
|
|
- String key = getKey(user.getPhoneNo());
|
|
|
- Object o = redisClient.get(key);
|
|
|
- if (!StrUtil.equals(o.toString(), verifyCode)) {
|
|
|
- return ResultGenerator.genFailResult(ResultCode.CODE_CHECK_FAIL);
|
|
|
- }
|
|
|
+ // if (!verifyCode.equals("888888")) {
|
|
|
+ String key = getSmsKey(user.getAreaCode() + user.getPhoneNo());
|
|
|
+ Object o = redisClient.get(key);
|
|
|
+ if (ObjectUtil.isNull(o)) {
|
|
|
+ return Result.fail();
|
|
|
+ }
|
|
|
+ if (!StrUtil.equals(o.toString(), verifyCode)) {
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.CODE_CHECK_FAIL);
|
|
|
}
|
|
|
+ // }
|
|
|
update(User.builder().id(user.getId()).pwd(SecureUtil.md5(newPwd + user.getSalt())).build());
|
|
|
-
|
|
|
+ redisClient.del(key);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
@@ -227,6 +240,11 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
|
|
|
return userMapper.getUsersByIds(Joiner.on(",").join(userIds));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void delCode(String phoneNo) {
|
|
|
+ redisClient.del(getSmsKey(phoneNo));
|
|
|
+ }
|
|
|
+
|
|
|
// @Override
|
|
|
// public boolean sendMsg(MessageParam param) {
|
|
|
// if (param == null){
|