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. Sending 'ccColor4B' (aka 'struct_ccColor4B') to parameter of incompatible type

    今天遇到了如下的一个错误, Sending 'ccColor4B' (aka 'struct_ccColor4B') to parameter of incompatible type CiColor ...

  2. Hibernate 的查询

    1. Hibernate 框架的查询方式 唯一标识OID的检索方式: session.get(对象.class, OID) 对象导航的方式; HQL 检索方式; QBC 检索方式; SQL 检索方式 ...

  3. Java 集合框架查阅技巧

    如何记录每一个容器的结构和所属体系呢? List ArrayList LinkedList Set HashSet TreeSet 其中,后缀名就是该集合所属的体系,前缀名就是该集合的数据结构. 看到 ...

  4. 安装MySQL版本为mysql-installer-community-5.7.17.msi

    双击MySQL安装包, 勾选复选框,点击下一步: 选择仅仅服务器模式,点击下一步: 直接点击执行: 执行完成,点击下一步: 确认配置,点击下一步: 输入用户名和密码,点击下一步: 默认选项,点击下一步 ...

  5. DL for objection detection

    在计算机视觉领域,"目标检测"主要解决两个问题:图像上多个目标物在哪里(位置),是什么(类别).围绕这个问题,人们一般把其发展历程分为3个阶段:1. 传统的目标检测方法2. 以R- ...

  6. springcloud 开发时快速剔除无用服务

    注册中心配置: # 关闭保护机制 eureka.server.enable-self-preservation=false #剔除失效服务间隔 eureka.server.eviction-inter ...

  7. path的join和resolve的使用区别

    文章目录   1.连接路径:path.join([path1][, path2][, ...]) 2.路径解析:path.resolve([from ...], to) 3.对比 1.连接路径:pat ...

  8. Oracle DG强制激活 备库

    在实际运营环境中,我们经常碰到类似这样的需求,譬如想不影响现网业务评估DB补丁在现网环境中运行的时间,或者是想在做DB切换前想连接Standby DB做实际业务运行的测试,如果在9i版本的时候,想做到 ...

  9. Spark SQL原理和实现--王家林老师

  10. 查询前几条记录 top limit

    SQL Server 数据库中的Top关键字可实现查询数据库表中的前几条数据,但是需要注意的是,Top关键字只能在SQL Server数据库中可以使用,而在MySQL数据库中就要使用具有同样功能的LI ...