雙十一剛過去烦却,馬上迎來雙十二宠叼,各大公司都在想著發(fā)促銷短信給客戶,讓他們再買一波其爵,我們公司也不列外冒冬,這不,項(xiàng)目這邊又來了一波摩渺,這次需要給之前的客戶群發(fā)短信简烤,發(fā)一下我們公司的最新產(chǎn)品信息,讓他們點(diǎn)進(jìn)來脈脈摇幻,今天給大家介紹一下怎么用java去實(shí)現(xiàn)短信群發(fā)的功能横侦,首先去www.ihuyi.com上下載jar包以及注冊用戶,然后調(diào)用api接口绰姻,取得秘鑰
JAVA調(diào)用
import Java.io.UnsupportedEncodingException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
public class SendMsg_webchinese {
public static void main(String[] args)throws Exception
{
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在頭文件中設(shè)置轉(zhuǎn)碼
NameValuePair[] data ={ new NameValuePair("Uid", "本站用戶名"),new NameValuePair("Key", "接口安全密碼"),new NameValuePair("smsMob","手機(jī)號碼"),new NameValuePair("smsText","短信內(nèi)容")};
post.setRequestBody(data);
client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
System.out.println("statusCode:"+statusCode);
for(Header h : headers)
{
System.out.println(h.toString());
}
String result = new String(post.getResponseBodyAsString().getBytes("gbk"));
System.out.println(result);
post.releaseConnection();
}
}