SmsUtils 发送短信
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 发送短信的更多相关文章
- JAVA实现多线程处理批量发送短信、APP推送
/** * 推送消息 APP.短信 * @param message * @throws Exception */ public void sendMsg(Message message) throw ...
- java 阿里云接口实现发送短信验证码
此刻自己做的小项目中,需要用到手机发送短信验证码实现注册功能,于是就去阿里云注册了账号,并实现随机发送验证码的功能 第一步:在阿里云官网登录注册 已有支付宝或淘宝的账号可以直接登录,最后需要实名认 ...
- 移动MAS短信平台发送短信
MAS短信平台发送短信分为两种方式 参考文档下载 一.sdk调用 using mas.ecloud.sdkclient; using System; namespace 短信发送 { class Pr ...
- PHP发送短信功能
发送短信的功能主要在于获得短信接口后,在函数中模仿用户行为,例如浏览器跳转输出短信接口的链接. 需要运用的函数为 curl_init(); curl_setopt(); curl_exec(); cu ...
- WPF MVVM下做发送短信小按钮
最近做一个项目,因为涉及到注册,因此需要发送短信,一般发送短信都有一个倒计时的小按钮,因此,就做了一个,在此做个记录. 一.发送消息 没有调用公司的短信平台,只是模拟前台生成一串数字,将此串数字输出一 ...
- NetCore 阿里大于发送短信
使用阿里大于API发送短信,但阿里没有提供NetCore 的API,自己看了下源码重写了发短信这个部分 public class MessageSender { private readonly st ...
- android 中调用接口发送短信
android中可以通过两种方式发送短信 第一:调用系统短信接口直接发送短信:主要代码如下: //直接调用短信接口发短信 SmsManager smsManager = SmsManager.getD ...
- Android 学习第13课,android 实现发送短信的功能
1. 界面布局 界面代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...
- ios调用本地拨打电话,发送短信
电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicat ...
随机推荐
- 信息安全意识教育日历——By 安全牛
安全牛:企业即使投入再好的信息安全技术和产品,也难以解决内部威胁以及社会工程等攻击手段,无法做到全面有效地保护企业信息资产.而通过开展员工的信息安全意识培训教育工作,不仅能降低企业风险.满足合规要求, ...
- Part1.2 、RabbitMQ -- Publish/Subscribe 【发布和订阅】
python 目录 (一).交换 (Exchanges) -- 1.1 武sir 经典 Exchanges 案例展示. (二).临时队列( Temporary queues ) (三).绑定(Bind ...
- git分支更新代码命令
第一步: 查看状态 git status 第二步: 全部添加 git add --all 第三步: 再次查看状态 git status 第四步: 提交 git commit -m '备 ...
- 终端创建scrapy项目时报错(转)
在终端创建scrapy项目时报错 PS D:\scrapy_project> scrapy startproject fangFatal error in launcher: Unable to ...
- [笔记]Go语言写文件几种方式性能对比
Go语言中写文件有多种方式,这里进行如下几种方式的速度对比: 打开文件,写入内容,关闭文件.如此重复多次 打开文件,写入内容,defer 关闭文件.如此重复多次 打开文件,重复多次写入内容,defer ...
- C#:DateTime格式增减时间
DateTime time = DateTime.Now(); DateTime XMinutesrLater = time.AddMinutes(X); // X分钟以后的时间,即在当前时间基础上增 ...
- CodeForces - 920F SUM and REPLACE (线段树)
题意:给N个数M次操作,(1<=N,M<=3e5, 1<=ai<=1e6),1是使[L,R]中的每个元素变成其因子的个数之和:2是求[L,R]区间之和 分析:看上去就很线段树的 ...
- 【Flask】Flask Session操作
### session:1. session的基本概念:session和cookie的作用有点类似,都是为了存储用户相关的信息.不同的是,cookie是存储在本地浏览器,session是一个思路.一个 ...
- Oracle11g:分区表数据操作出现ORA-14400异常处理
Oracle11g:分区表数据操作出现ORA-14400异常处理 问题: 当对已分区的表数据进行操作(例如新增,修改),出现异常提示: ORA: 插入的分区关键字未映射到任何分区 分析: 意思说的是插 ...
- Linux系统crontab定时调度Python脚本
Linux系统crontab定时调度Python脚本 一.Python脚本随Linux开机自动运行 #Python脚本:/home/edgar/auto.py #用root权限编辑以下文件:/etc/ ...