网站的发送短信功能必不可少,这里提供一个强大的平台蝶信通,之所以说它强大是因为改平台提供的接口文档比较详细,支持多种语言,而且附有一些小案例,使用起来相当方便;一般短信发送用途:用户注册、修改密码验证、手机认证、申请神马特殊身份等等,这里付一张注册图:
下面是常用的接口:
输入参数:
|
参数 |
说明 |
类型 |
|
CorpID |
账号 |
String |
|
Pwd |
密码 |
String |
|
Mobile |
发送手机号码 |
String |
|
Content |
发送内容 |
String |
|
Cell |
子号 |
String |
|
SendTime |
定时发送时间 |
String(14) |
输出参数:
|
输出返回值参数 |
状态说明 |
|
0 |
发送成功 |
|
–1 |
账号未注册 |
|
–2 |
其他错误 |
|
–3 |
密码错误 |
|
–4 |
手机号格式不对 |
|
–5 |
余额不足 |
|
–6 |
定时发送时间不是有效的时间格式 |
|
–7 |
禁止10小时以内向同一手机号发送相同短信 |
|
-100 |
限制此IP访问 |
|
-101 |
调用接口速度太快 |
调用方式:
http://115.28.14.21/WS/Send.aspx?CorpID=*&Pwd=*&Mobile=*&Content=*&Cell=*&SendTime=*
输入参数:
|
参数 |
说明 |
类型 |
|
CorpID |
账号 |
String |
|
Pwd |
密码 |
String |
|
Mobile |
发送手机号码 |
String |
|
Content |
发送内容(需要UrlEncode) |
String |
|
Cell |
子号 |
String |
|
SendTime |
定时发送时间 |
String(14) |
输出参数:
|
输出返回值参数 |
状态说明 |
|
大于0的数字 |
发送成功(得到大于0的数字、作为取报告的id) |
|
–1 |
账号未注册 |
|
–2 |
其他错误 |
|
–3 |
密码错误 |
|
–4 |
手机号格式不对 |
|
–5 |
余额不足 |
|
–6 |
定时发送时间不是有效的时间格式 |
|
–7 |
禁止10小时以内向同一手机号发送相同短信 |
|
-100 |
限制此IP访问 |
|
-101 |
调用接口速度太快 |
http://115.28.14.21/WS/Send2.aspx?CorpID=*&Pwd=*&Mobile=*&Content=*&Cell=*&SendTime=*
这里先来一个http访问接口的案例,我比较喜欢用http请求,用着简单方便,闲话少说,上代码:
<span style="font-family:KaiTi_GB2312;font-size:18px;">package com.hudong.postmessage.dao.smstools;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import com.hoodong.framework.util.FrameProperties;
importcom.hudong.core.common.logger.HuDongErrorCodeEnum;
import com.hudong.core.common.logger.HuDongLogger;
import com.hudong.core.common.logger.HuDongLoggerFactory;
import com.hudong.postmessage.dao.impl.SendSMSDAOImpl;
/**
* 蝶信短信接口
* @Title:ButterflyLetterSMSClient.java
* @Copyright:Copyright (c) 2005
* @Created on 2014-5-16 上午10:06:37
* @author 杨凯
*/
public class ButterflyLetterSMSClient {
private finalstatic HuDongLogger logger =HuDongLoggerFactory.getLogger(SendSMSDAOImpl.class);
/**
* 发送短信接口
* @paramMobile
* @paramContent
* @paramsend_time
* @return
*/
public staticint sendSMS(String Mobile,String Content,String send_time,String srcCharset) {
URL url =null;
intinputLine = 1000;
try {
StringCorpID = FrameProperties.getProperties("SysConfig.xml","CorpID"); //用户名
StringPwd=FrameProperties.getProperties("SysConfig.xml","Pwd"); //密码
StringBlUrl=FrameProperties.getProperties("SysConfig.xml","BlUrl"); //接口
Stringsend_content=URLEncoder.encode(Content.replaceAll("<br/>"," "), srcCharset);//发送内容
url = newURL(BlUrl+"?CorpID="+CorpID+"&Pwd="+Pwd+"&Mobile="+Mobile+"&Content="+send_content+"&Cell=&SendTime="+send_time);
BufferedReader in = null;
in =new BufferedReader(new InputStreamReader(url.openStream()));
inputLine = new Integer(in.readLine()).intValue();
} catch(Exception e) {
logger.error(HuDongErrorCodeEnum.RemoteRequestError, "网络异常,发送短信失败!mobiles:" + Mobile);
inputLine=-2;
}
returninputLine;
}
}</span>
就这么简单,上面代码去除一些业务性的东西,其实三五行代码,当然第三方平台都是收费的,想想移动、联通、电信运营商也不可能让你免费发短信的。附上碟信通的相关文档的下载地址:http://download.csdn.net/detail/tianyazaiheruan/7489329
原文地址:http://blog.csdn.net/yangkai_hudong/article/details/30260037