网建平台短信发送
package com.util;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import java.io.IOException;
public class SendMsg {
public static void main(String[] args) throws IOException {
String userID = "***";
String userKey = "***";
String smsMob = "130****2104,139****1027";
String smsText = "网建sms 这是开发测试用的短信批量发送内容2";
String result = sendMsg(userID, userKey, smsMob, smsText);
System.out.println(result);
}
public static String sendMsg(String userID, String userKey, String smsMob, String smsText) throws IOException {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://utf8.api.smschinese.cn");
post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf8");
NameValuePair[] data = {
new NameValuePair("Uid", userID),
new NameValuePair("Key", userKey),
new NameValuePair("smsMob", smsMob),
new NameValuePair("smsText", smsText)
};
post.setRequestBody(data);
client.executeMethod(post);
String result = new String(post.getResponseBodyAsString().getBytes("UTF-8"));
post.releaseConnection();
return result;
}
}