待发短信

在线客服
产品支持 短信宝客服
合作渠道 渠道合作
服务咨询

4001-021-502

工作时间

9:00-18:00

巡云轻论坛系统5.3新增短信宝短信接口

巡云轻论坛系统包含论坛、问答模块。系统采用JAVA+MYSQL架构,自适应手机端和电脑端,界面简洁,性能高效。后台数据库备份/还原、全站指定目录打包、一键自动升级等功能使维护简单方便。系统拥有强大的模板管理功能,布局版块支持设置输出条件,让前端页面展示方便快捷,是一款非常优秀的论坛系统。小编今天就以替换短信接口为例带大家进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用

搭建好开发环境后

打开项目:/src/main/java/cms/bean/SendService.java 在25行后添加

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    /** 短信宝短信签名 **/
    private String  smsbao_signName;
    /** 短信宝短信模板代码 **/
    private String smsbao_templateCode;
    /** 短信宝支持变量 key:变量字段  value:备注 /** 
/** 在SendService.java最后后添加以下内容 /** 
        public String getSmsbao_signName() {
        return smsbao_signName;
    }
    public void setSmsbao_signName(String smsbao_signName) {
        this.smsbao_signName = smsbao_signName;
    }
    public String getSmsbao_templateCode() {
        return smsbao_templateCode;
    }
    public void setSmsbao_templateCode(String smsbao_templateCode) {
        this.smsbao_templateCode = smsbao_templateCode;
    }
    public Map<String, String> getSmsbao_variable() {
        return smsbao_variable;
    }
    public void setSmsbao_variable(Map<String, String> smsbao_variable) {
        this.smsbao_variable = smsbao_variable;
    }

在项目:/src/main/java/cms/bean 下新建Smsbao.java内容如下

?
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
package cms.bean.sms;
 
import java.io.Serializable;
 
/**
 * 短信宝参数
 *
 */
public class Smsbao implements Serializable{
    private static final long serialVersionUID = 2209384057991960031L;
 
    private String accessKeyId="";
    
    private String accessKeySecret="";
 
    public String getAccessKeyId() {
        return accessKeyId;
    }
 
    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }
 
    public String getAccessKeySecret() {
        return accessKeySecret;
    }
 
    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }
    
    
}

打开项目:/src/main/java/cms/web/action/SmsManage.java

导入相关包、添加短信宝发送函数、添加发送函数相关函数

?
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
package cms.web.action.sms;
 
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
import javax.annotation.Resource;
 
import cms.bean.sms.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
 
 import com.aliyuncs.DefaultAcsClient;
 import com.aliyuncs.IAcsClient;
 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
 import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
 import com.aliyuncs.exceptions.ClientException;
 import com.aliyuncs.exceptions.ServerException;
 import com.aliyuncs.profile.DefaultProfile;
 import com.aliyuncs.profile.IClientProfile;
import com.fasterxml.jackson.core.type.TypeReference;
 
import cms.bean.setting.SystemSetting;
import cms.service.setting.SettingService;
import cms.service.sms.SmsService;
import cms.utils.JsonUtils;
 
/**
 * 短信管理
 *
 */
@Component("smsManage")
public class SmsManage {
    private static final Logger logger = LogManager.getLogger(SmsManage.class);
    @Resource SmsService smsService;//通过接口引用代理返回的对象
 
    @Resource SmsManage smsManage;
    @Resource SettingService settingService;
 
    //产品名称:云通信短信API产品,开发者无需替换
    private static final String product = "Dysmsapi";
    //产品域名,开发者无需替换
    private static final String domain = "dysmsapi.aliyuncs.com";
 
