| 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); | 
|     } | 
| } |