importjava.net.URLEncoder;importjava.net.URL;importjava.net.URLConnection;importjava.util.*;importjava.io.*;classhttp_post{publicStringsend_sms(Stringuser_id,Stringpasswo...
import java.net.URLEncoder;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import java.io.*;
class http_post
{
public String send_sms(String user_id, String password, String mobile_phone,
String msg, String send_date, String subcode) {
String ret_str = "";
try {
// Construct data
String data = "user_id=" + user_id + "&password=" + password +
"&mobile_phone=" + mobile_phone +
"&msg=" + URLEncoder.encode(msg, "GBK") + "&send_date=" + send_date +
"&subcode=" + subcode;
// Send data
URL url = new URL("http://bms.hichina.com/sms_gateway/sms_api");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.
getInputStream()));
String line;
while ( (line = rd.readLine()) != null) {
ret_str += line;
}
wr.close();
rd.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
return ret_str;
}
public static void main(String[] args) throws IOException
{
http_post http= new http_post();
String ret=http.send_sms("4003","xxxxxxx","13900000000","fromjava中国万岁","","4003");
System.out.println(ret);
}
}
对java发短信是一片空白,这个是网上找的一个代码,里面的第1,2和最后一个参数不明白什么意思,大概是我在信息中心的id和登陆密码?是这个意思吗?如果我想测试我该如何注册这个id和密码,各个地区的信息中心还不一样吧?北京的应该去那里注册?请高手帮我调通这个程序,谢谢
用户名,即企业代码: $user_id
密码:$password
接收短信的手机号(如果是多个手机号,用逗号分开,最多100个):$mobile_phone
要发送的短信内容:$msg
定时发送时间(格式为:年月日时分秒“040524165823”,如果即时发送置为空):$send_date
子特服号(与企业代码相同):$subCode
展开