    /**
     * 生成短信发送服务
     * @param interfaceProduct 接口产品
     * @return
     */
    public List<SendService> createSendService(Integer interfaceProduct){
        List<SendService> sendServiceList = new ArrayList<SendService>();
        if(interfaceProduct.equals(1)){//阿里大于
            SendService sendService_1 = new SendService();
            sendService_1.setInterfaceProduct(interfaceProduct);
            sendService_1.setServiceId(1);
            sendService_1.setServiceName("绑定手机服务");
            /** 支持变量 key:变量字段  value:备注 **/
            Map<String,String> variable_1 = new LinkedHashMap<String,String>();
            variable_1.put("${number}""短信验证码");
            sendService_1.setAlidayu_variable(variable_1);
            sendServiceList.add(sendService_1);
            /**
            SendService sendService_10 = new SendService();
            sendService_10.setInterfaceProduct(interfaceProduct);
            sendService_10.setServiceId(10);
            sendService_10.setServiceName("短信营销服务");
            sendServiceList.add(sendService_10);
            **/
        }else if(interfaceProduct.equals(9)){//短信宝
            SendService sendService_9 = new SendService();
            sendService_9.setInterfaceProduct(interfaceProduct);
            sendService_9.setServiceId(1);
            sendService_9.setServiceName("绑定手机服务");
            /** 支持变量 key:变量字段  value:备注 **/
            Map<String,String> variable_9 = new LinkedHashMap<String,String>();
            variable_9.put("${number}""短信验证码");
            sendService_9.setSmsbao_variable(variable_9);
            sendServiceList.add(sendService_9);
        }
        return sendServiceList;
    }
 
 
    /**
     * 发送短信验证码
     * @param platformUserId 平台用户Id
     * @param mobile 手机号
     * @param code 验证码
     * @return
     */
    public String sendSms_code(String platformUserId,String mobile,String code){
 
        String errorInfo = null;
 
        SystemSetting systemSetting = settingService.findSystemSetting_cache();
        if(systemSetting.getUserSentSmsCount() != null && systemSetting.getUserSentSmsCount() >0){
            int count = smsManage.addSentSmsCount(platformUserId, 0);//先查询发送次数
            if(count >= systemSetting.getUserSentSmsCount()){
                errorInfo = "超出每用户每24小时内发送短信限制次数";
            }
        }
        if(errorInfo == null){//如果没有错误
            SmsInterface smsInterface = smsService.findEnableInterface_cache();
            if(smsInterface != null){
                if(smsInterface.getInterfaceProduct().equals(1)){//1.阿里大于
                    String accessKeyId=null;
                    String accessKeySecret=null;
                    //阿里大于短信签名
                    String alidayu_signName=null;
                    //阿里大于短信模板代码
                    String alidayu_templateCode=null;
 
                    Integer serviceId = null;
 
                    if(smsInterface.getDynamicParameter() != null && !"".equals(smsInterface.getDynamicParameter().trim())){
                        Alidayu alidayu = JsonUtils.toObject(smsInterface.getDynamicParameter(), Alidayu.class);
                        if(alidayu != null){
                            accessKeyId = alidayu.getAccessKeyId();
                            accessKeySecret=alidayu.getAccessKeySecret();
                        }
 
 
                    }
                    if(smsInterface.getSendService() != null && !"".equals(smsInterface.getSendService().trim())){
                        List<SendService> _sendServiceList = JsonUtils.toGenericObject(smsInterface.getSendService(), new TypeReference< List<SendService> >(){});
                        if(_sendServiceList != null && _sendServiceList.size() >0){
                            for(SendService _sendService : _sendServiceList){
                                if(_sendService.getServiceId().equals(1)){//1.绑定手机服务
                                    alidayu_signName = _sendService.getAlidayu_signName();
                                    alidayu_templateCode = _sendService.getAlidayu_templateCode();
                                    serviceId = _sendService.getServiceId();
                                }
                            }
                        }
                    }
 
                    if(accessKeyId == null || "".equals(accessKeyId)){
                        errorInfo = "请配置用户密钥";
                    }
                    if(accessKeySecret == null || "".equals(accessKeySecret)){
                        errorInfo = "请配置用户密钥";
                    }
                    if(alidayu_signName == null || "".equals(alidayu_signName)){
                        errorInfo = "请配置短信签名";
                    }
                    if(alidayu_templateCode == null || "".equals(alidayu_templateCode)){
                        errorInfo = "请配置短信模板代码";
                    }
 
                    if(errorInfo == null){//如果没有错误
                        System.setProperty("sun.net.client.defaultConnectTimeout""10000");//连接主机的超时时间(单位:毫秒)
                        System.setProperty("sun.net.client.defaultReadTimeout""10000");//从主机读取数据的超时时间(单位:毫秒)
 
                        //初始化acsClient,暂不支持region化
                        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
                        try {
                            DefaultProfile.addEndpoint("cn-hangzhou""cn-hangzhou", product, domain);
                        catch (ClientException e) {
                            errorInfo = "发送服务初始化错误";
                            if (logger.isErrorEnabled()) {
                                logger.error("阿里大于初始化错误",e);
                            }
                            // TODO Auto-generated catch block
                        //  e.printStackTrace();
                        }
                        IAcsClient acsClient = new DefaultAcsClient(profile);
 
                      //组装请求对象-具体描述见控制台-文档部分内容
                        SendSmsRequest request = new SendSmsRequest();
                        //必填:待发送手机号
                        request.setPhoneNumbers(mobile);
                        //必填:短信签名-可在短信控制台中找到
                        request.setSignName(alidayu_signName);
                        //必填:短信模板-可在短信控制台中找到
                        request.setTemplateCode(alidayu_templateCode);
                        //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
                        request.setTemplateParam("{\"number\":\""+code+"\"}");
 
                        //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
                        //request.setSmsUpExtendCode("90997");
 
                        //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
                        request.setOutId(platformUserId);
 
                        //hint 此处可能会抛出异常,注意catch
                        try {
                            SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
                            if(sendSmsResponse != null){
                                if(!"OK".equals(sendSmsResponse.getCode())){
                                    errorInfo = "短信发送错误";
 
                                    //错误日志
                                    SendSmsLog sendSmsLog = new SendSmsLog();
                                    sendSmsLog.setInterfaceProduct(smsInterface.getInterfaceProduct());//接口产品
                                    sendSmsLog.setServiceId(serviceId);//服务Id
                                    sendSmsLog.setPlatformUserId(platformUserId);;//平台用户Id
                                    sendSmsLog.setMobile(mobile);//手机
                                    sendSmsLog.setCode(sendSmsResponse.getCode());//状态码-返回OK代表请求成功,其他错误码详见错误码列表
                                    sendSmsLog.setMessage(sendSmsResponse.getMessage());//状态码描述
                                //  sendSmsLog.setAlidayu_requestId(sendSmsResponse.getRequestId());//请求ID
                                //  sendSmsLog.setAlidayu_bizId(sendSmsResponse.getBizId());//发送回执ID,可根据该ID查询具体的发送状态
                                    smsService.saveSendSmsLog(sendSmsLog);
                                }else{
                                    int original = smsManage.addSentSmsCount(platformUserId, 0);//原来总次数
                                    smsManage.deleteSentSmsCount(platformUserId);
                                    //增加发送短信次数记录
                                    smsManage.addSentSmsCount(platformUserId,original+1);
                                }
 
                            }
                        catch (ServerException e) {
                            errorInfo = "发送服务错误";
                            if (logger.isErrorEnabled()) {
                                logger.error("阿里大于错误",e);
                            }
                    //      e.printStackTrace();
                        catch (ClientException e) {
                            errorInfo = "发送服务错误";
                            if (logger.isErrorEnabled()) {
                                logger.error("阿里大于错误",e);
                            }
 
                        //  e.printStackTrace();
                        }
 
                    }
                }else if(smsInterface.getInterfaceProduct().equals(9)) {//短信宝
                    String accessKeyId = null;
                    String accessKeySecret = null;
                    //短信宝短信签名
                    String smsbao_signName = null;
                    //短信宝短信模板代码
                    String  smsbao_templateCode = null;
 
                    Integer serviceId = null;
 
                    if (smsInterface.getDynamicParameter() != null && !"".equals(smsInterface.getDynamicParameter().trim())) {
                        Smsbao smsbao = JsonUtils.toObject(smsInterface.getDynamicParameter(), Smsbao.class);
                        if (smsbao != null) {
                            accessKeyId = smsbao.getAccessKeyId();
                            accessKeySecret = smsbao.getAccessKeySecret();
                        }
 
 
                    }
                    if (smsInterface.getSendService() != null && !"".equals(smsInterface.getSendService().trim())) {
                        List<SendService> _sendServiceList = JsonUtils.toGenericObject(smsInterface.getSendService(), new TypeReference<List<SendService>>() {
                        });
                        if (_sendServiceList != null && _sendServiceList.size() > 0) {
                            for (SendService _sendService : _sendServiceList) {
                                if (_sendService.getServiceId().equals(1)) {//1.绑定手机服务
                                    smsbao_signName = _sendService.getSmsbao_signName();
                                    smsbao_templateCode = _sendService.getSmsbao_templateCode();
                                    serviceId = _sendService.getServiceId();
                                }
                            }
                        }
                    }
 
                    if (accessKeyId == null || "".equals(accessKeyId)) {
                        errorInfo = "请配置短信宝帐号";
                    }
                    if (accessKeySecret == null || "".equals(accessKeySecret)) {
                        errorInfo = "请配置短信宝密码";
                    }
                    if (smsbao_signName == null || "".equals(smsbao_signName)) {
                        errorInfo = "请配置短信签名";
                    }
                    if (smsbao_templateCode == null || "".equals(smsbao_templateCode)) {
                        errorInfo = "请配置短信模板";
                    }
 
                    if (errorInfo == null) {//如果没有错误
                        String smsbaoUsername = accessKeyId; //在短信宝注册的用户名
                        String smsbaoPassword = accessKeySecret; //在短信宝注册的密码
                        String smsbaosignName = smsbao_signName;
                        String smsbaosigntemplate = smsbao_templateCode.replace("${number}", code);
                        String smsbaoContent = "【 " + smsbaosignName + " 】" + smsbaosigntemplate;
 
                        String httpUrl = "http://api.smsbao.com/sms";
 
                        StringBuffer httpArg = new StringBuffer();
                        httpArg.append("u=").append(smsbaoUsername).append("&");
                        httpArg.append("p=").append(md5(smsbaoPassword)).append("&");
                        httpArg.append("m=").append(mobile).append("&");
                        httpArg.append("c=").append(encodeUrlString(smsbaoContent, "UTF-8"));
                        String result = request(httpUrl, httpArg.toString());
                        if (result != null) {
                            if (!"0".equals(result)) {
                                errorInfo = result;
 
                                //错误日志
                                SendSmsLog sendSmsLog = new SendSmsLog();
                                sendSmsLog.setInterfaceProduct(smsInterface.getInterfaceProduct());//接口产品
                                sendSmsLog.setServiceId(1);//服务Id
                                sendSmsLog.setPlatformUserId(accessKeyId);
                                ;//平台用户Id
                                sendSmsLog.setMobile(mobile);//手机
                                sendSmsLog.setCode(result);//状态码-返回0代表请求成功
                                sendSmsLog.setMessage(result);//状态码描述
                                smsService.saveSendSmsLog(sendSmsLog);
                            else {
                                int original = smsManage.addSentSmsCount(platformUserId, 0);//原来总次数
                                smsManage.deleteSentSmsCount(platformUserId);
                                //增加发送短信次数记录
                                smsManage.addSentSmsCount(platformUserId, original + 1);
                            }
                        }
                    }
                }
                }
            }else{
            errorInfo = "没有配置短信接口";
        }
        return errorInfo;
                }
    public static String request(String httpUrl, String httpArg) {
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        httpUrl = httpUrl + "?" + httpArg;
 
        try {
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            String strRead = reader.readLine();
            if (strRead != null) {
                sbf.append(strRead);
                while ((strRead = reader.readLine()) != null) {
                    sbf.append("\n");
                    sbf.append(strRead);
                }
            }
            reader.close();
            result = sbf.toString();
        catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
 
    public static String md5(String plainText) {
        StringBuffer buf = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            int i;
            buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
        catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return buf.toString();
    }
 
    public static String encodeUrlString(String str, String charset) {
        String strret = null;
        if (str == null)
            return str;
        try {
            strret = java.net.URLEncoder.encode(str, charset);
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return strret;
    }
    /**
     * 缓存增加用户发短信次数
     * @param platformUserId 平台用户Id
     * @param count 发送总数
     */
    @Cacheable(value="smsManage_cache_sentSmsCount",key="#platformUserId")
    public Integer addSentSmsCount(String platformUserId,Integer count){
        return count;
    }
    /**
     * 删除缓存用户发短信次数
     * @param platformUserId 平台用户Id
    */
    @CacheEvict(value="smsManage_cache_sentSmsCount",key="#platformUserId")
    public void deleteSentSmsCount(String platformUserId){
    
    
    
    
    /**
     * 生成手机验证码标记
     * @param module 模块 1.绑定手机  2.更换绑定手机第一步  3.更换绑定手机第二步   100.注册   200.登录 300.找回密码
     * @param platformUserId 平台用户Id
     * @param mobile 手机号
     * @param mobile 验证码
     * @return
     */
    @Cacheable(value="smsManage_cache_smsCode",key="#module+'_'+#platformUserId+'_'+#mobile")
    public String smsCode_generate(Integer module,String platformUserId,String mobile,String smsCode){
        return smsCode;
    }
    /**
     * 删除手机验证码标记
     * @param module 模块
     * @param platformUserId 平台用户Id
     * @param mobile 手机号
     * @return
     */
    @CacheEvict(value="smsManage_cache_smsCode",key="#module+'_'+#platformUserId+'_'+#mobile")
    public void smsCode_delete(Integer module,String platformUserId,String mobile){
    }
    
    /**
     * 更换绑定手机验证码标记
     * @param userId 用户Id
     * @param mobile 手机号
     * @param allow 是否允许
     * @return
     */
    @Cacheable(value="smsManage_cache_replaceCode",key="#userId+'_'+#mobile")
    public boolean replaceCode_generate(Long userId,String mobile,boolean allow){
        return allow;
    }
    /**
     * 删除绑定手机验证码标记
     * @param module 模块
     * @param userId 用户Id
     * @param mobile 手机号
     * @return
     */
    @CacheEvict(value="smsManage_cache_replaceCode",key="#userId+'_'+#mobile")
    public void replaceCode_delete(Long userId,String mobile){
    }
}

打开项目:/src/main/java/cms/web/action/SmsManageAction.java

添加短信宝前端显示代码

?
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
package cms.web.action.sms;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.Validator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.ImmutableMap;
 
import cms.bean.RequestResult;
import cms.bean.ResultCode;
import cms.bean.sms.Alidayu;
import cms.bean.sms.Smsbao;
import cms.bean.sms.SendService;
import cms.bean.sms.SmsInterface;
import cms.service.sms.SmsService;
import cms.utils.JsonUtils;
 
/**
 * 短信接口管理
 *
 */
@Controller
@RequestMapping("/control/smsInterface/manage"
public class SmsManageAction {
 
    @Resource(name = "smsInterfaceValidator"
    private Validator validator; 
    
    @Resource SmsManage smsManage;
    @Resource SmsService smsService;//通过接口引用代理返回的对象
    @Resource MessageSource messageSource;
    
    private Map<Integer,String> smsInterfaceProductParameter = ImmutableMap.of(1"阿里云通信",9"短信宝");//ImmutableMap.of(1, "阿里云通信", 9, "短信宝");
    
    
    /**
     * 短信接口 添加界面显示
     */
    @ResponseBody
    @RequestMapping(params="method=add",method=RequestMethod.GET)
    public String addUI(ModelMap model,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        Map<String,Object> returnValue = new HashMap<String,Object>();
        
        //可添加的接口产品
        LinkedHashMap<Integer,String> smsInterfaceProductMap = new LinkedHashMap<Integer,String>();
        smsInterfaceProductMap.putAll(smsInterfaceProductParameter);
        
        List<SmsInterface> smsInterfaceList =  smsService.findAllSmsInterface();
        if(smsInterfaceList != null && smsInterfaceList.size() >0){
            
            for(SmsInterface _smsInterface : smsInterfaceList){
                if(smsInterfaceProductMap.containsKey(_smsInterface.getInterfaceProduct())){
                    smsInterfaceProductMap.remove(_smsInterface.getInterfaceProduct());
                }
            }
        }
        List<SendService> all_sendServiceList = new ArrayList<SendService>();
 
        for (Map.Entry<Integer, String> entry : smsInterfaceProductMap.entrySet()) {
            List<SendService> _sendServiceList = smsManage.createSendService(entry.getKey());
            all_sendServiceList.addAll(_sendServiceList);
        }
        
        returnValue.put("sendServiceList", all_sendServiceList);
 
        returnValue.put("smsInterfaceProductMap",smsInterfaceProductMap);
        return JsonUtils.toJSONString(new RequestResult(ResultCode.SUCCESS,returnValue));
    }
    
    /**
     * 短信接口 添加
     */
    @ResponseBody
    @RequestMapping(params="method=add",method=RequestMethod.POST)
    public String add(ModelMap model,SmsInterface formbean,BindingResult result,  
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        //错误
        Map<String,Object> error = new HashMap<String,Object>();
        
        this.validator.validate(formbean, result); 
        
        Alidayu alidayu = new Alidayu();//阿里大于
        Smsbao smsbao = new Smsbao();//短信宝
 
        
        String dynamicParameter = "";
        String sendService_json = "";
        
        
        //可添加的接口产品
        List<Integer> smsInterfaceProductList = new ArrayList<Integer>();
        smsInterfaceProductList.addAll(smsInterfaceProductParameter.keySet());
        
        SmsInterface smsInterface = new SmsInterface();
        
        //是否选择  true:启用 false: 禁用
        boolean enable = true;
        
        List<SmsInterface> smsInterfaceList =  smsService.findAllSmsInterface();
        if(smsInterfaceList != null && smsInterfaceList.size() >0){
            for(SmsInterface _smsInterface : smsInterfaceList){
                if(_smsInterface.isEnable()){
                    enable = false;
                }
                if(smsInterfaceProductList.contains(_smsInterface.getInterfaceProduct())){
                    smsInterfaceProductList.remove(_smsInterface.getInterfaceProduct());
                }
            }
        }
        
        List<SendService> all_sendServiceList = new ArrayList<SendService>();
        for(Integer smsInterfaceProduct: smsInterfaceProductList){
            List<SendService> _sendServiceList = smsManage.createSendService(smsInterfaceProduct);
            all_sendServiceList.addAll(_sendServiceList);
        }
 
        if(formbean.getInterfaceProduct() == null ||!smsInterfaceProductParameter.containsKey(formbean.getInterfaceProduct())){
            result.rejectValue("interfaceProduct","errors.required"new String[]{"接口产品参数错误"},"");
        }
        if(!smsInterfaceProductList.contains(formbean.getInterfaceProduct())){
            result.rejectValue("interfaceProduct","errors.required"new String[]{"请选择接口产品"},"");
        }
        
        if(formbean.getInterfaceProduct() != null){
            
            if(formbean.getInterfaceProduct().equals(1)){//1.阿里大于
                String alidayu_accessKeyId = request.getParameter("alidayu_accessKeyId");
                String alidayu_accessKeySecret = request.getParameter("alidayu_accessKeySecret");
                
                if(alidayu_accessKeyId != null && !"".equals(alidayu_accessKeyId.trim())){
                    alidayu.setAccessKeyId(alidayu_accessKeyId);
                }else{
                    error.put("alidayu_accessKeyId""用户密钥Id不能为空");
                }
                
                if(alidayu_accessKeySecret != null && !"".equals(alidayu_accessKeySecret.trim())){
                    alidayu.setAccessKeySecret(alidayu_accessKeySecret);
                }else{
                    error.put("alidayu_accessKeySecret""用户密钥不能为空");
                }
                dynamicParameter = JsonUtils.toJSONString(alidayu);
                
                
                List<SendService> new_sendServiceList = new ArrayList<SendService>();
                for(SendService sendService : all_sendServiceList){
                    if(sendService.getInterfaceProduct().equals(formbean.getInterfaceProduct())){
                        String signName = request.getParameter("alidayu_signName_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId());
                        String templateCode = request.getParameter("alidayu_templateCode_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId());
                        int count = 0;//统计有值字段
                        if(signName != null && !"".equals(signName.trim())){
                            sendService.setAlidayu_signName(signName.trim());
                            count++;
                        }
                        if(templateCode != null && !"".equals(templateCode.trim())){
                            sendService.setAlidayu_templateCode(templateCode.trim());
                            count++;
                        }
                        if(count == 1){
                            if(signName == null || "".equals(signName.trim())){
                                error.put("alidayu_signName_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId(), "短信签名不能为空");
                            }
                            if(templateCode == null || "".equals(templateCode.trim())){
                                error.put("alidayu_templateCode_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId(), "短信模板代码不能为空");
                            }
                        }
                        
                        new_sendServiceList.add(sendService);
                    }
                    
                }
                sendService_json = JsonUtils.toJSONString(new_sendServiceList);
            }else if(formbean.getInterfaceProduct().equals(9)){//短信宝
                String smsbao_accessKeyId = request.getParameter("alidayu_accessKeyId");
                String smsbao_accessKeySecret = request.getParameter("alidayu_accessKeySecret");
 
                if(smsbao_accessKeyId != null && !"".equals(smsbao_accessKeyId.trim())){
                    smsbao.setAccessKeyId(smsbao_accessKeyId);
                }else{
                    error.put("alidayu_accessKeyId""用户密钥Id不能为空");
                }
 
                if(smsbao_accessKeySecret != null && !"".equals(smsbao_accessKeySecret.trim())){
                    smsbao.setAccessKeySecret(smsbao_accessKeySecret);
                }else{
                    error.put("alidayu_accessKeySecret""用户密钥不能为空");
                }
                dynamicParameter = JsonUtils.toJSONString(smsbao);
 
 
                List<SendService> new_sendServiceList = new ArrayList<SendService>();
                for(SendService sendService : all_sendServiceList){
                    if(sendService.getInterfaceProduct().equals(formbean.getInterfaceProduct())){
                        String signName = request.getParameter("alidayu_signName_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId());
                        String templateCode = request.getParameter("alidayu_templateCode_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId());
                        int count = 0;//统计有值字段
                        if(signName != null && !"".equals(signName.trim())){
                            sendService.setSmsbao_signName(signName.trim());
                            count++;
                        }
                        if(templateCode != null && !"".equals(templateCode.trim())){
                            sendService.setSmsbao_templateCode(templateCode.trim());
                            count++;
                        }
                        if(count == 1){
                            if(signName == null || "".equals(signName.trim())){
                                error.put("alidayu_signName_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId(), "短信签名不能为空");
                            }
                            if(templateCode == null || "".equals(templateCode.trim())){
                                error.put("alidayu_templateCode_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId(), "短信模板不能为空");
                            }
                        }
 
                        new_sendServiceList.add(sendService);
                    }
 
                }
                sendService_json = JsonUtils.toJSONString(new_sendServiceList);
            }else{
                result.rejectValue("interfaceProduct","errors.required"new String[]{"请选择接口产品"},"");
            }
            
        }
        
        if (result.hasErrors()) {  
            List<FieldError> fieldErrorList = result.getFieldErrors();
            if(fieldErrorList != null && fieldErrorList.size() >0){
                for(FieldError fieldError : fieldErrorList){
                    error.put(fieldError.getField(), messageSource.getMessage(fieldError, null));
                }
            }
        
        if(error.size() ==0){
            smsInterface.setName(formbean.getName());
            smsInterface.setInterfaceProduct(formbean.getInterfaceProduct());
            smsInterface.setDynamicParameter(dynamicParameter);
            smsInterface.setSendService(sendService_json);
            smsInterface.setEnable(enable);
            smsInterface.setSort(formbean.getSort());
            
 
            smsService.saveSmsInterface(smsInterface);
        }
        
        if(error.size() >0){
            return JsonUtils.toJSONString(new RequestResult(ResultCode.FAILURE,error));
        }else{
            return JsonUtils.toJSONString(new RequestResult(ResultCode.SUCCESS,null));
        }
    }
    
    /**
     * 短信接口 显示修改
     */
    @ResponseBody
    @RequestMapping(params="method=edit",method=RequestMethod.GET)
    public String editUI(ModelMap model,Integer smsInterfaceId,
            HttpServletRequest request, HttpServletResponse response) throws Exception { 
        //错误
        Map<String,Object> error = new HashMap<String,Object>();
        Map<String,Object> returnValue = new HashMap<String,Object>();
        if(smsInterfaceId != null && smsInterfaceId >0){
            //根据ID查询要修改的数据
            SmsInterface smsInterface = smsService.findSmsInterfaceById(smsInterfaceId);
            
            if(smsInterface != null){
                returnValue.put("smsInterface", smsInterface);
                
                if(smsInterface.getDynamicParameter() != null && !"".equals(smsInterface.getDynamicParameter().trim())){
                    if(smsInterface.getInterfaceProduct().equals(1)){//阿里大于
                        Alidayu alidayu= JsonUtils.toObject(smsInterface.getDynamicParameter(), Alidayu.class);
                        returnValue.put("alidayu", alidayu);
                    }
                }
                if(smsInterface.getDynamicParameter() != null && !"".equals(smsInterface.getDynamicParameter().trim())){
                    if(smsInterface.getInterfaceProduct().equals(9)){//短信宝
                        Smsbao smsbao= JsonUtils.toObject(smsInterface.getDynamicParameter(),  Smsbao.class);
                        returnValue.put("smsbao", smsbao);
                    }
                }
 
                List<SendService> sendServiceList = smsManage.createSendService(smsInterface.getInterfaceProduct());
                
                if(smsInterface.getInterfaceProduct().equals(1)){//阿里大于
                    if(smsInterface.getSendService() != null && !"".equals(smsInterface.getSendService().trim())){
                        List<SendService> _sendServiceList = JsonUtils.toGenericObject(smsInterface.getSendService(), new TypeReference< List<SendService> >(){});
                        
                        for(SendService sendService : sendServiceList){
                            for(SendService _sendService : _sendServiceList){
                                if(sendService.getServiceId().equals(_sendService.getServiceId())){
                                    sendService.setAlidayu_signName(_sendService.getAlidayu_signName());
                                    sendService.setAlidayu_templateCode(_sendService.getAlidayu_templateCode());
                                    break;
                                }
                            }
                        }
                        
                    }
                }
                if(smsInterface.getInterfaceProduct().equals(9)){//短信宝
                    if(smsInterface.getSendService() != null && !"".equals(smsInterface.getSendService().trim())){
                        List<SendService> _sendServiceList = JsonUtils.toGenericObject(smsInterface.getSendService(), new TypeReference< List<SendService> >(){});
 
                        for(SendService sendService : sendServiceList){
                            for(SendService _sendService : _sendServiceList){
                                if(sendService.getServiceId().equals(_sendService.getServiceId())){
                                    sendService.setSmsbao_signName(_sendService.getSmsbao_signName());
                                    sendService.setSmsbao_templateCode(_sendService.getSmsbao_templateCode());
                                    break;
                                }
                            }
                        }
 
                    }
                }
                returnValue.put("sendServiceList", sendServiceList);
            }else{
                error.put("smsInterfaceId""短信接口不存在");
            }
        }else{
            error.put("smsInterfaceId""短信接口Id不能为空");
        }
        
        if(error.size() >0){
            return JsonUtils.toJSONString(new RequestResult(ResultCode.FAILURE,error));
        }else{
            return JsonUtils.toJSONString(new RequestResult(ResultCode.SUCCESS,returnValue));
        }
    }
    /**
     * 短信接口 修改
     */
    @ResponseBody
    @RequestMapping(params="method=edit",method=RequestMethod.POST)
    public String edit(ModelMap model,SmsInterface formbean,BindingResult result,Integer smsInterfaceId,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map<String,Object> error = new HashMap<String,Object>();
 
        if(smsInterfaceId != null && smsInterfaceId >0){
            SmsInterface smsInterface = smsService.findSmsInterfaceById(smsInterfaceId);
            if(smsInterface != null){
                this.validator.validate(formbean, result); 
                
                String dynamicParameter = "";
                String sendService_json = "";
                
                Alidayu alidayu = new Alidayu();//阿里大于
                Smsbao smsbao = new Smsbao();//短信宝
                
                List<SendService> sendServiceList = null;
                
                
                if(smsInterface.getInterfaceProduct().equals(1)){//1.阿里大于
                    String alidayu_accessKeyId = request.getParameter("alidayu_accessKeyId");
                    String alidayu_accessKeySecret = request.getParameter("alidayu_accessKeySecret");
                    
                    if(alidayu_accessKeyId != null && !"".equals(alidayu_accessKeyId.trim())){
                        alidayu.setAccessKeyId(alidayu_accessKeyId);
                    }else{
                        error.put("alidayu_accessKeyId""用户密钥Id不能为空");
                    }
                    
                    if(alidayu_accessKeySecret != null && !"".equals(alidayu_accessKeySecret.trim())){
                        alidayu.setAccessKeySecret(alidayu_accessKeySecret);
                    }else{
                        error.put("alidayu_accessKeySecret""用户密钥不能为空");
                    }
                    
                    
                    dynamicParameter = JsonUtils.toJSONString(alidayu);
                    
                    
                    sendServiceList = smsManage.createSendService(smsInterface.getInterfaceProduct());
                    
                    for(SendService sendService : sendServiceList){
 
                        String signName = request.getParameter("alidayu_signName_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId());
                        String templateCode = request.getParameter("alidayu_templateCode_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId());
                        int count = 0;//统计有值字段
                        if(signName != null && !"".equals(signName.trim())){
                            sendService.setAlidayu_signName(signName.trim());
                            count++;
                        }
                        if(templateCode != null && !"".equals(templateCode.trim())){
                            sendService.setAlidayu_templateCode(templateCode.trim());
                            count++;
                        }
                        if(count == 1){
                            if(signName == null || "".equals(signName.trim())){
                                error.put("alidayu_signName_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId(), "短信签名不能为空");
                            }
                            if(templateCode == null || "".equals(templateCode.trim())){
                                error.put("alidayu_templateCode_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId(), "短信模板代码不能为空");
                            }
                        }
                    }
                    sendService_json = JsonUtils.toJSONString(sendServiceList);
                else if(smsInterface.getInterfaceProduct().equals(9)){           //短信宝
                    String smsbao_accessKeyId = request.getParameter("alidayu_accessKeyId");
                    String smsbao_accessKeySecret = request.getParameter("alidayu_accessKeySecret");
 
                    if(smsbao_accessKeyId != null && !"".equals(smsbao_accessKeyId.trim())) {
                        smsbao.setAccessKeyId(smsbao_accessKeyId);
                    }else{
                        error.put("alidayu_accessKeyId""用短信宝密码不能为空");
                    }
 
                    if(smsbao_accessKeySecret != null && !"".equals(smsbao_accessKeySecret.trim())){
                        smsbao.setAccessKeySecret(smsbao_accessKeySecret);
                    }else{
                        error.put("alidayu_accessKeySecret""短信宝帐号不能为空");
                    }
 
 
                    dynamicParameter = JsonUtils.toJSONString(smsbao);
 
 
                    sendServiceList = smsManage.createSendService(smsInterface.getInterfaceProduct());
 
                    for(SendService sendService : sendServiceList){
                        String signName = request.getParameter("alidayu_signName_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId());
                        String templateCode = request.getParameter("alidayu_templateCode_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId());
                        int count = 0;//统计有值字段
                        if(signName != null && !"".equals(signName.trim())){
                            sendService.setSmsbao_signName(signName.trim());
                            count++;
                        }
                        if(templateCode != null && !"".equals(templateCode.trim())){
                            sendService.setSmsbao_templateCode(templateCode.trim());
                            count++;
                        }
                        if(count == 1){
                            if(signName == null || "".equals(signName.trim())){
                                error.put("alidayu_signName_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId(), "短信签名不能为空");
                            }
                            if(templateCode == null || "".equals(templateCode.trim())){
                                error.put("alidayu_templateCode_"+sendService.getInterfaceProduct()+"_"+sendService.getServiceId(), "短信模板不能为空");
                            }
                        }
                    }
                    sendService_json = JsonUtils.toJSONString(sendServiceList);
                }
                
                smsInterface.setId(smsInterfaceId);
                smsInterface.setName(formbean.getName());
                smsInterface.setDynamicParameter(dynamicParameter);
                smsInterface.setSendService(sendService_json);
                smsInterface.setSort(formbean.getSort());  
                smsInterface.setVersion(Integer.parseInt(RandomStringUtils.randomNumeric(5)));//5位随机数
                
                if (result.hasErrors()) {  
                    List<FieldError> fieldErrorList = result.getFieldErrors();
                    if(fieldErrorList != null && fieldErrorList.size() >0){
                        for(FieldError fieldError : fieldErrorList){
                            error.put(fieldError.getField(), messageSource.getMessage(fieldError, null));
                        }
                    }
                }
                if(error.size() ==0){
                    
                    smsService.updateSmsInterface(smsInterface);
                }
            }else{
                error.put("smsInterfaceId""短信接口不存在");
            }
        }else{
            error.put("smsInterfaceId""短信接口Id不能为空");
        }
    
        
        if(error.size() >0){
            return JsonUtils.toJSONString(new RequestResult(ResultCode.FAILURE,error));
        }else{
            return JsonUtils.toJSONString(new RequestResult(ResultCode.SUCCESS,null));
        }
    }
    
    /**
     * 短信接口 删除
     */
    @ResponseBody
    @RequestMapping(params="method=delete",method=RequestMethod.POST)
    public String delete(ModelMap model,Integer smsInterfaceId,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        //错误
        Map<String,Object> error = new HashMap<String,Object>();
        
        if(smsInterfaceId != null && smsInterfaceId >0){
            smsService.deleteSmsInterface(smsInterfaceId);
            return JsonUtils.toJSONString(new RequestResult(ResultCode.SUCCESS,null));
        }else{
            error.put("smsInterfaceId""短信接口Id不能为空");
        }
        return JsonUtils.toJSONString(new RequestResult(ResultCode.FAILURE,error));
    }
    
    
    /**
     * 短信接口 启用当前接口
     * @param model
     * @param dirName 模板目录名称
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(params="method=enableInterface",method=RequestMethod.POST)
    public String enableInterface(ModelMap model,Integer smsInterfaceId,
            HttpServletRequest request, HttpServletResponse response)throws Exception {
        //错误
        Map<String,Object> error = new HashMap<String,Object>();
        if(smsInterfaceId != null && smsInterfaceId >0){
            smsService.updateEnableInterface(smsInterfaceId,Integer.parseInt(RandomStringUtils.randomNumeric(5)));
            return JsonUtils.toJSONString(new RequestResult(ResultCode.SUCCESS,null));
        }else{
            error.put("smsInterfaceId""短信接口Id不能为空");
        }
        return JsonUtils.toJSONString(new RequestResult(ResultCode.FAILURE,error));
    }
 
}

打开项目:/src/main/webapp/WEB-INF/manage/sms/addSmsInterface.vue 修改前端显示

?
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!-- 添加短信接口 -->
<template id="addSmsInterface-template">
    <div>
        <div class="main" >
            <div class="navbar">
                <el-button type="primary" plain size="small" @click="$router.push({path: '/admin/control/smsInterface/list',query:{ page:($route.query.page != undefined ? $route.query.page:'')}})">返回</el-button>
            </div>
            <div class="data-form label-width-blank" >
                <el-form label-width="auto"  @submit.native.prevent>
                    <el-form-item label="名称" :required="true" :error="error.name">
                        <el-row><el-col :span="18"><el-input v-model.trim="name" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                    </el-form-item>
                    <el-form-item label="接口产品" :required="true" :error="error.interfaceProduct">
                        <el-select v-model="interfaceProduct" placeholder="请选择">
                            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                        <div class="form-help" >每种接口只能添加一次</div>
                    </el-form-item>
                    <el-form-item label="用户密钥Id(accessKeyId)" v-if="interfaceProduct ==1" :required="true" :error="error.alidayu_accessKeyId">
                        <el-input type="textarea" v-model="alidayu_accessKeyId" :autosize="{minRows: 1}" placeholder="请输入密钥" ></el-input>
                        <div class="form-help" >
                            <a href="backstage/images/help/alidayu_accessKey.jpg" target="_blank">获取方法演示</a>
                        </div>
                    </el-form-item>
                    <el-form-item label="短信宝帐号" v-if="interfaceProduct ==9" :required="true" :error="error.alidayu_accessKeyId">
                        <el-input type="textarea" v-model="alidayu_accessKeyId" :autosize="{minRows: 1}" placeholder="请输入短信宝帐号" ></el-input>
                        <div class="form-help" >
                            <a href="https://www.smsbao.com/reg?" target="_blank">没有短信宝帐号?点击立刻注册</a>
                        </div>   
                    </el-form-item>
                    <el-form-item label="用户密钥(accessKeySecret)" v-if="interfaceProduct ==1" :required="true" :error="error.alidayu_accessKeySecret">
                        <el-input type="textarea" v-model="alidayu_accessKeySecret" :autosize="{minRows: 1}" placeholder="请输入密钥" ></el-input>
                        <div class="form-help" >
                            <a href="backstage/images/help/alidayu_accessKey.jpg" target="_blank">获取方法演示</a>
                        </div>
                    </el-form-item>
                    <el-form-item label="短信宝密码" v-if="interfaceProduct ==9 " :required="true" :error="error.alidayu_accessKeySecret">
                        <el-input type="textarea" v-model="alidayu_accessKeySecret" :autosize="{minRows: 1}" placeholder="请输入短信宝密码" ></el-input> 
                    </el-form-item>
                    <el-form-item label="排序" :required="true" :error="error.sort">
                        <el-row><el-col :span="6"><el-input v-model.trim="sort" maxlength="8" clearable="true" show-word-limit></el-input></el-col></el-row>
                    </el-form-item>
                    
                    <div class="data-view" v-for="(sendService,index) in sendServiceList">
                        <el-form-item v-if="sendService.interfaceProduct == 1 && interfaceProduct ==1 || sendService.interfaceProduct == 9 && interfaceProduct ==9">
                           {{sendService.serviceName}}
                        </el-form-item>
                        <el-form-item label="短信签名" v-if="sendService.interfaceProduct == 1 && interfaceProduct ==1" :required="true" :error="error.alidayu_signName.get(sendService.interfaceProduct+'_'+sendService.serviceId)">
                            <el-row><el-col :span="18"><el-input v-model.trim="alidayu_signName[index]" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                            <div class="form-help" >阿里云管理控制台审核通过的短信签名</div>
                        </el-form-item>
                        <el-form-item label="短信签名" v-if="sendService.interfaceProduct == 9 && interfaceProduct ==9" :required="true" :error="error.alidayu_signName.get(sendService.interfaceProduct+'_'+sendService.serviceId)">
                            <el-row><el-col :span="18"><el-input v-model.trim="alidayu_signName[index]" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                        </el-form-item>
                        <el-form-item label="短信模板代码" v-if="sendService.interfaceProduct == 1 && interfaceProduct ==1" :required="true" :error="error.alidayu_templateCode.get(sendService.interfaceProduct+'_'+sendService.serviceId)">
                            <el-row><el-col :span="18"><el-input v-model.trim="alidayu_templateCode[index]" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                            <div class="form-help" >例如:SMS_1000000</div>
                        </el-form-item>
                        <el-form-item label="请输入短信模板" v-if="sendService.interfaceProduct == 9 && interfaceProduct ==9" :required="true" :error="error.alidayu_templateCode.get(sendService.interfaceProduct+'_'+sendService.serviceId)">
                            <el-row><el-col :span="18"><el-input v-model.trim="alidayu_templateCode[index]" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                            <div class="form-help" >例如:您的验证码为${number},请勿告知他人</div>
                        </el-form-item>
                        
                        <el-form-item label="支持变量" v-if="sendService.interfaceProduct == 1 && interfaceProduct ==1">
                            <el-table ref="table" :data="sendService.alidayu_variable" tooltip-effect="dark" :show-header="false" stripe style="width: 100%" empty-text="没有变量">
                                <el-table-column label="变量" >
                                    <template #default="scope"
                                        {{scope.row.key}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="备注" >
                                    <template #default="scope"
                                        {{scope.row.value}}
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-form-item>
                        <el-form-item label="支持变量" v-if="sendService.interfaceProduct == 9 && interfaceProduct ==9">
                            <el-table ref="table" :data="sendService.smsbao_variable" tooltip-effect="dark" :show-header="false" stripe style="width: 100%" empty-text="没有变量">
                                <el-table-column label="变量" >
                                    <template #default="scope"
                                        {{scope.row.key}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="备注" >
                                    <template #default="scope"
                                        {{scope.row.value}}
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-form-item>
                    </div>
                    
                    
                    
                    <el-form-item>
                        <el-button type="primary" class="submitButton" @click="submitForm" :disabled="submitForm_disabled">提交</el-button>
                    </el-form-item>
                </el-form>
                
                
            </div>
        </div>
    </div>
</template>
 
<script>
//添加短信接口
export default({
    name: 'addSmsInterface',//组件名称,keep-alive缓存需要本参数
    template : '#addSmsInterface-template',
    inject:['reload'], 
    data : function data() {
        return {
            sendServiceList:'',
            
            name :'',
            interfaceProduct :'',
            options: [],
            sort:0,
            alidayu_accessKeyId :'',
            alidayu_accessKeySecret :'',
            alidayu_signName:[],
            alidayu_templateCode:[],
            
            error : {
                name :'',
                interfaceProduct :'',
                sort :'',
                alidayu_accessKeyId :'',
                alidayu_accessKeySecret :'',
                alidayu_signName : new Map(),
                alidayu_templateCode : new Map(),
            },
            submitForm_disabled:false,//提交按钮是否禁用
        };
    },
    created : function created() {
        //当前路由组件名this.$router.currentRoute.value.name
        //设置缓存
        this.$store.commit('setCacheComponents',  [this.$route.name]);
        
        this.queryAddSmsInterface();
    },
    methods : {
        //查询添加短信接口
        queryAddSmsInterface: function(){
            let _self = this;
            
            
            _self.$ajax.get('control/smsInterface/manage', {
                params: {
                    method : 'add',
                }
            })
            .then(function (response) {
                if(response == null){
                    return;
                }
                let result = response.data;
                if(result){
                    let returnValue = JSON.parse(result);
                   
                    if(returnValue.code === 200){//成功
                        let mapData = returnValue.data;
                        for(let key in mapData){
                            if(key == "sendServiceList"){
                                let sendServiceList = mapData[key];
                                if(sendServiceList != null && sendServiceList.length >0){
                                    for(let i=0; i<sendServiceList.length; i++){
                                        let sendService = sendServiceList[i];
                                        _self.alidayu_signName.push("");
                                        _self.alidayu_templateCode.push("");
                                        if (sendService.interfaceProduct == 1){
                                            let variable = sendService.alidayu_variable;
                                            let variableList = [];
                                            for(let key in variable){//Map转为List
                                                let obj =new Object();
                                                obj.key = key;
                                                obj.value = variable[key];
                                                variableList.push(obj);
                                            }
                                            sendService.alidayu_variable = variableList;
                                        }
                                        if (sendService.interfaceProduct == 9){
                                            let variable = sendService.smsbao_variable;
                                            let variableList = [];
                                            for(let key in variable){//Map转为List
                                                let obj =new Object();
                                                obj.key = key;
                                                obj.value = variable[key];
                                                variableList.push(obj);
                                            }
                                            sendService.smsbao_variable = variableList;
                                        }
                                    }
                                }
                                _self.sendServiceList = sendServiceList;
                            }else if(key == "smsInterfaceProductMap"){
                                let smsInterfaceProductMap = mapData[key];
                                let count = 0;
                                for(let interfaceProduct in smsInterfaceProductMap){
                                    let obj =new Object();
                                    obj.value = interfaceProduct;
                                    obj.label = smsInterfaceProductMap[interfaceProduct];
                                    _self.options.push(obj);
                                    count++;
                                }
                                if(count == 0){
                                    _self.error.interfaceProduct = "接口已添加完";
                                }
                            }
                        }
                    }else if(returnValue.code === 500){//错误
                        let errorMap = returnValue.data;
                        for (let key in errorMap) {   
                            _self.error[key] = errorMap[key];
                        }
                    }
                   
                }
                
                
            })
            .catch(function (error) {
                console.log(error);
            });
        },
    
        //提交表单
        submitForm : function() {
            let _self = this;
            _self.submitForm_disabled = true;
            
             //清除错误
            for (let key in _self.error) { 
                if(getType(_self.error[key]) == 'map'){
                    _self.error[key].clear();
                }else{
                    _self.error[key] = "";
                }
            }
             
            let formData = new FormData();
            if(_self.name != null){
                formData.append('name', _self.name);
            }
            if(_self.interfaceProduct != null){
                formData.append('interfaceProduct', _self.interfaceProduct);
            }
            if(_self.sort != null){
                formData.append('sort', _self.sort);
            }
            if(_self.alidayu_accessKeyId != null){
                formData.append('alidayu_accessKeyId', _self.alidayu_accessKeyId);
            }
            if(_self.alidayu_accessKeySecret != null){
                formData.append('alidayu_accessKeySecret', _self.alidayu_accessKeySecret);
            }
            
            if(_self.sendServiceList != null && _self.sendServiceList.length >0){
                for(let i=0; i<_self.sendServiceList.length; i++){
                    let sendService = _self.sendServiceList[i];
                    
                    formData.append('alidayu_signName_'+sendService.interfaceProduct+"_"+sendService.serviceId, _self.alidayu_signName[i]);
                    formData.append('alidayu_templateCode_'+sendService.interfaceProduct+"_"+sendService.serviceId, _self.alidayu_templateCode[i]);
                }
            }
            
            
            
            
            _self.$ajax({
                method: 'post',
                url: 'control/smsInterface/manage?method=add',
                data: formData
            })
            .then(function (response) {
                if(response == null){
                    return;
                }
                
                let result = response.data;
                if(result){
                    let returnValue = JSON.parse(result);
                    if(returnValue.code === 200){//成功
                        _self.$message.success("提交成功");
                       
                        //删除缓存
                        _self.$store.commit('setCacheNumber');
                        _self.$router.push({
                            path : '/admin/control/smsInterface/list',
                        });
                    }else if(returnValue.code === 500){//错误
                       
                        let errorMap = returnValue.data;
                        for (let key in errorMap) {   
                            if(key.split("_").length >3){//alidayu_signName_1_1
                                let parameterName = key.split("_")[0] +"_"+ key.split("_")[1];
                               
                                if(parameterName != "" && getType(_self.error[parameterName]) == 'map'){
                                    _self.error[parameterName].set(key.split("_")[2] +"_"+ key.split("_")[3],errorMap[key]);
                                    continue;
                                }
                            }
                           
                            if(_self.error[key] == undefined){
                                _self.$message({
                                    duration :0,
                                    showClose: true,
                                    message: errorMap[key],
                                    type: 'error'
                                });
                            }else{
                                _self.error[key] = errorMap[key];
                            }
                        }
                       
                    }
                }
                _self.submitForm_disabled = false;
            })
            .catch(function (error) {
                console.log(error);
            });
        }
    }
});

打开项目:/src/main/webapp/WEB-INF/manage/sms/smsInterfaceList.vue 将13行修改为

?
1
2
<span v-if="scope.row.interfaceProduct == 1">阿里云通信</span>
<span v-if="scope.row.interfaceProduct == 9">短信宝</span>

打开项目:/src/main/webapp/WEB-INF/manage/sms/sendSmsLogList.vue 将9行修改为

?
1
2
<span v-if="scope.row.interfaceProduct == 1">阿里云通信</span>
<span v-if="scope.row.interfaceProduct == 9">短信宝</span>

打开项目:/src/main/webapp/WEB-INF/manage/sms/aeditSmsInterface.vue 修改前端显示

?
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
    <!-- 修改短信接口 -->
<template id="editSmsInterface-template">
    <div>
        <div class="main" >
            <div class="navbar">
                <el-button type="primary" plain size="small" @click="$router.push({path: '/admin/control/smsInterface/list',query:{ page:($route.query.page != undefined ? $route.query.page:'')}})">返回</el-button>
            </div>
            <div class="data-form label-width-blank" >
                <el-form label-width="auto"  @submit.native.prevent>
                    <el-form-item label="名称" :required="true" :error="error.name">
                        <el-row><el-col :span="18"><el-input v-model.trim="name" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                    </el-form-item>
                    <el-form-item label="接口产品">
                        <span v-if="interfaceProduct == 1">阿里云通信</span>
                        <span v-if="interfaceProduct == 9">短信宝</span>
                    </el-form-item>
                    <el-form-item label="用户密钥Id(accessKeyId)" v-if="interfaceProduct ==1" :required="true" :error="error.alidayu_accessKeyId">
                        <el-input type="textarea" v-model="alidayu_accessKeyId" :autosize="{minRows: 1}" placeholder="请输入密钥" ></el-input>
                        <div class="form-help" >
                            <a href="backstage/images/help/alidayu_accessKey.jpg" target="_blank">获取方法演示</a>
                        </div>
                    </el-form-item>
                    <el-form-item label="短信宝帐号" v-if="interfaceProduct ==9" :required="true" :error="error.alidayu_accessKeyId">
                        <el-input type="textarea" v-model="alidayu_accessKeyId" :autosize="{minRows: 1}" placeholder="请输入短信宝帐号" ></el-input> 
                    </el-form-item>
                    <el-form-item label="用户密钥(accessKeySecret)" v-if="interfaceProduct ==1" :required="true" :error="error.alidayu_accessKeySecret">
                        <el-input type="textarea" v-model="alidayu_accessKeySecret" :autosize="{minRows: 1}" placeholder="请输入密钥" ></el-input>
                        <div class="form-help" >
                            <a href="backstage/images/help/alidayu_accessKey.jpg" target="_blank">获取方法演示</a>
                        </div>
                    </el-form-item>
                    <el-form-item label="短信宝密码" v-if="interfaceProduct ==9 " :required="true" :error="error.alidayu_accessKeySecret">
                        <el-input type="textarea" v-model="alidayu_accessKeySecret" :autosize="{minRows: 1}" placeholder="请输入短信宝密码" ></el-input> 
                    </el-form-item>
                    
                    <div class="data-view" v-for="(sendService,index) in sendServiceList">
                        <el-form-item v-if="sendService.interfaceProduct == 1 && interfaceProduct ==1">
                           {{sendService.serviceName}}
                        </el-form-item>
                        <el-form-item label="短信签名" v-if="sendService.interfaceProduct == 1 && interfaceProduct ==1" :required="true" :error="error.alidayu_signName.get(sendService.interfaceProduct+'_'+sendService.serviceId)">
                            <el-row><el-col :span="18"><el-input v-model.trim="alidayu_signName[index]" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                            <div class="form-help" >阿里云管理控制台审核通过的短信签名</div>
                        </el-form-item>
                        <el-form-item label="短信签名" v-if="sendService.interfaceProduct == 9 && interfaceProduct ==9" :required="true" :error="error.alidayu_signName.get(sendService.interfaceProduct+'_'+sendService.serviceId)">
                            <el-row><el-col :span="18"><el-input v-model.trim="alidayu_signName[index]" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                        </el-form-item>
                        <el-form-item label="短信模板代码" v-if="sendService.interfaceProduct == 1 && interfaceProduct ==1" :required="true" :error="error.alidayu_templateCode.get(sendService.interfaceProduct+'_'+sendService.serviceId)">
                            <el-row><el-col :span="18"><el-input v-model.trim="alidayu_templateCode[index]" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                            <div class="form-help" >例如:SMS_1000000</div>
                        </el-form-item>
                        <el-form-item label="请输入短信模板" v-if="sendService.interfaceProduct == 9 && interfaceProduct ==9" :required="true" :error="error.alidayu_templateCode.get(sendService.interfaceProduct+'_'+sendService.serviceId)">
                            <el-row><el-col :span="18"><el-input v-model.trim="alidayu_templateCode[index]" maxlength="80" clearable="true" show-word-limit></el-input></el-col></el-row>
                            <div class="form-help" >例如:您的验证码为${number},请勿告知他人</div>
                        </el-form-item>
                        
                        <el-form-item label="支持变量" v-if="sendService.interfaceProduct == 1 && interfaceProduct ==1">
                            <el-table ref="table" :data="sendService.alidayu_variable" tooltip-effect="dark" :show-header="false" stripe style="width: 100%" empty-text="没有变量">
                                <el-table-column label="变量" >
                                    <template #default="scope"> 
                                        {{scope.row.key}}
                                    </template>
                                </el-table-column>
                                <el-table-column label="备注" >
                                    <template #default="scope"> 
                                        {{scope.row.value}}
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-form-item>
                    </div>
                    
                    
                    
                    <el-form-item>
                        <el-button type="primary" class="submitButton" @click="submitForm" :disabled="submitForm_disabled">提交</el-button>
                    </el-form-item>
                </el-form>
                
                
            </div>
        </div>
    </div>
</template>
 
<script>
//修改短信接口
export default({
    name: 'editSmsInterface',//组件名称,keep-alive缓存需要本参数
    template : '#editSmsInterface-template',
    inject:['reload'], 
    data : function data() {
        return {
            smsInterfaceId:'',
            sendServiceList:'',
            
            name :'',
            interfaceProduct :'',
            options: [],
            sort:0,
            alidayu_accessKeyId :'',
            alidayu_accessKeySecret :'',
            alidayu_signName:[],
            alidayu_templateCode:[],
            
            error : {
                name :'',
                sort :'',
                alidayu_accessKeyId :'',
                alidayu_accessKeySecret :'',
                alidayu_signName : new Map(),
                alidayu_templateCode : new Map(),
            },
            submitForm_disabled:false,//提交按钮是否禁用
        };
    },
    created : function created() {
        //当前路由组件名this.$router.currentRoute.value.name
        //设置缓存
        this.$store.commit('setCacheComponents',  [this.$route.name]);
        
        if(this.$route.query.smsInterfaceId != undefined && this.$route.query.smsInterfaceId != ''){
            this.smsInterfaceId = this.$route.query.smsInterfaceId;
        }
        
        this.queryEditSmsInterface();
    },
    methods : {
        //查询修改短信接口
        queryEditSmsInterface: function(){
            let _self = this;
            
            
            _self.$ajax.get('control/smsInterface/manage', {
                params: {
                    method : 'edit',
                    smsInterfaceId : _self.smsInterfaceId,
                }
            })
            .then(function (response) {
                if(response == null){
                    return;
                }
                let result = response.data;
                if(result){
                    let returnValue = JSON.parse(result);
                   
                    if(returnValue.code === 200){//成功
                        let mapData = returnValue.data;
                        for(let key in mapData){
                            if(key == "sendServiceList"){
                                let sendServiceList = mapData[key];
                                if(sendServiceList != null && sendServiceList.length >0){
                                    for(let i=0; i<sendServiceList.length; i++){
                                        let sendService = sendServiceList[i];
                                            // _self.alidayu_signName.push(sendService.alidayu_signName);
                                            // _self.alidayu_templateCode.push(sendService.alidayu_templateCode);
                                            // let variable = sendService.alidayu_variable;
                                            // let variableList = [];
                                            // for(let key in variable){//Map转为List
                                            //     let obj =new Object();
                                         //        obj.key = key;
                                         //        obj.value = variable[key];
                                         //        variableList.push(obj);
                                            // }
                                            // sendService.alidayu_variable = variableList;                                     
                                        if (sendService.interfaceProduct == 1){
                                            _self.alidayu_signName.push(sendService.alidayu_signName);
                                            _self.alidayu_templateCode.push(sendService.alidayu_templateCode);
                                            let variable = sendService.alidayu_variable;
                                            let variableList = [];
                                            for(let key in variable){//Map转为List
                                                let obj =new Object();
                                                obj.key = key;
                                                obj.value = variable[key];
                                                variableList.push(obj);
                                            }
                                            sendService.alidayu_variable = variableList;
                                        }
                                        if (sendService.interfaceProduct == 9){
                                            _self.alidayu_signName.push(sendService.smsbao_signName);
                                            _self.alidayu_templateCode.push(sendService.smsbao_templateCode);
                                            let variable = sendService.smsbao_variable;
                                            let variableList = [];
                                            for(let key in variable){//Map转为List
                                                let obj =new Object();
                                                obj.key = key;
                                                obj.value = variable[key];
                                                variableList.push(obj);
                                            }
                                            sendService.smsbao_variable = variableList;
                                        }
                                    }
                                }
                                _self.sendServiceList = sendServiceList;
                            }else if(key == "smsInterface"){
                                let smsInterface = mapData[key];
                               
                                _self.name = smsInterface.name;
                                _self.interfaceProduct = smsInterface.interfaceProduct;
                                _self.sort = smsInterface.sort;
                            }else if(key == "alidayu"){
                                let alidayu = mapData[key];
                                _self.alidayu_accessKeyId = alidayu.accessKeyId;
                                _self.alidayu_accessKeySecret = alidayu.accessKeySecret;
                            }else if(key == "smsbao"){
                                let smsbao = mapData[key];
                                _self.alidayu_accessKeyId = smsbao.accessKeyId;
                                _self.alidayu_accessKeySecret = smsbao.accessKeySecret;
                            }
                        }
                    }else if(returnValue.code === 500){//错误
                        let errorMap = returnValue.data;
                        for (let key in errorMap) {   
                            _self.error[key] = errorMap[key];
                        }
                    }
                   
                }
                
                
            })
            .catch(function (error) {
                console.log(error);
            });
        },
    
        //提交表单
        submitForm : function() {
            let _self = this;
            _self.submitForm_disabled = true;
            
             //清除错误
            for (let key in _self.error) { 
                if(getType(_self.error[key]) == 'map'){
                    _self.error[key].clear();
                }else{
                    _self.error[key] = "";
                }
            }
             
            let formData = new FormData();
            formData.append('smsInterfaceId', _self.smsInterfaceId);
            if(_self.name != null){
                formData.append('name', _self.name);
            }
            if(_self.sort != null){
                formData.append('sort', _self.sort);
            }
            if(_self.alidayu_accessKeyId != null){
                formData.append('alidayu_accessKeyId', _self.alidayu_accessKeyId);
            }
            if(_self.alidayu_accessKeySecret != null){
                formData.append('alidayu_accessKeySecret', _self.alidayu_accessKeySecret);
            }
            
            if(_self.sendServiceList != null && _self.sendServiceList.length >0){
                for(let i=0; i<_self.sendServiceList.length; i++){
                    let sendService = _self.sendServiceList[i];
                    
                    formData.append('alidayu_signName_'+sendService.interfaceProduct+"_"+sendService.serviceId, _self.alidayu_signName[i]);
                    formData.append('alidayu_templateCode_'+sendService.interfaceProduct+"_"+sendService.serviceId, _self.alidayu_templateCode[i]);
                }
            }
            
            
            
            
            _self.$ajax({
                method: 'post',
                url: 'control/smsInterface/manage?method=edit',
                data: formData
            })
            .then(function (response) {
                if(response == null){
                    return;
                }
                
                let result = response.data;
                if(result){
                    let returnValue = JSON.parse(result);
                    if(returnValue.code === 200){//成功
                        _self.$message.success("提交成功");
                       
                        //删除缓存
                        _self.$store.commit('setCacheNumber');
                        _self.$router.push({
                            path : '/admin/control/smsInterface/list',
                            query:{ page:(_self.$route.query.page != undefined ? _self.$route.query.page:'')}
                        });
                    }else if(returnValue.code === 500){//错误
                       
                        let errorMap = returnValue.data;
                        for (let key in errorMap) {   
                            if(key.split("_").length >3){//alidayu_signName_1_1
                                let parameterName = key.split("_")[0] +"_"+ key.split("_")[1];
                               
                                if(parameterName != "" && getType(_self.error[parameterName]) == 'map'){
                                    _self.error[parameterName].set(key.split("_")[2] +"_"+ key.split("_")[3],errorMap[key]);
                                    continue;
                                }
                            }
                           
                            if(_self.error[key] == undefined){
                                _self.$message({
                                    duration :0,
                                    showClose: true,
                                    message: errorMap[key],
                                    type: 'error'
                                });
                            }else{
                                _self.error[key] = errorMap[key];
                            }
                        }
                       
                    }
                }
                _self.submitForm_disabled = false;
            })
            .catch(function (error) {
                console.log(error);
            });
        }
    }
});
 
</script>

经过上面的替换并编译,短信宝的短信平台已经添加成功了,可以正常使用了。

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。

另外:我们已经开发好完整的巡云轻论5.3系统短信宝插件,点击此链接 下载及查看安装流程。

开源插件

最新更新

电商类

CMS类

微信类

文章标签