*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 " ));
推荐阅读
- steam有哪些飞行游戏,steam有什么模拟飞行游戏
- 拆硬盘螺丝刀怎么用,拆硬盘螺丝刀怎么用视频
- 云记pdf删除了怎么找回,云记app导入pdf
- go语言从入门到高级13 go语言技巧
- 怎么把硬盘设置主分区的简单介绍
- 视频号发布后怎么编辑,视频号怎么发布的
- 写java初级代码 java入门程序代码
- 如何安排电商美工,电商美工的工作流程
- ChatGPT引爆全网,用了chatGPT没网了