我試圖發送短信使用Java和爲此,我第一次嘗試與thilio.But我得到的錯誤,提到底部。然後我下載,在nexmo中創建一個帳戶,但又我得到了同樣的錯誤。請那些已經在上面兩個人工作過的人告訴我爲什麼會出現這個問題。無法發送短信使用nexmo或thilio
import com.nexmo.messaging.sdk.NexmoSmsClient;
import com.nexmo.messaging.sdk.SmsSubmissionResult;
import com.nexmo.messaging.sdk.messages.TextMessage;
public class SendTextMessage {
public static final String API_KEY = "apikey";
public static final String API_SECRET = "apisecret";
public static final String SMS_FROM = "singapore_number";// as i use my office number so can not disclose it
public static final String SMS_TO = "singapre_number";
public static final String SMS_TEXT = "Hello World!";
public static void main(String[] args) {
// Create a client for submitting to Nexmo
NexmoSmsClient client = null;
try {
client = new NexmoSmsClient(API_KEY, API_SECRET);
} catch (Exception e) {
System.err.println("Failed to instanciate a Nexmo Client");
e.printStackTrace();
throw new RuntimeException("Failed to instanciate a Nexmo Client");
}
// Create a Text SMS Message request object ...
TextMessage message = new TextMessage(SMS_FROM, SMS_TO, SMS_TEXT);
// Use the Nexmo client to submit the Text Message ...
SmsSubmissionResult[] results = null;
try {
results = client.submitMessage(message);
} catch (Exception e) {
System.err.println("Failed to communicate with the Nexmo Client");
e.printStackTrace();
throw new RuntimeException("Failed to communicate with the Nexmo Client");
}
// Evaluate the results of the submission attempt ...
System.out.println("... Message submitted in [ " + results.length + " ] parts");
for (int i=0;i<results.length;i++) {
System.out.println("--------- part [ " + (i + 1) + " ] ------------");
System.out.println("Status [ " + results[i].getStatus() + " ] ...");
if (results[i].getStatus() == SmsSubmissionResult.STATUS_OK)
System.out.println("SUCCESS");
else if (results[i].getTemporaryError())
System.out.println("TEMPORARY FAILURE - PLEASE RETRY");
else
System.out.println("SUBMISSION FAILED!");
System.out.println("Message-Id [ " + results[i].getMessageId() + " ] ...");
System.out.println("Error-Text [ " + results[i].getErrorText() + " ] ...");
if (results[i].getMessagePrice() != null)
System.out.println("Message-Price [ " + results[i].getMessagePrice() + " ] ...");
if (results[i].getRemainingBalance() != null)
System.out.println("Remaining-Balance [ " + results[i].getRemainingBalance() + " ] ...");
}
}
}
錯誤如下
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
at SendTextMessage.main(SendTextMessage.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
第32行表示該線 客戶=新NexmoSmsClient(API_KEY,API_SECRET);
我想從網頁上發送短信application.So請告訴我如何做? – SpringLearner
有許多原因使用專用的API而不是SMS電子郵件網關。關閉我的頭頂:通過電子郵件網關發送的消息通常不能可靠傳送,您無法使用電子郵件網關接收傳入的SMS消息。 –