kokimiki

/**
* 阿里云通用短信发送
*
* @param msg
* @return
*/
public String sendAdapSms(String msg) {
String message = SMS_URL + "?sendType=" + sendType;
StringBuffer sb = send(msg, message);
return sb.toString();
}

/**
* 短信发送调用接口
*
* @param msg
* @param message
* @return
*/
protected static StringBuffer send(String msg, String message) {
BufferedReader in = null;
PrintWriter out = null;
StringBuffer sb = new StringBuffer();
// 发送请求,获取返回信息
try {
URL url = new URL(message);
URLConnection uc = url.openConnection();
uc.setRequestProperty("Content-Type", "text/plain");
uc.setDoOutput(true);
uc.setDoInput(true);
out = new PrintWriter(uc.getOutputStream());
out.print(msg);
out.flush();
in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String temp = null;
while ((temp = in.readLine()) != null) {
sb.append(temp);
}
} catch (MalformedURLException e) {
log.error("send msg error:{}", e.getLocalizedMessage(), e);
} catch (IOException e) {
log.error("send msg error:{}", e.getLocalizedMessage(), e);
} finally {
try {
if (in != null && out != null) {
in.close();
out.close();
}
} catch (IOException e) {
log.error("send msg error:{}", e.getLocalizedMessage(), e);
}
}
return sb;
}

分类:

技术点:

相关文章: