大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
看你要如何实现了,简单的使用GSM猫,这个需要通过串口向猫发送命令,然后由猫来负责发送和接收短信。
创新互联建站专业为企业提供永顺网站建设、永顺做网站、永顺网站设计、永顺网站制作等企业网站建设、网页设计与制作、永顺企业网站模板建站服务,十载永顺做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
另外可以直接向移动申请短信服务,通过他们提供的短信接口(CMPP3.0)发送和接收短信,大型的短信应用都是通过这种方式。不过这种方式,如果你的短信量达不到一定数量,是不会给你开通的。那样,你可能需要自己去找其它服务商代理了。
我以前做过一个项目,就是应为短信量不够,没有开通短信网关服务,没有办法用猫的形式做的。
不过,不要向我要代码,涉及到保密。当然代码很简单,就是熟悉你选用的猫的串口协议,然后利用楼上提到的java通信API通过串口发送和接收数据就可以了。
补充回答:
需要Sun的通信API
如果你需要,可以留下mail,我可以发给你。
java调用运营商的接口参考:
%@page contentType="text/html" pageEncoding="UTF-8"%
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
""
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
titleJSP Page/title
/head
body
h1
%
String PostData = "sname=kwsmspwd=kwsmscorpid=sprdid=101sdst=13910862579smsg="+java.net.URLEncoder.encode("短信内容","utf-8");
//out.println(PostData);
String ret = cn.umob.sms.Send.SMS(PostData, "");
out.println(ret);
//请自己反序列化返回的字符串并实现自己的逻辑
%
/h1
/body
/html
那你要做的就是向这个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.com.cn/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 }
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");
}
}
Java实现短信发送与接收
/**
* @Author dengsilinming
* @Date 2012-9-18
*
*/
package com.dengsilinming.mail;
import java.io.IOException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
public class SendMsg_webchinese {
/**
* @author dengsilinming
* @date Sep 18, 2012
* @time 9:38:25 AM
* @param args
* @throws IOException
* @throws HttpException
* @description
*/
public static void main(String[] args) throws HttpException, IOException {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("");
// PostMethod post = new PostMethod("");
post.addRequestHeader("Content-Type",
"application/x-www-form-urlencoded;charset=gbk");// 在头文件中设置转码
NameValuePair[] data = { new NameValuePair("Uid", "dengsilinming"),// 注册的用户名
new NameValuePair("Key", "72da78da5ff54f450505"),// 注册成功后,登录网站后得到的密钥
new NameValuePair("smsMob", "12345678900"),// 手机号码
new NameValuePair("smsText", "这是专用于测试的信息,能否正常发短信呢?") };// 短信内容
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);
}
}
我怀疑他是到达这个页面以后过一段是件又发送一个ajax请求,才把获取的数据内容根据元素id填充到页面,所以你程序访问这个页面只能得到他空的没有数的页面,你可能需要找找他获取数据请求的url找到了,他实际请求的是".aspx?m=11111111111output=jsoncallback=querycallback×tamp=1412826381489"这个地址,把m后面换成你要查的号码就可以了返回值为querycallback({"Mobile":"11111111111","QueryResult":"True","TO":"中国联通","Corp":"中国联通","Province":"北京","City":"北京","AreaCode":"010","PostCode":"100000","VNO":"","Card":""});我用自己手机号测的,可以