JAVA对接大汉三通短信http接口
public class TestEMA {
private static String ACCOUNT = "xxxxxxxxxx";
private static String PASSWORD = "xxxxxxxxxx";
private static String phone = "xxxxxxxxxx";
private static String content = "测试";
public static void main(String[] args) {
try {
long start = System.currentTimeMillis();
PASSWORD = MD5.MD5_32bit(PASSWORD);
content = java.net.URLEncoder.encode(content,"UTF-8");
String _url = "http://www.dh3t.com/json/sms/Submit";
String _param = "Account="+ACCOUNT+"&Password="+PASSWORD
+"&Phone="+phone+"&Content="+content+"&SuCode=&SendTime=";
URL url = new URL(_url);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true);
OutputStream outputStream = urlConnection.getOutputStream();
outputStream.write(_param.getBytes("GBK"));
outputStream.flush();
outputStream.close();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream(),"GBK"));
StringBuffer stringBuffer = new StringBuffer();
int ch;
while ((ch = bufferedReader.read())>-1){
stringBuffer.append((char)ch);
}
System.out.println(stringBuffer);
bufferedReader.close();
Long end = System.currentTimeMillis();
System.out.println("发送 短信 耗时:"+(end-start));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}