十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
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");
}
}
那你要做的就是向这个URL发送数据就好,给个例子:
public class Httptest1 {
8
9 public static void main(String[] args) {
10
11 URL url = null ;
12 HttpURLConnection conn = null ;
13 OutputStream outStream = null ;
14 InputStream inStream = null ;
15
16 try {
17 url = new URL( " " );
18 conn = (HttpURLConnection) url.openConnection();
19 conn.setDoOutput( true );
20 conn.setDoInput( true );
21
22 String sendXml = " ?xml version=\ " 1.0 \ " encoding=\ " UTF - 16 \ " ?!DOCTYPE SigMailCommand SYSTEM \ " SigMail.dtd\ " " ; // XML数据
23 sendXml += " SigMailCommand Name=\ " checkuser\ " Param Name=\ " domainname\ " test点抗 点吸烟 /Param " ;
24 sendXml += " Param Name=\ " username\ " admin/Param/SigMailCommand " ;
25
26 outStream = conn.getOutputStream();
27
28 // 准备通过CONN对象写入XML数据
29 BufferedWriter bw = new BufferedWriter( new java.io.OutputStreamWriter(outStream,
30 " UTF-16 " ));
31 bw.write(sendXml);
32 bw.flush();
33 bw.close();
34
35 // DataOutputStream dataOutStream = new DataOutputStream(outStream);
36 // dataOutStream.writeChars(xml);
37 // dataOutStream.flush();
38 // dataOutStream.close();
39
40
41 // 准备通过CONN对象读取返回的XML数据
42
43 inStream = conn.getInputStream();
44 StringBuffer returnXml = new StringBuffer( "" );
45 BufferedReader rd = new BufferedReader( new InputStreamReader(inStream,
46 " UTF-16 " ));
47 for (String line = null ; (line = rd.readLine()) != null ;) {
48 returnXml.append(line);
49 }
50 System.out.println(returnXml.toString());
51 rd.close();
52 } catch (IOException ex) {
53 ex.printStackTrace();
54 } finally {
55 try {
56 if (outStream != null )
57 outStream.close();
58 if (inStream != null )
59 inStream.close();
60 if (conn != null )
61 conn.disconnect();
62 } catch (IOException e) {
63 // TODO 自动生成 catch 块
64 e.printStackTrace();
65 }
66 }
67
68 }
69
70 }
Java实现短信自动发送功能主要是用httpclient实现的,要有发短信的端口。
1、硬件设备是一个3G网卡;
2、软件方面需要sun提过的java底层通信common包;
3、此外还需要第三方库SMSLib,这个是开源项目,主要用于实现java发短信的功能;
主要代码如下:
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(
"");
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.getResponseBodyAsString().getBytes("utf-8"));
System.out.println(result);
post.releaseConnection();
Java源程序(.java文件)——java字节码文件(.class文件)——由解释执行器(java.exe)将字节码文件加载到java虚拟机(jvm)——字节码文件(.class)就会在java虚拟机中执行。
Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。
Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点 。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等