jms

来源:互联网 发布:斗鱼主播用的唱歌软件 编辑:程序博客网 时间:2024/04/29 23:41
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); } } 用户名,即企业代码: $user_id 密码:$password 接收短信的手机号(如果是多个手机号,用逗号分开,最多100个):$mobile_phone 要发送的短信内容:$msg 定时发送时间(格式为:年月日时分秒“040524165823”,如果即时发送置为空):$send_date 子特服号(与企业代码相同):$subCode