要先註冊才可以使用喔 ! 因為程式碼會需要你打帳密...
話說這個要錢,不過發顯訊本來就要錢...所以...
廠商 BulkSMS:
// 官方網站:http://www.bulksms.com/
// API 可參考 : http://developer.bulksms.com/eapi/
package server;
import java.net.*;
import java.io.*;
public class NewClass {
public static void main(String[] args) {
try {
// Construct data
String data = "";
data += "username=" + URLEncoder.encode("abcd1234", "ISO-8859-1"); // 輸入帳號
data += "&password=" + URLEncoder.encode("abcd1234", "ISO-8859-1"); // 輸入密碼
data += "&message=" + URLEncoder.encode("I Love Loli", "ISO-8859-1"); // 輸入訊息 (ASCII)
data += "&want_report=1";
data += "&msisdn=+886912345678"; // 輸入手機號碼 (前面要加上國碼)
// Send data
// Please see the FAQ regarding HTTPS (port 443) and HTTP (port 80/5567)
URL url = new URL("https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0");
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) {
// Print the response output...
System.out.println(line);
}
wr.close();
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
廠商 nexmo:
// 官方網站:https://www.nexmo.com/
package server;
import java.net.*;
import java.io.*;
public class NewClass {
public static void main(String[] args) {
try {
// Construct data
String data = "";
data += "api_key=<鑰匙,每個人都不同>";
data += "&api_secret=<秘密,每個人不同>";
data += "&from=NEXMO";
data += "&to=886912345678";
data += "&type=unicode";
data += "&text=" + URLEncoder.encode("銘言:沒有蘿莉,沒有未來。", "utf-8");
System.out.println(data);
// Send data
// Please see the FAQ regarding HTTPS (port 443) and HTTP (port 80/5567)
URL url = new URL("https://rest.nexmo.com/sms/json");
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 json = rd.readLine();
System.out.println(json);
wr.close();
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
留言列表