java110
2020-12-17 b187bd87553a986e4c5344fa29a64561442793fd
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
package com.java110.core.factory;
 
import com.java110.utils.cache.MappingCache;
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);
        }
    }
 
    /**
     * 生成验证码
     *
     * @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;
    }
}