短信功能完善
This commit is contained in:
parent
5aae85cadb
commit
c0fd7885dc
|
|
@ -8,7 +8,9 @@ import com.bonus.sgzb.common.core.exception.ServiceException;
|
|||
import com.bonus.sgzb.common.core.utils.GlobalConstants;
|
||||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.sgzb.common.redis.service.RedisService;
|
||||
import com.bonus.sgzb.system.api.domain.SysUser;
|
||||
import com.bonus.sgzb.system.config.TencentSmsConfig;
|
||||
import com.bonus.sgzb.system.mapper.SysUserMapper;
|
||||
import com.bonus.sgzb.system.service.ISysSmsService;
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
|
|
@ -43,6 +45,8 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
@Resource
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
@Resource
|
||||
private TencentSmsConfig tencentSmsConfig;
|
||||
|
|
@ -55,6 +59,7 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
|
||||
/**
|
||||
* 验收通知短信
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @param msg 内容
|
||||
* @return
|
||||
|
|
@ -79,6 +84,7 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
|
||||
/**
|
||||
* 登录短信验证码
|
||||
*
|
||||
* @param phone 手机号
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -102,6 +108,7 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
|
||||
/**
|
||||
* 发送消息msg到手机
|
||||
*
|
||||
* @param phone 手机号码
|
||||
* @return AjaxResult对象
|
||||
*/
|
||||
|
|
@ -128,6 +135,7 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
|
||||
/**
|
||||
* 发送验证码到手机
|
||||
*
|
||||
* @param phone 手机号码
|
||||
* @return AjaxResult对象
|
||||
*/
|
||||
|
|
@ -136,6 +144,11 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
if (phone == null || phone.length() != UserConstants.PHONE_DEFAULT_LENGTH_LOGIN) {
|
||||
return AjaxResult.error("手机号格式错误,请输入11位数字号码");
|
||||
}
|
||||
// 校验是否存在该手机号
|
||||
SysUser sysUser = sysUserMapper.checkPhoneUnique(phone);
|
||||
if (sysUser == null){
|
||||
return AjaxResult.error("该手机号未绑定用户,请重新确认");
|
||||
}
|
||||
String code = getSixBitCode();
|
||||
// 校验验证码
|
||||
if (code.length() != UserConstants.CODE_MIN_LENGTH_LOGIN) {
|
||||
|
|
@ -151,7 +164,8 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
}
|
||||
// 存储验证码至Redis中,键值为:code_15588886157 , 有效期5,时间颗粒度为MINUTES:分钟
|
||||
redisService.setCacheObject("code_" + phone, code, 5L, TimeUnit.MINUTES);
|
||||
return success("手机号:" + phone + ",用户登录验证码:" + code + ",返回结果:" + body);
|
||||
// return success("手机号:" + phone + ",用户登录验证码:" + code + ",返回结果:" + body);
|
||||
return success("验证码发送成功",body);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("发送失败:" + e.getMessage());
|
||||
}
|
||||
|
|
@ -195,6 +209,7 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
|
||||
/**
|
||||
* 腾讯sms短信
|
||||
*
|
||||
* @param mobilePhone
|
||||
* @param templateId
|
||||
* @param args
|
||||
|
|
|
|||
Loading…
Reference in New Issue