java发送手机信息代码 java发送手机信息代码是什么( 二 )


*pswd
* @param mobile
*手机号码
* @param content
*短信发送内容
*/
public static String send(String account,String pswd, String mobile, String msg) {
NameValuePair[] data = https://www.04ip.com/post/{ new NameValuePair(“account”, account),
new NameValuePair(“pswd”, pswd),
new NameValuePair(“mobile”, mobile),
【java发送手机信息代码 java发送手机信息代码是什么】new NameValuePair(“msg”, msg),
new NameValuePair(“needstatus”, “true”),
new NameValuePair(“product”, “”) };
return doPost(url, data);
}
/**
* 基于HttpClient的post函数
* PH
* @param url
*提交的URL
*
* @param data
*提交NameValuePair参数
* @return 提交响应
*/
private static String doPost(String url, NameValuePair[] data) {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
// method.setRequestHeader(“ContentType”,
// “application/x-www-form-urlencoded;charset=UTF-8”);
method.setRequestBody(data);
// client.getParams() 。setContentCharset(“UTF-8”);
client.getParams() 。setConnectionManagerTimeout(10000);
try {
client.executeMethod(method);
return method.getResponseBodyAsString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
java 编写手机短信,高手赐教!!!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调用短信接口给手机发送短信怎么写代码??接口已经有了,是一个url.那你要做的就是向这个URL发送数据就好,给个例子:
publicclassHttptest1{
8
9publicstaticvoidmain(String[] args){
10
11URL url=null ;
12HttpURLConnection conn=null ;
13OutputStream outStream=null ;
14InputStream inStream=null ;
15
16try{
17url=newURL( "" );
18conn=(HttpURLConnection) url.openConnection();
19conn.setDoOutput( true );
20conn.setDoInput( true );
21
22String sendXml=" ?xml version=\ " 1.0 \ "encoding=\ " UTF - 16 \ " ?!DOCTYPE SigMailCommand SYSTEM \ " SigMail.dtd\ " " ;// XML数据
23sendXml+=" SigMailCommand Name=\ " checkuser\ " Param Name=\ " domainname\ " test.com.cn/Param " ;
24sendXml+=" Param Name=\ " username\ " admin/Param/SigMailCommand " ;
25
26outStream=conn.getOutputStream();
27
28// 准备通过CONN对象写入XML数据
29BufferedWriter bw=newBufferedWriter( newjava.io.OutputStreamWriter(outStream,
30" UTF-16 " ));

推荐阅读