package examples;
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();