使用web短信平台发送短信
2011-07-15 09:53
423 查看
// 使用web短信平台发送短信
首先创建一个messgee.properties 文件,
文件内部写入用户名和密码
比如:
#短信平台的账号和密码
cdkey=3ADK-YUH-0130-LGXQO
password=945681
编写发送短信类
@Override
public void sendMsg(String content, String phones) throws Exception {
try {
if(phones == null || "".equals(phones) || "null".equals(phones) || content == null || "".equals(content) || "null".equals(content))
return;
ResourceBundle bundle=PropertyResourceBundle.getBundle("message");
String cdkey=bundle.getString("cdkey");
String password=bundle.getString("password");
content = URLEncoder.encode(content, "utf-8");
String urlstr = "http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action?cdkey="+cdkey+"&password="+password+"&phone="+phones+"&message="+content +"&addserial=";
URL url = new URL(urlstr);
URLConnection urlConn = url.openConnection();
urlConn.connect();
InputStream in = urlConn.getInputStream();
in = new BufferedInputStream(in);
// Reader r = new InputStreamReader(in);
// int c;
// while ((c = r.read()) != -1){
// System.out.print(c + "==1表示发送成功");
// }
in.close();
}catch (Exception exception) {
exception.printStackTrace();
}
}
首先创建一个messgee.properties 文件,
文件内部写入用户名和密码
比如:
#短信平台的账号和密码
cdkey=3ADK-YUH-0130-LGXQO
password=945681
编写发送短信类
@Override
public void sendMsg(String content, String phones) throws Exception {
try {
if(phones == null || "".equals(phones) || "null".equals(phones) || content == null || "".equals(content) || "null".equals(content))
return;
ResourceBundle bundle=PropertyResourceBundle.getBundle("message");
String cdkey=bundle.getString("cdkey");
String password=bundle.getString("password");
content = URLEncoder.encode(content, "utf-8");
String urlstr = "http://sdkhttp.eucp.b2m.cn/sdkproxy/sendsms.action?cdkey="+cdkey+"&password="+password+"&phone="+phones+"&message="+content +"&addserial=";
URL url = new URL(urlstr);
URLConnection urlConn = url.openConnection();
urlConn.connect();
InputStream in = urlConn.getInputStream();
in = new BufferedInputStream(in);
// Reader r = new InputStreamReader(in);
// int c;
// while ((c = r.read()) != -1){
// System.out.print(c + "==1表示发送成功");
// }
in.close();
}catch (Exception exception) {
exception.printStackTrace();
}
}
相关文章推荐
- Linux平台,使用JavaComm3 API及SMSLib项目实现在Web Application中发送手机短信的功能
- javaweb使用JSON格式利用云之讯平台发送短信(单条)
- 使用第三方平台短信接口实现发送验证码
- php使用阿里大于短信平台发送验证码记录
- java项目中使用阿里大于平台进行短信发送
- 使用阿里大于平台发送短信验证码java代码实现
- 短信应用接口发送平台使用篇——短信签名、模板设置
- Web应用中使用JavaMail发送邮件
- 使用Sencha Touch开发移动Web应用平台
- 在.net平台上如何创建和使用web 服务(C#)
- 自己开发的web快速开发平台教程(3),工具条(Toolbar)的使用教程
- 用 Java 通过串口发送手机短信(二)简单使用
- 使用MTM发送中文短信 需要更改的配置信息
- 使用 Web Services Enhancements 发送带有附件的 SOAP 消息
- activity间数据传递实例_使用系统短信发送器发送数据
- Android使用第三方服务器Bmob实现发送短信验证码
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 3)
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 4)
- JavaWeb学习总结(五十三)——Web应用中使用JavaMail发送邮件
- 使用httpwebrequest发送数据到网站