Helius
2020-05-18 a5b282e1c85ea498377215e43ff475054bf2e4e2
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
package com.xcong.excoin.utils;
 
 
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 短信发送工具
 *
 * @author wzy
 * @date 2020-05-18
 **/
public class SmsUtils {
 
 
    private static HttpClient httpclient;
 
    @SuppressWarnings("deprecation")
    public static Map<String, Object> hxSmsSend(String mobile, String sendContent) {
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            httpclient = new SSLClient();
            //TFT001
            String url = "https://dx.ipyy.net/sms.aspx";
            //excoin DX001        //ctcoin:OT00028            //改为实际账号名
            String accountName = "DX001";
            //excoin 1qaz2wsx    //ctcoin:    atvckt                //改为实际发送密码
            String password = "1qaz2wsx";
            String text = sendContent;
            HttpPost post = new HttpPost(url);
            post.setHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("action", "send"));
            nvps.add(new BasicNameValuePair("userid", ""));
            nvps.add(new BasicNameValuePair("account", accountName));
            nvps.add(new BasicNameValuePair("password", password));
            //多个手机号用逗号分隔
            nvps.add(new BasicNameValuePair("mobile", mobile));
            nvps.add(new BasicNameValuePair("content", text));
            nvps.add(new BasicNameValuePair("sendTime", ""));
            nvps.add(new BasicNameValuePair("extno", ""));
 
            post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
 
            HttpResponse response = httpclient.execute(post);
            HttpEntity entity = response.getEntity();
            // 将字符转化为XML
            String returnString = EntityUtils.toString(entity, "UTF-8");
            Document doc = DocumentHelper.parseText(returnString);
            // 获取根节点
            Element rootElt = doc.getRootElement();
            // 获取根节点下的子节点的值
            String returnstatus = rootElt.elementText("returnstatus").trim();
            String message = rootElt.elementText("message").trim();
            String remainpoint = rootElt.elementText("remainpoint").trim();
            String taskID = rootElt.elementText("taskID").trim();
            String successCounts = rootElt.elementText("successCounts").trim();
 
            map.put("returnstatus", returnstatus);
            map.put("message", message);
            map.put("remainpoint", remainpoint);
            map.put("taskID", taskID);
            map.put("successCounts", successCounts);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }
 
    /**
     * 短信验证码
     *
     * @param phone 手机号
     * @param code  验证码
     * @return
     */
    public static Map<String, Object> sendVerifyCode(String phone, int code) {
        String smsContent = "【Excoin】您的验证码为:"+code+",该验证码有效期为2分钟,请勿泄露于他人。";
        return hxSmsSend(phone, smsContent);
    }
}