SmsCodeServiceImpl.java
1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.meishu.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meishu.common.exception.HttpException;
import com.meishu.dto.sms.SendVerifyCodeDTO;
import com.meishu.model.SmsCodeDO;
import com.meishu.mapper.SmsCodeMapper;
import com.meishu.model.UserRoleDO;
import com.meishu.service.SmsCodeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.service.UserRoleService;
import com.meishu.util.ConstantUtils;
import com.meishu.util.RandomUtil;
import com.meishu.util.SMSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
* 短信验证码 服务实现类
* </p>
*
* @author Tuyp
* @since 2021-04-25
*/
@Service
public class SmsCodeServiceImpl extends ServiceImpl<SmsCodeMapper, SmsCodeDO> implements SmsCodeService {
@Autowired
private SMSUtils smsUtils;
@Autowired
private UserRoleService userRoleService;
@Override
public void sendVerifyCode(SendVerifyCodeDTO sendVerifyCodeDTO) {
UserRoleDO userRoleDO =userRoleService.getOne(new QueryWrapper<UserRoleDO>()
.lambda()
.eq(UserRoleDO::getPhone, sendVerifyCodeDTO.getPhone()));
if(userRoleDO == null) {
throw new HttpException(70012);
}
String code = RandomUtil.getRandomCode(6);
smsUtils.send(sendVerifyCodeDTO.getPhone(), code);
SmsCodeDO smsCodeDO = new SmsCodeDO();
smsCodeDO.setCode(code);
smsCodeDO.setTelephone(sendVerifyCodeDTO.getPhone());
this.baseMapper.insert(smsCodeDO);
}
}