dhz
2022-06-22 06856202544f4324e27896e8a7b2fcf1298f5c68
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package cn.ksource.core.util;
 
import java.util.HashMap;
import java.util.Map;
 
import org.apache.log4j.Logger;
 
import cn.ksource.web.Constants;
 
 
/**
 * 发送短信接口
 * @author jxl
 *
 */
public class SMSUtil {
 
    //短信模板常量=================================
    //发送验证码模板
    private static String sendVaildCode = "【"+Constants.company_name+"】您于#datetime#申请手机号码绑定,验证码是#code#,2分钟内有效。";
    
    //工单提醒短信模板
    private static String orderTip = "【"+Constants.company_name+"】您有一条#ordertype#工单,标题#ordertitle#,请及时处理 ";
    
    //工单催办
    private static String orderRemind = "【"+Constants.company_name+"】#reminder#催办了工单编号[#order_code#],工单名称[#order_name#]的工单,请尽快办理。#remind_content#";
    
    //加盟商注册
    private static String registerCode = "【"+Constants.company_name+"】感谢您注册"+Constants.company_name+",您的验证码是#code#";
    
    //加盟商注册
    private static String registermsgCode = "【"+Constants.company_name+"】#company#申请注册加盟商,联系人#user#,手机号#phone#。";
    
    //找回密码
    private static String findpwdCode = "【"+Constants.company_name+"】正在找回密码,您的验证码是#code#";
    
    //报警短信
    private static String alarmCode = "【"+Constants.company_name+"】监控对象'#ciName#',IP地址#ip#,于#alarmTime#,当前值为:#currentValue#,阀值为#setingValue#";
 
    //短信模板常量=================================
    
    private static Logger logger = Logger.getLogger(SMSUtil.class);
    
    /**
     * 报警发送信息
     * @param ciName 设备名称
     * @param ip ip地址
     * @param alarmTime 时间+异常项+告警类型
     * @param setingValue 异常值
     * @param conditions 异常条件
     * @return
     */
    public static String getAlarmCodeMsg(String ciName,String ip,String alarmTime,String currentValue,String setingValue) {
        String message = SMSUtil.alarmCode;
        message = message.replaceAll("#ciName#", ciName);
        message = message.replaceAll("#ip#", ip);
        message = message.replaceAll("#alarmTime#", alarmTime);
        message = message.replaceAll("#currentValue#", currentValue);
        message = message.replaceAll("#setingValue#", setingValue);
        return message;
    }
    
    /**
     * 获取短信验证码发送信息
     * @param date 发送日期
     * @param code 验证码
     * @return
     */
    public static String getVaildCodeMsg(String date,String code) {
        String message = SMSUtil.sendVaildCode;
        message = message.replaceAll("#datetime#", date);
        message = message.replaceAll("#code#", code);
        return message;
    }
    
    /**
     * 获取工单提醒短信模板发送信息
     * @param ordreType 工单类型
     * @param orderTitle 工单标题
     * @return
     */
    public static String getOrderTipMsg(String ordreType,String orderTitle) {
        String message = SMSUtil.orderTip;
        message = message.replaceAll("#ordertype#", ordreType);
        message = message.replaceAll("#ordertitle#", "["+orderTitle+"]");
        return message;
    }
    
    
    
    public static String getOrderRemindMsg(String reminder,String order_code,String order_name,String remind_content){
        String message =  SMSUtil.orderRemind;
        message = message.replaceAll("#reminder#", reminder);
        message = message.replaceAll("#order_code#", order_code);
        message = message.replaceAll("#order_name#", order_name);
        if(StringUtil.isNotBlank(remind_content)){
            message = message.replaceAll("#remind_content#", "催办内容:"+remind_content);
        }else{
            message = message.replaceAll("#remind_content#", " ");
        }
        return message;
    }
    
    /**
     * 获取短信验证码发送信息
     * @param date 发送日期
     * @param code 验证码
     * @return
     */
    public static String getregisterCodeMsg(String code) {
        String message = SMSUtil.registerCode;
        message = message.replaceAll("#code#", code);
        return message;
    }
    
    /**
     * 获取短信验证码发送信息
     * @param date 发送日期
     * @param code 验证码
     * @return
     */
    public static String getregistermsgCodeMsg(String company,String user,String phone) {
        String message = SMSUtil.registermsgCode;
        message = message.replaceAll("#company#", company);
        message = message.replaceAll("#user#", user);
        message = message.replaceAll("#phone#", phone);
        return message;
    }
    
    /**
     * 获取短信验证码发送信息
     * @param date 发送日期
     * @param code 验证码
     * @return
     */
    public static String getfindpwdCodeMsg(String code) {
        String message = SMSUtil.findpwdCode;
        message = message.replaceAll("#code#", code);
        return message;
    }
    
    
    /**
     * 发送短信
     * @param GG_MESSAGE 接收信息的号码
     * @param mobile 手机号码字符串 多个号码以逗号分割
     * @return
     * @throws Exception
     */
    public static String sendSMS(String message,String mobile) throws Exception {
        if(StringUtil.isNotBlank(mobile)){
            Map<String, String> param = new HashMap<String, String>();
            param.put("apikey", Constants.GG_SMS_KEY);
            param.put("mobile", mobile);
            param.put("text", message);
            String result =  HttpUtil.doPost(Constants.GG_SMS_URL, param, HttpCharset.UTF8);
            Map resultMap = JsonUtil.json2Map(result);
            String code = ConvertUtil.obj2StrBlank(resultMap.get("code"));
            System.out.println("code---------------->"+code);
            if(code.equals("0")) {
                return "0";
            }
            return code;
        }else{
            return "无手机号码";
        }
    }
    
}