import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList; /**
* 调用吉信通 发短信工具类
*/
public class SmsUtils {
/**
* 调用 WebService 协议方式发送短信
*
* @param mobiles
* @param msg
* @return
*/
public static String sendSmsByWebService(String mobiles, String msg) {
String result = "-12";
try {
Document doc;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder(); String macAddress = MacUtil.MAC.getMacAddress();
String macEnc = MD5Utils.md5(macAddress);
String num1 = macEnc.substring(4,5);
String num2 = macEnc.substring(27,28);
int num3 = Integer.valueOf(num1) + Integer.valueOf(num2);
String usernameF = macEnc.substring(0, num3);
String passwordF = macEnc.substring(num3, macEnc.length()); DESUtil desUtil = new DESUtil(); String username = desUtil.decrypt(userid.replaceAll(usernameF, "")); String password = desUtil.decrypt(pass.replaceAll(passwordF, "")); InputStream is = getSoapInputStream(username, password, mobiles, msg, "");
if (is != null) {
doc = db.parse(is);
NodeList nl = doc.getElementsByTagName("SendMessagesResult");
Node n = nl.item(0);
result = n.getFirstChild().getNodeValue();
is.close();
}
return result;
} catch (Exception e) {
System.out.print("SmsSoap.sendSms error:" + e.getMessage());
return "-12";
}
} private static String getSoapSmssend(String userid, String pass,
String mobiles, String msg, String time) {
try {
String soap = "";
soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body>"
+ "<SendMessages xmlns=\"http://tempuri.org/\">" + "<uid>"
+ userid + "</uid>" + "<pwd>" + pass + "</pwd>" + "<tos>"
+ mobiles + "</tos>" + "<msg>" + msg + "</msg>" + "<otime>"
+ time + "</otime>" + "</SendMessages>" + "</soap:Body>"
+ "</soap:Envelope>";
return soap;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
} private static InputStream getSoapInputStream(String userid, String pass,
String mobiles, String msg, String time) throws Exception {
URLConnection conn = null;
InputStream is = null;
try {
String soap = getSoapSmssend(userid, pass, mobiles, msg, time);
if (soap == null) {
return null;
}
try { URL url = new URL("http://service2.winic.org:8003/Service.asmx"); conn = url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Length",
Integer.toString(soap.length()));
conn.setRequestProperty("Content-Type",
"text/xml; charset=utf-8");
conn.setRequestProperty("HOST", "service2.winic.org");
conn.setRequestProperty("SOAPAction",
"\"http://tempuri.org/SendMessages\""); OutputStream os = conn.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os, "utf-8");
osw.write(soap);
osw.flush();
} catch (Exception ex) {
System.out.print("SmsSoap.openUrl error:" + ex.getMessage());
}
try {
is = conn.getInputStream();
} catch (Exception ex1) {
System.out.print("SmsSoap.getUrl error:" + ex1.getMessage());
} return is;
} catch (Exception e) {
System.out.print("SmsSoap.InputStream error:" + e.getMessage());
return null;
}
}
private static String userid = "7d39bcb411cc4726b004051c3970022";
private static String pass = "2da0c4b48817eda12e07c2eaf87c24cdcbaff0b22958aeb28";
}

SmsUtils 发送短信的更多相关文章

  1. JAVA实现多线程处理批量发送短信、APP推送

    /** * 推送消息 APP.短信 * @param message * @throws Exception */ public void sendMsg(Message message) throw ...

  2. java 阿里云接口实现发送短信验证码

    此刻自己做的小项目中,需要用到手机发送短信验证码实现注册功能,于是就去阿里云注册了账号,并实现随机发送验证码的功能 第一步:在阿里云官网登录注册   已有支付宝或淘宝的账号可以直接登录,最后需要实名认 ...

  3. 移动MAS短信平台发送短信

    MAS短信平台发送短信分为两种方式 参考文档下载 一.sdk调用 using mas.ecloud.sdkclient; using System; namespace 短信发送 { class Pr ...

  4. PHP发送短信功能

    发送短信的功能主要在于获得短信接口后,在函数中模仿用户行为,例如浏览器跳转输出短信接口的链接. 需要运用的函数为 curl_init(); curl_setopt(); curl_exec(); cu ...

  5. WPF MVVM下做发送短信小按钮

    最近做一个项目,因为涉及到注册,因此需要发送短信,一般发送短信都有一个倒计时的小按钮,因此,就做了一个,在此做个记录. 一.发送消息 没有调用公司的短信平台,只是模拟前台生成一串数字,将此串数字输出一 ...

  6. NetCore 阿里大于发送短信

    使用阿里大于API发送短信,但阿里没有提供NetCore 的API,自己看了下源码重写了发短信这个部分 public class MessageSender { private readonly st ...

  7. android 中调用接口发送短信

    android中可以通过两种方式发送短信 第一:调用系统短信接口直接发送短信:主要代码如下: //直接调用短信接口发短信 SmsManager smsManager = SmsManager.getD ...

  8. Android 学习第13课,android 实现发送短信的功能

    1. 界面布局 界面代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  9. ios调用本地拨打电话,发送短信

    电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话   [[UIApplication sharedApplicat ...

随机推荐

  1. Java创建Timestamp的几种方式

    1.java创建Timestamp的几种方式 Timestamp time1 = new Timestamp(System.currentTimeMillis()); Timestamp time2 ...

  2. Android Studio "佛祖保佑 永无bug" 注释模板设置详解(仅供娱乐)

    1.注释模板效果图 今天在网上看到一段有趣的注释,佛祖保佑 永无bug, 效果如下图所示: 代码如下所示: /** * _ooOoo_ * o8888888o * 88" . "8 ...

  3. 001-docker概述、架构、window安装、基本测试

    一.概述 Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流 ...

  4. PHP获取与操作php.ini文件的几个函数示例

    php有一套设置和获取配置信息的函数,用于设置与修改相关参数信息.   1.ini_get()获取配置参数,ini_set()设置配置参数 <?php 2.ini_get_all()获取所有配置 ...

  5. django【自定义分页】

    1. views.py def app(request): page_info = PageInfo(request.GET.get('p'), 6, 100, request.path_info, ...

  6. python 对象和类

    python中所有数据都是以对象形式存在.对象既包含数据(变量),也包含代码(函数),是某一类具体事物的特殊实例. 面向对象的三大特性为封装.继承和多态. 1.定义类 #定义空类 class Pers ...

  7. LocalReport Print with C# C#打印RDLC

             {             ;                                                      )             {        ...

  8. 关于OAuth的state参数的作用

    引用: https://blog.csdn.net/gjb724332682/article/details/54428808 在开发 OAuth认证服务器 的时候,开发者的安全意识不高的话,很可能会 ...

  9. Codeforces Round #395 (Div. 2) D. Timofey and rectangles

    地址:http://codeforces.com/contest/764/problem/D 题目: D. Timofey and rectangles time limit per test 2 s ...

  10. 把 html标签转化为 html标签代码

    HttpUtility.HtmlEncode(table.Rows[0]["footnote"].ToString());