Java调取创蓝253短信验证码的实现代码
基于创蓝253短信服务平台的Java调用短信接口API
packagecom.bcloud.msg.http;
importjava.io.ByteArrayOutputStream;
importjava.io.InputStream;
importjava.net.URLDecoder;
importorg.apache.commons.httpclient.HttpClient;
importorg.apache.commons.httpclient.HttpStatus;
importorg.apache.commons.httpclient.NameValuePair;
importorg.apache.commons.httpclient.URI;
importorg.apache.commons.httpclient.methods.GetMethod;
/**
*
*@paramurl应用地址,类似于http://ip:port/msg/
*@paramaccount账号
*@parampswd密码
*@parammobile手机号码,多个号码使用","分割
*@parammsg短信内容
*@paramneedstatus是否需要状态报告,需要true,不需要false
*@return返回值定义参见HTTP协议文档
*@throwsException
*/
publicstaticStringbatchSend(Stringurl,Stringaccount,Stringpswd,Stringmobile,Stringmsg,
booleanneedstatus,Stringextno)throwsException{
HttpClientclient=newHttpClient();
GetMethodmethod=newGetMethod();
try{
URIbase=newURI(url,false);
method.setURI(newURI(base,"HttpBatchSendSM",false));
method.setQueryString(newNameValuePair[]{
newNameValuePair("account",account),
newNameValuePair("pswd",pswd),
newNameValuePair("mobile",mobile),
newNameValuePair("needstatus",String.valueOf(needstatus)),
newNameValuePair("msg",msg),
newNameValuePair("extno",extno),
});
intresult=client.executeMethod(method);
if(result==HttpStatus.SC_OK){
InputStreamin=method.getResponseBodyAsStream();
ByteArrayOutputStreambaos=newByteArrayOutputStream();
byte[]buffer=newbyte[1024];
intlen=0;
while((len=in.read(buffer))!=-1){
baos.write(buffer,0,len);
}
returnURLDecoder.decode(baos.toString(),"UTF-8");
}else{
thrownewException("HTTPERRORStatus:"+method.getStatusCode()+":"+method.getStatusText());
}
}finally{
method.releaseConnection();
}
}
}
总结
以上所述是小编给大家介绍的Java调取创蓝253短信验证码的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!