java发短信怎么写 java编写手机短信,高手赐教
- 综合知识
- 关注:2.29W次
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();
- 文章版权属于文章作者所有,转载请注明 https://dongkepu.com/zonghezhishi/m9ly0p.html