SmsVerifyCodeServiceImpl.java
1.72 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
53
54
55
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.sms.SendVerifyCodeDTO;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.model.MemberDO;
import com.subsidy.model.SmsVerifyCodeDO;
import com.subsidy.mapper.SmsVerifyCodeMapper;
import com.subsidy.service.MemberService;
import com.subsidy.service.SmsVerifyCodeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.RandomUtil;
import com.subsidy.util.SMSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.Member;
/**
* <p>
* 短信验证码记录表 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-14
*/
@Service
public class SmsVerifyCodeServiceImpl extends ServiceImpl<SmsVerifyCodeMapper, SmsVerifyCodeDO> implements SmsVerifyCodeService {
@Autowired
private SMSUtils smsUtils;
@Autowired
private MemberMapper memberMapper;
public void sendVerifyCode(SendVerifyCodeDTO sendVerifyCodeDTO){
MemberDO memberDO =memberMapper.selectOne(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getTelephone, sendVerifyCodeDTO.getTelephone()));
if(memberDO == null) {
throw new HttpException(70012);
}
String code = RandomUtil.getRandomCode(6);
smsUtils.send(sendVerifyCodeDTO.getTelephone(), code);
SmsVerifyCodeDO smsCodeDO = new SmsVerifyCodeDO();
smsCodeDO.setVerifyCode(code);
smsCodeDO.setTelephone(sendVerifyCodeDTO.getTelephone());
this.baseMapper.insert(smsCodeDO);
}
}