liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.tools.web;
 
import java.io.IOException;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.jeeplus.common.sms.SMSUtils;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.sys.entity.SystemConfig;
import com.jeeplus.modules.sys.service.SystemConfigService;
 
/**
 * 发送短信
 * @author lgf
 * @version 2016-01-07
 */
@Controller
@RequestMapping(value = "${adminPath}/tools/sms")
public class SMSController extends BaseController {
 
    @Autowired
    private SystemConfigService systemConfigService;
    
    /**
     * 打开短信页面
     */
    @RequestMapping(value = {"index", ""})
    public String index( HttpServletRequest request, HttpServletResponse response, Model model) {
        return "modules/tools/sendSMS";
    }
 
    /**
     * 发送短信
     */
    @RequestMapping("send")
    public String send(String tels,  HttpServletResponse response, String content, Model model) throws Exception {
        SystemConfig config = systemConfigService.get("1");
        String result = "";
        try{
                String resultCode = SMSUtils.send(config.getSmsName(),config.getSmsPassword(), tels, content);
                if (!resultCode.equals("100")) {
                    
                    result = "短信发送失败,错误代码:"+resultCode+",请 联系管理员。";
                
                }else{
                    result = "短信发送成功";
                }
            } catch (IOException e) {
                result = "因未知原因导致短信发送失败,请联系管理员。";
            }
            
            model.addAttribute("result", result);
            return "modules/tools/sendSMSResult";
    }
        
}