shane
2021-08-20 ab6a423cf604b83f06b5768dbc162ece744a32d9
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.java110.core.factory;
 
import com.java110.dto.smsConfig.SmsConfigDto;
import com.java110.utils.cache.MappingCache;
import com.java110.vo.ResultVo;
import org.apache.commons.lang3.StringUtils;
 
import java.util.Random;
 
/**
 * @ClassName SendSmsFactory
 * @Description 验证码短信发送接口
 * @Author wuxw
 * @Date 2020/2/10 10:14
 * @Version 1.0
 * add by wuxw 2020/2/10
 **/
public class SendSmsFactory {
 
    private static final String SMS_DOMAIN = "SMS_DOMAIN";
    private static final String SMS_COMPANY = "SMS_COMPANY";
    private static final String SMS_COMPANY_ALI = "ALI";
    private static final String SMS_COMPANY_TENCENT = "TENCENT";
    public static final String VALIDATE_CODE = "_validateTel";
 
    /**
     * 短信开关
     */
    public static final String SMS_SEND_SWITCH = "SMS_SEND_SWITCH";
 
    public static void sendSms(String tel, String code) {
 
        String smsCompany = MappingCache.getValue(SMS_DOMAIN, SMS_COMPANY);
 
        if (!StringUtils.isEmpty(smsCompany) && SMS_COMPANY_ALI.equals(smsCompany.trim())) {
            AliSendMessageFactory.sendMessage(tel, code);
        } else {
            TencentSendMessageFactory.sendMessage(tel, code);
        }
    }
 
    public static ResultVo sendOweFeeSms(String tel, SmsConfigDto smsConfigDto, Object param){
 
        ResultVo resultVo = null;
        if (SMS_COMPANY_ALI.equals(smsConfigDto.getSmsType().trim())) {
            resultVo = AliSendMessageFactory.sendOweFeeSms(tel, param,smsConfigDto);
        } else {
            resultVo = TencentSendMessageFactory.sendOweFeeSms(tel, param,smsConfigDto);
        }
 
        return resultVo;
    }
 
 
 
    /**
     * 生成验证码
     *
     * @param limit 位数
     * @return
     */
    public static String generateMessageCode(int limit) {
        Random random = new Random();
        String result = "";
        for (int i = 0; i < limit; i++) {
            result += (random.nextInt(9) + 1);
        }
        return result;
    }
}