- 浏览: 331327 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (59)
- wicket (1)
- java (24)
- js (27)
- xml (3)
- Android (1)
- 服务器 (7)
- 数据库 (7)
- spring (1)
- hibernate (1)
- ssh (6)
- web (25)
- oracle (1)
- 函数 (2)
- mysql (1)
- 手机 (6)
- javascript (21)
- session (3)
- cookie (4)
- struts (1)
- ngnix (1)
- 软件使用 (2)
- linux (1)
- vi (1)
- 前端 (6)
- javascrip (2)
- html (3)
- js css (2)
- 正则 (1)
- ajax (1)
- toast (1)
- 消息提示 (1)
- 确认弹窗 (1)
- springmvc (1)
- 倒计时 (1)
最新评论
-
wenm168:
美观的图片上传前预览效果:http://www.anyrt.c ...
JavaScript 图片的上传前预览(兼容所有浏览器) -
口弦1992:
我的ie9并没有图片预览出来啊。
JavaScript 图片的上传前预览(兼容所有浏览器) -
axie1234567:
分享的东西很有用。
java web中实现同一帐号同一时间只能一个地点登陆(类似QQ登录的功能) -
wyl4728:
32个赞
mysql函数大全 -
yu_long:
seeker.getCountry(ip);
解析出来的 ...
根据IP地址获取所在地
最近自己在弄一个英国的优惠券的网站!需要用到国外的短信发送接口!
搜索和查找发现有几个比较不错的短信发送接口网站!
代码粘出来给大家分享一下!
SMSService 抽象接口类
/** * squarelife * * @author eric * * 2011-11-28 下午08:41:43 */ package com.life.service.sms; /** * @author eric * * 2011-11-28 下午08:41:43 */ public interface SMSService { boolean sendMessage(String msg,String countryCode,String phoneNumber); }
需要配置的短信配置信息! sms.properties #短信接口名称Gateway160SMSServiceImpl,BulksmsSmsServiceImpl #Gateway160SMSServiceImpl,test123456,test123456, 065af763-bdb8-4f27-bc81-d6c14f2f545c #http://www.bulksms.co.uk/ #http://www.gateway160.com/ wy.sms.service.name=Gateway160SMSServiceImpl #短信接口的用户名 wy.sms.service.accountName=**** #短信接口国家代码 #Gateway160SMSServiceImpl 用国家代码如中国:CN 美国:US 英国:GB #BulksmsSmsServiceImpl 用电话代码如中国:86 美国:1 英国:44 wy.sms.service.countryCode=CN #短信接口的密码 wy.sms.service.password=**** #短信接口APIkey 注册时候的APIkey wy.sms.service.apiKey=****
package com.life.service.sms; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; import com.life.util.PropertyUtil; /** * * @author eric * * 2011-11-28 下午09:15:23 */ public class AbstractSMSService { /** * 获取属性值 * 2011-11-28 下午09:15:27 * @param key * @return */ protected String getProperty(String key) { return new PropertyUtil().getProperty(key); } /** * 2011-11-28 下午10:28:57 * @param params * @return * @throws UnsupportedEncodingException */ protected String encode(final HashMap<String,String> params) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : params.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); sb.append(URLEncoder.encode(key, "UTF-8")); sb.append("="); sb.append(URLEncoder.encode(val, "UTF-8")); sb.append("&"); } return sb.toString(); } }
BulksmsSmsServiceImpl 短信接口实现类 接口相关信息网址 http://www.bulksms.co.uk/
/** * squarelife * * @author eric * * 2011-11-28 下午09:33:18 */ package com.life.service.sms.impl; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; import org.apache.log4j.Logger; import com.life.service.sms.AbstractSMSService; import com.life.service.sms.SMSService; /** * @author eric * * 2011-11-28 下午09:33:18 */ public class BulksmsSmsServiceImpl extends AbstractSMSService implements SMSService { private static final Logger logger = Logger .getLogger(BulksmsSmsServiceImpl.class); /* * (non-Javadoc) * * @see com.life.service.sms.SMSService#sendMessage(java.lang.String, * java.lang.String, java.lang.String) */ @Override public boolean sendMessage(String msg, String countryCode, String phoneNumber) { HashMap<String, String> params = new HashMap<String, String>(); params.put("username", getProperty("wy.sms.service.accountName")); params.put("password", getProperty("wy.sms.service.password")); params.put("phoneNumber", phoneNumber); params.put("message", msg); params.put("want_report", "1"); params.put("msisdn", countryCode + phoneNumber); URL url = null; HttpURLConnection httpCon = null; try { // Construct data // String data = ""; /* * Note the suggested encoding for certain parameters, notably the * username, password and especially the message. ISO-8859-1 is * essentially the character set that we use for message bodies, * with a few exceptions for e.g. Greek characters. For a full list, * see: * http://www.bulksms.co.uk/docs/eapi/submission/character_encoding/ */ // Send data url = new URL( "http://www.bulksms.co.uk:5567/eapi/submission/send_sms/2/2.0"); /* * If your firewall blocks access to port 5567, you can fall back to * port 80: URL url = new * URL("http://www.bulksms.co.uk/eapi/submission/send_sms/2/2.0"); * (See FAQ for more details.) */ httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestMethod("POST"); httpCon.setRequestProperty("Content-type", "text/html"); httpCon.setRequestProperty("Accept-Charset", "UTF-8"); httpCon.setRequestProperty("contentType", "UTF-8"); // write post body OutputStreamWriter out = new OutputStreamWriter(httpCon .getOutputStream(), "UTF-8"); String postBody = encode(params); out.write(postBody); out.flush(); out.close(); // Get the response StringBuilder sb = new StringBuilder(); BufferedReader rd = new BufferedReader(new InputStreamReader( httpCon.getInputStream())); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); logger.info("responseCode=" + httpCon.getResponseCode()); logger.info("responseBody=" + sb.toString()); if (httpCon != null && httpCon.getResponseCode() == HttpURLConnection.HTTP_OK) { return true; } else { return false; } } catch (Exception e) { logger.error("Exception throw!", e); return false; } finally { if (httpCon != null) { httpCon.disconnect(); } } } }
Gateway160SMSServiceImpl 接口相关信息网址 http://www.gateway160.com/
/** * squarelife * * @author eric * * 2011-11-28 下午08:43:23 */ package com.life.service.sms.impl; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; import org.apache.log4j.Logger; import com.life.service.sms.AbstractSMSService; import com.life.service.sms.SMSService; /** * @author eric * * 2011-11-28 下午08:43:23 */ public class Gateway160SMSServiceImpl extends AbstractSMSService implements SMSService { private static final Logger logger = Logger .getLogger(Gateway160SMSServiceImpl.class); @Override public boolean sendMessage(String msgContent, String countryCode, String phoneNumber) { HashMap<String, String> params = new HashMap<String, String>(); params.put("accountName", getProperty("wy.sms.service.accountName")); params.put("key", getProperty("wy.sms.service.apiKey")); params.put("phoneNumber", phoneNumber); params.put("message", msgContent); params.put("countryCode", countryCode); try { URL url = new URL("http://api.gateway160.com/client/sendmessage/"); HttpURLConnection httpCon = (HttpURLConnection) url .openConnection(); httpCon.setDoOutput(true); httpCon.setRequestMethod("POST"); // write post body OutputStreamWriter out = new OutputStreamWriter(httpCon .getOutputStream()); String postBody = encode(params); out.write(postBody); out.flush(); out.close(); // Get the response StringBuilder sb = new StringBuilder(); BufferedReader rd = new BufferedReader(new InputStreamReader( httpCon.getInputStream())); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); logger.info("responseCode=" + httpCon.getResponseCode()); logger.info("responseBody=" + sb.toString()); if (httpCon != null && httpCon.getResponseCode() == HttpURLConnection.HTTP_OK) { logger.info("连接成功!"); if (sb != null && sb.equals("1")) { logger.info("短信发送成功!"); return true; } else if (sb != null && sb.equals("0")) { logger.info("invalid account name or key"); return false; } else if (sb != null && sb.equals("-1")) { logger.info("短信发送失败!"); return false; } else { return false; } } else { logger.info("连接失败!"); return false; } } catch (IOException e) { logger.error("IOException thrown! ", e); return false; } } }
给出测试类!相关的PropertiesUtil.java文件就不提供了。一般大家都会写吧!如果有实在有问题的可以联系我!
package com.life.test; import org.junit.Test; import com.life.service.sms.SMSService; import com.life.service.sms.impl.BulksmsSmsServiceImpl; import com.life.service.sms.impl.Gateway160SMSServiceImpl; /** * * @author eric * * 2011-11-28 下午10:01:35 */ public class SMSTest { @Test public void testSendMsg(){ // SMSService smsService=new BulksmsSmsServiceImpl(); // smsService.sendMessage("亲爱的,我爱你!", "86", "**********"); // // SMSService smsService=new Gateway160SMSServiceImpl(); // smsService.sendMessage("亲爱的,我爱你! ", "CN", "**********"); // // SMSService smsService=new Gateway160SMSServiceImpl(); // smsService.sendMessage("哈哈,你这么肯定是我发的呀,你好好上课吧,不打扰你上课了,上课加油!!三明治加油!!", "CN", "*******"); SMSService smsService=new Gateway160SMSServiceImpl(); smsService.sendMessage("你莫冤枉我撒,又冤枉我,老是冤枉我,我承认个啥呀,嘎", "CN", "*********"); } }
大家注意不同的短信接口需要的国家代码格式会有所不同,测试类可以看到。。相关国家代码可以去查看相关网页,百度,谷歌都可以查到。你懂的!另外附上国家代码查看文档!见附件
- 国家代码查看表.zip (21.5 KB)
- 下载次数: 37
评论
4 楼
wangyong31893189
2012-04-09
y_lj2003 写道
非洲那边项目,需要能发送短信,这个接口能用么?还是去找他们那边的
你看下国家代码,里是否有非洲国家的,如果有也是可以用的!前提请注册一个帐号密码
3 楼
y_lj2003
2012-03-14
非洲那边项目,需要能发送短信,这个接口能用么?还是去找他们那边的
2 楼
wangyong31893189
2011-12-16
rensanning 写道
使用Clickatell(API) 不是更简单嘛!
http://www.clickatell.com/
http://www.clickatell.com/
当然我也没有说我的这个接口就写得很简单了,只是供大家一个参考而已,如果有要用到的可以参考一下,有更简单的当然很好了啊!呵呵。。可以交流交流撒!
1 楼
rensanning
2011-12-11
使用Clickatell(API) 不是更简单嘛!
http://www.clickatell.com/
http://www.clickatell.com/
发表评论
-
简单上传文件插件
2017-07-12 11:46 620team777.upload.js js: ; ... -
利用html5进行城市定位!aqi指数的获取
2014-07-08 17:52 21351<html><head> < ... -
seajs打包部署工具spm的使用总结
2014-06-30 14:22 900相信使用seajs的好处大家都是知道的,接触seajs好像 ... -
eclispe 编辑XML时,输入<无法自动提示的修复
2014-02-20 14:40 973eclispe 当编辑XML时,一 ... -
javaScript的性能优化
2014-01-17 14:05 1223随着网络的发展,网速 ... -
可以用来解析字符串表达式的包
2012-10-16 10:57 2069import com.singularsys.jep.J ... -
实现局部图片的懒加载
2012-08-31 14:52 5443此方式适用和iscroll结合使用,若用于普 ... -
struts1的一些总结
2012-04-16 11:11 1712struts1 7大组件 ActionServlet 控制器 ... -
java web中实现同一帐号同一时间只能一个地点登陆(类似QQ登录的功能)
2012-03-26 13:11 9683在java web中如何实现像QQ登录的功能,同一帐号不 ... -
根据sessionid获取session的被Servlet2.1抛弃getsession方法的解决方案
2012-01-17 23:15 11886最近一个项目中用到了getsession根据ses ... -
触屏中的JavaScript事件
2012-01-06 21:40 27230一、触摸事件ontouchstarto ... -
mysql函数大全
2011-12-16 10:00 9934控制流函数IFNULL(expr1,expr2) 如果expr ... -
【转载】ORACLE函数大全
2011-12-16 09:57 806SQL中的单记录函数1.ASCII返回与指定的字符对 ... -
Mysql数据库的优化三(索引优化)
2011-12-12 09:34 1383在一些情况下,MySQL可以直接使用索引来满足一个 ORD ... -
Mysql数据库的优化二(查询优化)
2011-12-12 09:32 1258糟糕的SQL查询语句可对整个应用程序的运行产生严重的影响, ... -
Mysql数据库的优化(参数优化)
2011-12-12 09:29 1447MySQL运行参数,修改/etc/my.cnf ... -
java路径问题总结
2011-12-09 15:26 870一 相对路径的获得说明:相对路径(即不写明时候到底相对谁) ... -
Spring声明式事务配置管理方法
2011-12-09 13:30 2842事务配置 首先在/WEB-INF/applicatio ... -
jboss-5.1.0.GA 有时出现的启动报错解决方案(java.lang.IllegalArgumentException: Wrong argumen)
2011-12-09 09:39 3083错误代码:(实例化名称为“AttachmentStore”出错 ... -
根据IP地址获取所在地
2011-06-08 16:46 5358主要Test.java public class Test ...
相关推荐
摩杜云短信业务接入,该平台支持国内和国际快速发送验证码、短信通知和推广短信,服务范围覆盖全球200多个国家和地区。国内短信支持三网合一专属通道,与工信部携号转网平台实时互联。...完美支撑8亿短信发送。
亿美短信应用API接口-八项创新 1、全网覆盖:全国全网、电信、联通、移动显示同一号码 2、心跳机制:保证客户端与服务器时时连接 3、异步通讯:支持异步通讯,每个连接峰值可达20条/秒 4、智能化短信...
摩杜云短信业务接入,该平台支持国内和国际快速发送验证码、短信通知和推广短信,服务范围覆盖全球200多个国家和地区。国内短信支持三网合一专属通道,与工信部携号转网平台实时互联。...完美支撑8亿短信发送。
免费发送无限短信的接口 通过Google voice的服务你可以把短信(SMS)发送到世界上任何手机.而且这项服务是免费的,可靠的 你需要一个google voice的账号即可。
§支持各大短信联盟、自定义短信联盟代号、手机号码批量发送、国际区号、自定义落款等等,与任何硬件设备完全无关,也不依赖任何手机或单一平台。 §支持电子邮件特快专递,自动监测当前DNS、MX服务器,支持发送...
无心版移动短信发送v1.2升级说明: 1、新版程序采用UTF-8编码,完全与国际接轨。 2、去除每条短信后面的签名,您可以自由设置自己的签名。 3、新版程序采用新的服务器,更加稳定。 无心版移动短信发送v1.2使用...
2013免费发送短信工具 利用国外的接口 验证码识别率不是很高哦
完美支撑双11期间20亿短信发送,6亿用户触达。 使用其短信服务要先申请access key,短信签名和短信模板,审核时间一般一到两个工作日就可以了。 然后确保账户有余额,一条通知短信0.0045元。 随后就可以调用API...
短信服务验证服务已经不是什么新鲜事了,但是免费的手机短信服务却不多见,本次利用Python3.0基于Twilio和腾讯云服务分别来体验一下国际短信和国内短信接口。 首先,注册Twilio: www.twilio.com/ 注册成功后,获取...
提供短信平台,sp平台软件(支持三网),企信通平台. 运营商,电视台,报业集团,气象局,各行业企业,单位,sp等等电信增值业务运营公司 专用的著名稳定,短信平台,彩信平台软件 帮助测试接入移动,联通,电信运营...
无心短信发送程序能使用此程序发送短信到移动手机用户,支持最多发送350字,按标准短信资费0.1元/条计费注:由于移动限制,每一个邮箱每天仅能发送50条短信。 无心短信发送程序 1.2 升级说明: 1、新版程序采用...
支持GSM短信发送,中英文短信息发送,支持发送闪烁短信、免提短信。 支持BIT7格式发送(即对于英文,长度可达160个字符) 支持WAP PUSH发送 支持状态回复 支持小灵通号码发送 支持国际手机号码发送 接收短信时...
2、邮件通道是由国际顶尖的几家EDM数据公司提供的通道,发送成功率90%左右;3、短信和邮件提供API(SDK)程序接口,方便网站和软件开发商进行系统集成开发;4、软件方便用户对自己的客户进行分组、信息管理。5、软件...
基于云计算技术,DegreeSMS是美国最大的免费短信服务,允许短信发送通过免费网站上的任何手机运营商。 (以上为词霸自动翻译结果) 免责:由于程序是利用其他网站的接口制作,故随时有可能因为该网站变动而失效,...
支持BIT7格式发送(即对于英文,长度可达160个字符) 支持WAP PUSH发送 支持状态回复 支持小灵通号码发送 支持国际手机号码发送 接收短信时,可自行选择是否将短信保存于SIM卡中 提供At Command接口,通过这一接口...
接口说明 给用户发短信验证码、短信通知,营销短信(内容长度不超过450字)。 注:sdkappid请填写您在腾讯云上申请到的,random请填成随机数。 2 请求包体 包体为json字符串,参数如下: { "tel": { //如需使用国际...
提供短信平台,彩信平台软件,性能稳定.全国品牌SP平台软件. 运营商,电视台,报业集团,气象局, sp等等电信增值业务运营公司的专用 电信增值管理平台软件。 联系:QQ:84401116 电话:13950404552 许风 短信平台: 1、...
快客通是一款集短信、邮件营销接口的小型免费CRM系统,适用于电商(淘宝、天猫、拍拍、京东及传统B2C)、学校、医院、汽车4S店、餐饮娱乐等各行各业。 软件特点: 1、高质量106短信通道,在手机号码无误的情况下...