|
@@ -11,10 +11,15 @@ import com.rongwei.bsentity.vo.ZhcxOutsideInspectionVo;
|
|
|
import com.rongwei.commonservice.service.RedisService;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysUserDo;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysUserService;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.CheckPasswordUtils;
|
|
|
import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import lombok.extern.java.Log;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -24,6 +29,7 @@ import java.util.Random;
|
|
|
/**
|
|
|
* @author zhuang
|
|
|
*/
|
|
|
+@Log
|
|
|
@Service
|
|
|
public class ZhcxApiServiceImpl implements ZhcxApiService {
|
|
|
|
|
@@ -69,15 +75,84 @@ public class ZhcxApiServiceImpl implements ZhcxApiService {
|
|
|
if(StringUtils.isBlank(phone)){
|
|
|
return R.error("未获取到手机号,请联系系统管理员");
|
|
|
}
|
|
|
- boolean exists = redisService.hasKey(loginType + phone);
|
|
|
- String sendCodeTimeObj = (String) redisService.getRedisCatchObj(loginType + phone);
|
|
|
+ String redisKeyName = loginType + phone;
|
|
|
+ String redisLabelName = loginType + account;
|
|
|
+ return sendSmsCode(null, redisKeyName, phone, redisLabelName);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R getAccountInfoForForgotPassword(Map<String, Object> map) {
|
|
|
+ String account = map.get("account").toString();
|
|
|
+ LambdaQueryWrapper<SysUserDo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.and(i -> i.eq(SysUserDo::getAccount, account));
|
|
|
+ SysUserDo sysUserDo = sysUserService.getOne(queryWrapper);
|
|
|
+ if (sysUserDo == null) {
|
|
|
+ return R.error("账号信息输入有误, 请重新输入!");
|
|
|
+ }
|
|
|
+ String sendType = map.get("sendType").toString();
|
|
|
+ String loginType = map.get("loginType").toString();
|
|
|
+ String smsCodeTpl = map.get("smsCodeTpl").toString();
|
|
|
+ String phone = sysUserDo.getMobile();
|
|
|
+ String redisKeyName = "forgot_password_" + loginType + phone;
|
|
|
+ String redisLabelName = "forgot_password_" + loginType + account;
|
|
|
+ if (sendType.contains("sms")) {
|
|
|
+ return sendSmsCode(smsCodeTpl, redisKeyName, phone, redisLabelName);
|
|
|
+ }
|
|
|
+ return R.error("获取账号信息失败, 请联系管理员!");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R resetPassword(Map<String, Object> map) {
|
|
|
+
|
|
|
+ Object loginTypeObj = map.get("loginType");
|
|
|
+ Object accountObj = map.get("account");
|
|
|
+ Object passwordObj = map.get("password");
|
|
|
+ Object codeObj = map.get("smsCode");
|
|
|
+ if( ObjectUtil.isNotEmpty(loginTypeObj) && ObjectUtil.isNotEmpty(accountObj) && ObjectUtil.isNotEmpty(passwordObj)
|
|
|
+ && ObjectUtil.isNotEmpty(codeObj)){
|
|
|
+ LambdaQueryWrapper<SysUserDo> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.and(i -> i.eq(SysUserDo::getAccount, accountObj.toString()));
|
|
|
+ SysUserDo sysUserDo = sysUserService.getOne(queryWrapper);
|
|
|
+ String redisKeyName = "forgot_password_" + loginTypeObj.toString() + accountObj.toString();
|
|
|
+ boolean exist = redisService.hasKey(redisKeyName);
|
|
|
+ if (exist) {
|
|
|
+ Object yzmObj = redisService.getRedisCatchObj(redisKeyName);
|
|
|
+ if(ObjectUtil.isEmpty(yzmObj)){
|
|
|
+ return R.error("未获取到验证码或验证码已过期,请获取验证码");
|
|
|
+ }
|
|
|
+ String yzm = (String) yzmObj;
|
|
|
+ if (codeObj.toString().equals(yzm)) {
|
|
|
+ Boolean ischeck = CheckPasswordUtils.checkPasswordDefaultRule(passwordObj.toString());
|
|
|
+ if(!ischeck){
|
|
|
+ return R.error("密码长度不小于8,并且大写字母、小写字母、数字、特殊字符,至少包含三种");
|
|
|
+ }
|
|
|
+ sysUserDo.setPassword(SecurityUtil.getSaltMd5AndSha(passwordObj.toString(), sysUserDo.getId()));
|
|
|
+ sysUserService.updateById(sysUserDo);
|
|
|
+ RedisTemplate redisTemplate = redisService.getRedisTemplate();
|
|
|
+ redisTemplate.delete(redisKeyName);
|
|
|
+ redisTemplate.delete("forgot_password_" + loginTypeObj.toString() + sysUserDo.getMobile());
|
|
|
+ return R.ok();
|
|
|
+ } else {
|
|
|
+ return R.error("验证码错误,请重新输入");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return R.error("未获取到验证码或验证码已过期,请获取验证码");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.error("重置密码失败, 请联系管理员!");
|
|
|
+ }
|
|
|
+
|
|
|
+ private R sendSmsCode(String templateId, String redisKeyName, String mobile, String redisLabelName) {
|
|
|
+ boolean exists = redisService.hasKey(redisKeyName);
|
|
|
+ String sendCodeTimeObj = (String) redisService.getRedisCatchObj(redisKeyName);
|
|
|
if (StringUtils.isBlank(sendCodeTimeObj)) {
|
|
|
sendCodeTimeObj = "0";
|
|
|
}
|
|
|
int sendCodeTime = Integer.parseInt(sendCodeTimeObj);
|
|
|
if( exists && sendCodeTime >= 3 ){
|
|
|
sendCodeTime += 1;
|
|
|
- redisService.redisCatchInit(loginType + phone,String.valueOf(sendCodeTime),300);
|
|
|
+ redisService.redisCatchInit(redisKeyName,String.valueOf(sendCodeTime),300);
|
|
|
return R.error("验证发送次数频繁,请过5分钟后再尝试");
|
|
|
}
|
|
|
StringBuilder code = new StringBuilder();
|
|
@@ -89,22 +164,22 @@ public class ZhcxApiServiceImpl implements ZhcxApiService {
|
|
|
}
|
|
|
}
|
|
|
try {
|
|
|
- JSONObject jsonObject = HwSmsUtil.sendSms(code.toString(), phone);
|
|
|
+ JSONObject jsonObject = HwSmsUtil.sendSms(templateId, code.toString(), mobile);
|
|
|
String returnCode = jsonObject.getString("code");
|
|
|
if("000000".equals(returnCode)){
|
|
|
if(!exists){
|
|
|
- redisService.redisCatchInit(loginType + phone,0,300);
|
|
|
+ redisService.redisCatchInit(redisKeyName,0,300);
|
|
|
}
|
|
|
sendCodeTime += 1;
|
|
|
- redisService.redisCatchInit(loginType + phone,String.valueOf(sendCodeTime),300);
|
|
|
- redisService.redisCatchInit(loginType + account,code.toString(),120);
|
|
|
+ redisService.redisCatchInit(redisKeyName,String.valueOf(sendCodeTime),300);
|
|
|
+ redisService.redisCatchInit(redisLabelName,code.toString(),120);
|
|
|
JSONObject json = new JSONObject();
|
|
|
- json.put("phone",phone.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2"));
|
|
|
+ json.put("phone",mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2"));
|
|
|
return R.ok("发送成功").putData(json);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return R.error();
|
|
|
+ return R.error("获取账号信息失败, 请联系管理员!");
|
|
|
}
|
|
|
}
|