123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package com.huimv.env.input.utils;
- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- public class DSendSMS {
- static String httpUrl = "http://imlaixin.cn/Api/send/data/json";
-
- //短信内容不能出现空格,换行,百分号等特殊字符.相同两条短信之间内容不能相同
- public static void main(String[] args) {
- /**
- *发送给报警器
- *//*
- String content = "003C0043004C0045004100520030003000310039003E";
- String mobile = "18767100452";//多个用英文逗号隔开 如18767100452,1388888888
- content = UnicodeTool.decodeUnicode(UnicodeTool.addUnicodeU(content.toString()));*/
-
- /**
- * 发送给用户
- */
- // String mobile = "13750862931";
- // String mobile = "13140429955";
- String mobile = "13376830277";
- // String content = "%3CCLOSE00000000%3e+52通知【慧牧科技】";
- String content = "0,2306101111520790<CLOSE99999999>";
- // String content = "%3CCLOSE00000158%3e";
- // String content = "0,2306061142510170%3C13140429955;13140429955;13140429955;03保育11断电报警%3e";
- String httpArg = "accesskey=5493&secretkey=7e6f0b6e9d12d2c750cbf1932a4b9cc53e36509b&mobile=" + mobile + "&content=" + content;
- String jsonResult = request(httpUrl, httpArg);
- System.out.println(jsonResult);//返回码
- }
-
- public static void sendSMS(String[] mobiles, String content) {
- for (String mobile : mobiles) {
- String httpArg = "accesskey=5493&secretkey=7e6f0b6e9d12d2c750cbf1932a4b9cc53e36509b&mobile=" + mobile + "&content=" + content + "通知【慧牧科技】";
- System.out.println(httpArg);
- String jsonResult = request(httpUrl, httpArg);
- System.out.println(jsonResult);//返回码
- }
- }
-
- 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 = null;
- while ((strRead = reader.readLine()) != null) {
- sbf.append(strRead);
- sbf.append("\r\n");
- }
- reader.close();
- result = sbf.toString();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
- }
|