DSendSMS.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.huimv.env.input.utils;
  2. import java.io.BufferedReader;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import java.net.HttpURLConnection;
  6. import java.net.URL;
  7. public class DSendSMS {
  8. static String httpUrl = "http://imlaixin.cn/Api/send/data/json";
  9. //短信内容不能出现空格,换行,百分号等特殊字符.相同两条短信之间内容不能相同
  10. public static void main(String[] args) {
  11. /**
  12. *发送给报警器
  13. *//*
  14. String content = "003C0043004C0045004100520030003000310039003E";
  15. String mobile = "18767100452";//多个用英文逗号隔开 如18767100452,1388888888
  16. content = UnicodeTool.decodeUnicode(UnicodeTool.addUnicodeU(content.toString()));*/
  17. /**
  18. * 发送给用户
  19. */
  20. // String mobile = "13750862931";
  21. // String mobile = "13140429955";
  22. String mobile = "13376830277";
  23. // String content = "%3CCLOSE00000000%3e+52通知【慧牧科技】";
  24. String content = "0,2306101111520790<CLOSE99999999>";
  25. // String content = "%3CCLOSE00000158%3e";
  26. // String content = "0,2306061142510170%3C13140429955;13140429955;13140429955;03保育11断电报警%3e";
  27. String httpArg = "accesskey=5493&secretkey=7e6f0b6e9d12d2c750cbf1932a4b9cc53e36509b&mobile=" + mobile + "&content=" + content;
  28. String jsonResult = request(httpUrl, httpArg);
  29. System.out.println(jsonResult);//返回码
  30. }
  31. public static void sendSMS(String[] mobiles, String content) {
  32. for (String mobile : mobiles) {
  33. String httpArg = "accesskey=5493&secretkey=7e6f0b6e9d12d2c750cbf1932a4b9cc53e36509b&mobile=" + mobile + "&content=" + content + "通知【慧牧科技】";
  34. System.out.println(httpArg);
  35. String jsonResult = request(httpUrl, httpArg);
  36. System.out.println(jsonResult);//返回码
  37. }
  38. }
  39. public static String request(String httpUrl, String httpArg) {
  40. BufferedReader reader = null;
  41. String result = null;
  42. StringBuffer sbf = new StringBuffer();
  43. httpUrl = httpUrl + "?" + httpArg;
  44. try {
  45. URL url = new URL(httpUrl);
  46. HttpURLConnection connection = (HttpURLConnection) url
  47. .openConnection();
  48. connection.setRequestMethod("GET");
  49. connection.connect();
  50. InputStream is = connection.getInputStream();
  51. reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
  52. String strRead = null;
  53. while ((strRead = reader.readLine()) != null) {
  54. sbf.append(strRead);
  55. sbf.append("\r\n");
  56. }
  57. reader.close();
  58. result = sbf.toString();
  59. } catch (Exception e) {
  60. e.printStackTrace();
  61. }
  62. return result;
  63. }
  64. }