短信接口都是这样做的
来源:互联网 发布:csgo皮肤测评 知乎 编辑:程序博客网 时间:2024/05/10 15:51
public void send(String phoneNo, String content){
boolean flag = false;
HttpClient client = new HttpClient();
GetMethod method = new GetMethod();
try {
URI base;
try {
base = new URI("短信平台地址", false);
method.setURI(new URI(base, "HttpBatchSendSM", false));
method.setQueryString(new NameValuePair[] {
new NameValuePair("account", "短信平台账号"),
new NameValuePair("needstatus", String.valueOf(true)),
new NameValuePair("msg", content),
new NameValuePair("product", null),
new NameValuePair("extno", null),
});
} catch (URIException | NullPointerException e) {
e.printStackTrace();
}
int result;
try {
result = client.executeMethod(method);
if (result == HttpStatus.SC_OK) {
InputStream in = method.getResponseBodyAsStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = in.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
String[] str=URLDecoder.decode(baos.toString(), "UTF-8").split(",");
String[] s=str[1].split("\\r?\\n");
if(s[0].equals("0"))
{
flag=true;
}
return flag;
}
/*else {
throw new Exception("HTTP ERROR Status: " + method.getStatusCode() + ":" + method.getStatusText());
}*/
} catch (IOException e) {
e.printStackTrace();
}
} finally {
method.releaseConnection();
}
return flag;
}
boolean flag = false;
HttpClient client = new HttpClient();
GetMethod method = new GetMethod();
try {
URI base;
try {
base = new URI("短信平台地址", false);
method.setURI(new URI(base, "HttpBatchSendSM", false));
method.setQueryString(new NameValuePair[] {
new NameValuePair("account", "短信平台账号"),
new NameValuePair("pswd", "短信平台密码"),
//其他的参数看文档
new NameValuePair("mobile", phoneNo),new NameValuePair("needstatus", String.valueOf(true)),
new NameValuePair("msg", content),
new NameValuePair("product", null),
new NameValuePair("extno", null),
});
} catch (URIException | NullPointerException e) {
e.printStackTrace();
}
int result;
try {
result = client.executeMethod(method);
if (result == HttpStatus.SC_OK) {
InputStream in = method.getResponseBodyAsStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = in.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
String[] str=URLDecoder.decode(baos.toString(), "UTF-8").split(",");
String[] s=str[1].split("\\r?\\n");
if(s[0].equals("0"))
{
flag=true;
}
return flag;
}
/*else {
throw new Exception("HTTP ERROR Status: " + method.getStatusCode() + ":" + method.getStatusText());
}*/
} catch (IOException e) {
e.printStackTrace();
}
} finally {
method.releaseConnection();
}
return flag;
}
0 0
- 短信接口都是这样做的
- 都是这样的吗?
- asp.net两种方式的短信接口使用(提供接口的都是收费的)
- 九度OJ+贪心二分+最大值最小化都是这样做的。
- 负责现场接口,每天都是电话、电话、电话,真不知道这样的工作意义何在
- 生意通常都是这样谈成的.
- 成功人士都是这样逼出来的
- 高手都是这样清除系统垃圾的
- 成功人士都是这样逼出来的
- 成功人士都是这样逼出来的
- 很多时候,很多程序员都是这样的......
- 我们都是做技术的
- 主题 : hibernate中POJO一定要实现Serializable接口吗?这样做的目的是什么?
- hibernate中POJO一定要实现Serializable接口吗?这样做的目的是什么?
- hibernate中POJO一定要实现Serializable接口吗?这样做的目的是什么?
- 收到这样的短信你咋办
- 有没有这样的短信通知平台?
- 有没有这样的短信通知平台?
- 金婚
- 事件模型小结
- 手机为什么13开头?
- 了解mach-o文件结构
- 如何成为一个合格的java程序员
- 短信接口都是这样做的
- 作为一个合格程序员每天该做的事
- 不要启动Java DB
- 数字电视液晶显示器通用规范
- 披着函数外衣的关键字sizeof
- Groovy的野心
- iOS 录音
- prototype.js 使用指南(转载)
- 顶级总裁的时间哲学(转)