您的位置:首页 > 其它

使用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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: