網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > 綜合知識 > 

java編寫手機短信,高手賜教|java發短信怎麼寫

欄目: 綜合知識 / 發佈於: / 人氣:2.1W
1.java 編寫手機短信,高手賜教

package examples;

java發短信怎麼寫 java編寫手機短信,高手賜教

import java.util.Scanner;

public class Entry {

public static void main(String args []) {

Scanner sc=new Scanner(System.in);

String pno,msg;

System.out.print("請輸入短信內容:");

msg=sc.nextLine();

System.out.println("請輸入目標**碼:");

pno=sc.nextLine();

ShortMesg newmsg=new ShortMesg();

newmsg.setPhoneNO(pno);

newmsg.setMessage(msg);

SendMesg send=new SendMesg(newmsg);

send.send();

}

}

class ShortMesg {

public ShortMesg() {

}

private String pno,msg;

public void setPhoneNO(String pno) {

this.pno=pno;

}

public String getPhoneNO() {

return this.pno;

}

public void setMessage( String msg) {

this.msg=msg;

}

public String getMessage() {

return this.msg;

}

}

class SendMesg {

private ShortMesg mms;

public SendMesg(ShortMesg mms) {

this.mms=mms;

}

public void send() {

System.out.println("短信內容: "+mms.getMessage());

System.out.println("目標手機: "+mms.getPhoneNO()+"n");

}

}

2.如何用Java實現短信自動發送功能

Java實現短信自動發送功能主要是用mon包;

3、此外還需要第三方庫SMSLib,這個是開源項目,主要用於實現java發短信的功能;

主要代碼如下:

要匯入三個包commons_codec,/submitdata/service.asmx/g_Submit");

post.addRequestHeader("Content-Type",

"application/x-www-form-urlencoded;charset=utf-8");// 在頭檔案中設定轉碼

NameValuePair[] data = { new NameValuePair("sname", "*****"),

new NameValuePair("spwd", "*****"),

new NameValuePair("scorpid", "*****"),

new NameValuePair("sprdid", "*****"),

new NameValuePair("sdst", "*****"),

new NameValuePair("smsg", "*****") };

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.().getBytes(

"utf-8"));

System.out.println(result);

post.releaseConnection();