本文主要研究了JAVA語言發送手機,分享給大家,供大家參考,具體內容如下
JAVA發送手機短信,流傳有幾種方法:
(1)使用webservice接口發送手機短信,這個可以使用sina提供的webservice進行發送,但是需要進行注冊;
(2)使用短信mao的方式進行短信的發送,這種方式應該是比較的常用,前提是需要購買硬件設備,呵呵;
(3)使用中國網建提供的SMS短信平臺,我的這個小的demo,是基于這個行是發送的。
說明:java實現發送手機短信
/*** 說明:java實現發送手機短信* 作者:aa00aa00*/package com.test.mobile; 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://sms.webchinese.cn/web_api/");post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");// 在頭文件中設置轉碼NameValuePair[] data = { new NameValuePair("Uid", "*****"), // 注冊的用戶名new NameValuePair("Key", "*******"), // 注冊成功后,登錄網站使用的密鑰new NameValuePair("smsMob", "*********"), // 手機號碼new NameValuePair("smsText", "java程序發的信息!!") };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();}} 運行以上的代碼:就可以給自己的手機發送短信了,本人親測,沒有問題,分享給大家!
以上就是本文的全部內容,希望對大家學習java程序設計有所幫助。
新聞熱點
疑難解答