用短信方式发送到用户手机上的代码怎么写啊?
我想做一个学校老师发布作业,同时以短信方式将作业发送到学生家长手机上的功能,这该如何做啊?
----------------解决方案--------------------------------------------------------
是J2ME的吗?J2ME不清楚,之前做过和移动的接口,由他们来发送。
----------------解决方案--------------------------------------------------------
用java做的
----------------解决方案--------------------------------------------------------
package com.fetion.test;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
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;
/**
* API2.1调用:f.php?phone=xxxxxx&pwd=xxx&to=xxxx&msg=xxxx&type=0
*以上接口参数详细说明 VIP API
*1.phone:手机号
*2.pwd:飞信密码
*3.to:发送给谁(手机号或飞信号)
*4.msg:飞信内容
*5.type:操作 0(空)发送短信 1检查好友 2添加好友
*6.u:备用参数:当发送内容为乱码时 在最后加上&u=1
*/
public class Fetion {
//自己的手机号
private static String PHONE = "";
//自己的飞信密码
private static String PWD = "";
//对方的手机号
private static String TO = "";
//
private static String configuration;
private Properties config = new Properties();
public Fetion(){
init();
}
//初始化配置文件
public void init(){
try {
InputStream is = new FileInputStream("FetionConfig");
config.load(new InputStreamReader(is));
configuration=config.getProperty("WeekendGreetings");
System.out.println(configuration);
PHONE=config.getProperty("phone");
PWD=config.getProperty("pwd");
TO=config.getProperty("to");
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void sendMsg(String _phone,String _pwd,String _to,String _msg) throws HttpException, IOException{
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://3.ibtf.sinaapp.com/f.php");
post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
NameValuePair[] data ={
new NameValuePair("phone", _phone),
new NameValuePair("pwd", _pwd),
new NameValuePair("to",_to),
new NameValuePair("msg",_msg),
new NameValuePair("type","0")
};
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);
System.out.println("ok!");
post.releaseConnection();
}
public void start(){
try {
FileReader fr = new FileReader(configuration);
BufferedReader br = new BufferedReader(fr);
String MSG=null;
while ((MSG=br.readLine())!=null) {
Fetion.sendMsg(PHONE, PWD, TO, MSG);
}
br.close();
fr.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Fetion f = new Fetion();
f.start();
}
}
----------------解决方案--------------------------------------------------------
表示着我就不懂了。来学习的
----------------解决方案--------------------------------------------------------
围观下,提好的
----------------解决方案--------------------------------------------------------
回复 4楼 feast_king
谢了 ----------------解决方案--------------------------------------------------------
围观中
----------------解决方案--------------------------------------------------------
这个需要接口程序 你可以先试试 飞信的接口 发送短信 其实挺简单的
----------------解决方案--------------------------------------------------------
确实挺厉害的
----------------解决方案--------------------------------------------------------