1821349743@qq.com
2023-02-20 afca4e11f0f2be79080a21d3cf95479317eb555d
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
package com.product.text.message.util;
 
import com.product.core.config.Global;
import com.product.core.exception.BaseException;
import com.product.text.message.util.ide.ISMSConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.stereotype.Component;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
 
/**
 * @author GHQ
 * @version 创建时间:2017年3月27日 下午2:36:08
 * 
 */
@Component
public class SendSMSUtil implements ISMSConfiguration {
    private static String Url = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
    private static String CorpID="CDJS003057";//账户名
    private static String Pwd="zm0513@";//密码
    private static String Signature="【企业管理平台】";//签名  德润美家  企业管理平台 成都龙欣科技
 
    @Deprecated
    public static String SendSMS(String phoneNum, boolean is_orignal) {
        HttpClient client = new HttpClient();
        PostMethod method = new PostMethod(Url);
 
        client.getParams().setContentCharset("GBK");
        method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=GBK");
 
        int mobile_code = (int)((Math.random()*9+1)*100000);
 
        String content = new String("您的验证码是:" + mobile_code + "。请不要把验证码泄露给其他人。");
 
        NameValuePair[] data = {//提交短信
                new NameValuePair("account", "C12266072"), //查看用户名请登录用户中心->验证码、通知短信->帐户及签名设置->APIID
                new NameValuePair("password", "6ddd7e53bc51fe1f666386564e0ee54f"),  //查看密码请登录用户中心->验证码、通知短信->帐户及签名设置->APIKEY
                //new NameValuePair("password", util.StringUtil.MD5Encode("密码")),
                new NameValuePair("mobile", phoneNum), 
                new NameValuePair("content", content),
        };
        method.setRequestBody(data);
        try {
            client.executeMethod(method);
            String SubmitResult =method.getResponseBodyAsString();
            //System.out.println(SubmitResult);
            Document doc = DocumentHelper.parseText(SubmitResult);
            Element root = doc.getRootElement();
 
            String code = root.elementText("code");
//            String msg = root.elementText("msg");
//            String smsid = root.elementText("smsid");
 
            System.out.println(code);
//            System.out.println(msg);
//            System.out.println(smsid);
             if("2".equals(code)){
                return mobile_code+""; 
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return ""; 
    }
 
    @Override
    public String SendSMS(String phoneNum) {
        int mobile_code = (int)((Math.random()*9+1)*100000);
        String content = new String("您的验证码是:" + mobile_code + ",请不要把验证码泄露给其他人。");
        int result;
        try {
            result = sendSMS(phoneNum, content, "");
            if (result > 0) {
                return mobile_code + "";
            }
        } catch (Exception e) {
            return "-2";
        }
        return result + "";
    }
    
    /**林凱-發送短信接口*/
    public int sendSMS(String Mobile,String Content,String send_time)throws BaseException {
        URL url = null;
        //通过配置文件获取公司签名
        Signature = Global.getSystemConfig("org.message.signatures","");
        Content+=Signature;
        String send_content= null;//发送内容
        try {
            send_content = URLEncoder.encode(Content.replaceAll("<br/>", " "), "GBK");
            url = new URL("https://sdk2.028lk.com/sdk2/BatchSend2.aspx?CorpID="+CorpID+"&Pwd="+Pwd+"&Mobile="+Mobile+"&Content="+send_content+"&Cell=&SendTime="+send_time);
        } catch (UnsupportedEncodingException | MalformedURLException e) {
            throw new BaseException("public int sendSMS(String Mobile,String Content,String send_time)throws BaseException",e.getMessage());
        }
 
//        url = new URL("https://sdk2.028lk.com/sdk2/SelSum.aspx?CorpID="+CorpID+"&Pwd="+Pwd); // 查询短信剩余条数
        BufferedReader in = null;
        int inputLine = 0;
        try {
            System.out.println("开始发送短信手机号码为 :"+Mobile);
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            inputLine = new Integer(in.readLine()).intValue();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("网络异常,发送短信失败!");
            throw new BaseException("网络异常,发送短信失败!-2",e.getMessage());
        }
        System.out.println("结束发送短信返回值:  "+inputLine);
        return inputLine;
    }
//
//    public static void main(String[] args) {
//        SendSMSUtil smsUtil = new SendSMSUtil();
//        System.out.println(smsUtil.SendSMS("15928438186"));
//
//    }
}