短信猫实现短信验证小例子
其实很多人都在用短信平台做这个注册的短信验证这块,以下是一个短信猫做短信验证的例子。
有具体的注解,可以尝试用用。
/**
* 获取验证码
*/
public void sendCode()
{
try
{
// 获取手机号码
String phoneNo = ((String[])ActionContext.getContext().getParameters().get("phoneNo"))[0].trim();
// 获取6位sms验证码
String SMSCode = SMSCodeUtil.createSMSCode();
// 将sms验证码放入session中
ActionContext.getContext().getSession().put("SMSCode",SMSCode);
// 建立currentTimeMillis定时器
ActionContext.getContext().getSession().put("SMSTime",System.currentTimeMillis());
String smsContext = "[卖炭网]注册验证码:" + SMSCode + ",该验证码有效期为5分钟。如非本人操作,请忽略此短信。";
// 建立流对象
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");
SendRecieveSms.getSendSms(phoneNo, smsContext, inputStream);
getResponse().getWriter().print("1");
}
catch (Exception e)
{
e.printStackTrace();
}
}
//这里较常用的包就不贴出来了
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;//短信猫的包
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
//提供短信猫的接口类
public class SendRecieveSms {
private String endPoint;
private String namespace;
private String method;
private static SendRecieveSms sendRecieveSms = null;
static Properties p = new Properties();
public SendRecieveSms(String endPoint, String namespace, String method) {
this.endPoint = endPoint;
this.namespace = namespace;
this.method = method;
}
/**
* 发短信部分
*/
public String sendSms(String phone, String msg, String com){
String strRtn = null;
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(this.endPoint));
call.setOperationName(new QName(this.namespace, method));
call.addParameter(new QName(this.namespace, "phone"),XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new QName(this.namespace, "msg"),XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new QName(this.namespace, "com"),XMLType.XSD_STRING, ParameterMode.IN);
call.setUseSOAPAction(true);
call.setSOAPActionURI(namespace + method);
call.setReturnType(XMLType.XSD_STRING);
strRtn = call.invoke(new Object[] { phone, msg , com }).toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
return strRtn;
}
/**
* @param args
* 在此处传入三个参数
* 分别是电话号码、短信内容、流对象
*/
public static String getSendSms(String phoneNo, String smsContext, InputStream inputStream)
{
synchronized (SendRecieveSms.class)
{
if(sendRecieveSms == null)
{
try {
p.load(inputStream);
} catch (IOException e1) {
e1.printStackTrace();
}
sendRecieveSms = new SendRecieveSms(
"http://"+p.getProperty("message.service.host")+":"+p.getProperty("message.service.port")+"/Service.asmx",
"http://qxtweb/webservices", "Sendmsg");
}
return sendRecieveSms.sendSms(phoneNo, smsContext, p.getProperty("message.service.com"));
}
}
/**
* @param args
* 测试main方法
*/
public static void main(String[] args) {
SendRecieveSms lmm = new SendRecieveSms(
"http://localhost:4305/Service.asmx",
"http://qxtweb/webservices", "Sendmsg");
System.out.println(lmm.sendSms("18706897798", "您好,您的验证码为:【9645】", "COM3"));
}
}
短信猫实现短信验证小例子相关推荐
- 通过asp.net 短信猫发短信
如今手机已成为大众交流的主要工具.有关手机的程序开发越来越广泛,本节通过典型实例介绍如何利用短信猫发送.接收短信. 1.方案分析 发短信的一种方法是利用短信猫发短信,本例中使用的是生产的串口短信猫. ...
- Java调用SMSLib用单口短信猫发送短信详解
技术园地 当前位置:短信猫网站主页 > 技术园地 > [转载]Java调用SMSLib用单口短信猫发送短信详解 发布时间:2017/02/09 点击量:620 SMSLib是Apache的 ...
- 超级终端调用短信猫发送短信说明
转载文章:超级终端调用短信猫发送短信说明 短信发送测试 1.短信收发说明命令说明: 1).设置短消息中心 AT+CSCA="+8613800756500"回车(短信中心具体的号码 ...
- wavecom短信猫发送短信失败
http://www.puppeter.cn/?p=106 wavecom短信猫发送短信失败 发表评论 分类:运维工具 | 标签:sms wavecom | 1,048 views 放置在机房用于监控 ...
- 基于JCFXBL与GSM短信猫的短信中心建设方案
基于JCFXBL与GSM短信猫的短信中心建设方案 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/ex_net/article/details/87 ...
- asp.Net下短信猫发送短信中的中文乱码解决
现象:用c#编码调用短信猫发送包含中文字符的短信,但收到的总是乱码或问号(?),使用了Default, Unicode-16等多种编码方式仍然无效,而其他非中文字符都可以正常接收. 另外,在超级终端中 ...
- c#实现wavecom短信猫发送长短信
长短信是有规约的,协议头部分如果是0x40以下,则说明是普通短信,如果是0x40以上,则是长短信,然后在短信内容部分,有六个字节分别定义短信唯一标识以及该短信是第几条,所以长短信发送时每条实际为67个 ...
- Wavecom 短信猫 发送短信设置
短信猫设置(命令为独占,当前命令没有返回写入其他命令提示ERROR) AT+CMGF 设置短信格式 AT+CMGF=0 设置短信为PDU格式 AT+CMGF=1 设置短信为text 格式(不能直接发送 ...
- java读取手机短信_使用短信猫读取短信java代码
短信猫简单配置:https://www.cnblogs.com/Big-Boss/p/9699880.html 测试发送短信代码:https://www.cnblogs.com/Big-Boss/p/ ...
最新文章
- 【转载】在服务器上用Fiddler抓取HTTPS流量
- Day 14 知识点串讲 下
- linux | 网卡驱动
- jQuery 效果 - 动画
- android屏幕基础知识
- linux下写脚本时-gt是什么意思
- gMIS吉密斯导航菜单Navimenu、自动安装等更新
- udp端口转发 Linux,Linux iptables 端口转发
- linux下的ps4手柄驱动,DS4 To XInput Wrapper
- tplink连接服务器失败_tplink路由器网络已连接但是上不了网怎么办?
- 家庭账本应该怎样记简洁明了
- quartus II 18.1 Qsys简单操作步骤
- 微信小程序零基础入门_第一章 小程序和开发者工具的介绍
- Autolayout布局相关和UIStackView
- GAS汇编器伪指令大全
- 学习笔记之范海鹰微表情识别
- 基于微信小程序的电影院买票选座系统
- 如何配置在线Yum源?
- vagrant搭建nginx、php环境,两个项目间使用curl请求问题
- (二) 简单认识Emacs