xuekang
2024-05-11 bac0878349a1db23e7b420ea164e22fb9db73a99
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
package com.nuvole.util.sms;
 
import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.nuvole.common.domain.emnu.SMSResultEmnu;
import com.nuvole.common.domain.result.SMSResult;
import com.nuvole.constants.ServiceConstants;
import com.nuvole.util.sc.sms.ScSMSUtil;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 发送短信(统一调度类)
 *
 * @Author: lc
 * @Date: 2019/6/1 11:09
 */
public class SMSCallUtil {
 
    /**
     * 短信接口类型(1.云片 2.四川省内部接口)
     */
    private final static int SMS_TYPE = 1;
 
    /**
     * 发送短信
     *
     * @param mobile  手机号码字符串 多个号码以逗号分割
     * @param message 短信内容
     * @Author: lc
     * @Date: 2019/6/1 11:27
     */
    public static SMSResult sendSMS(String mobile, String message) {
 
        //走外网服务调用
        if (ServiceConstants.SERVICE_TYPE) {
            Map map = new HashMap() {{
                put("mobile", mobile);
                put("message", message);
                put("smsType", SMS_TYPE);
            }};
            String result = HttpUtil.get(ServiceConstants.SERVICE_SMS_URL, map);
            JSONObject jsonObject = JSONObject.parseObject(result);
            if (!"0".equals(jsonObject.getString("code"))) {
                return new SMSResult(SMSResultEmnu.ERROR, jsonObject.getString("msg"));
            }
            return new SMSResult(SMSResultEmnu.OK);
        } else {
            switch (SMS_TYPE) {
                case 1:
                    return YpSMSUtil.sendSMS(mobile, message);
                case 2:
                    return ScSMSUtil.sendSMS(mobile, message);
                default:
                    break;
            }
            return new SMSResult(SMSResultEmnu.ERROR);
        }
    }
 
    public static void main(String[] args) {
        System.out.println(sendSMS("17803846500", SMSTemplate.getVaildCodeMsg(RandomUtil.randomNumbers(6))));
    }
 
}