[英]unable to send sms using nexmo or thilio
I was trying to send sms using java and for that I first tried with thilio.But I got error which is mentioned at the bottom.Then i downloaded,created an account in nexmo but again i get the same error.Please anybody those who had already worked on the above two can tell me why this issue come. 我试图使用Java发送短信,为此我首先尝试了thilio。但是我收到了底部提到的错误。然后我下载了该文件,并在nexmo中创建了一个帐户,但是我又遇到了同样的错误。已经在上面两个上工作过的可以告诉我为什么这个问题来了。
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() + " ] ...");
}
}
}
error is as follows 错误如下
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
Line 32 means this line client = new NexmoSmsClient(API_KEY, API_SECRET); 第32行表示此行客户端= new NexmoSmsClient(API_KEY,API_SECRET);
Why are you trying to use libraries? 为什么要尝试使用库? You can generally send SMS texts through email, as long as you know the carrier. 只要您知道运营商,通常就可以通过电子邮件发送SMS文本。 Usually it's number@carrier.com or something like that. 通常是number@carrier.com或类似的名称。
Here's a site with a list of carrier addresses: http://20somethingfinance.com/how-to-send-text-messages-sms-via-email-for-free/ 这是一个包含运营商地址列表的网站: http : //20somethingfinance.com/how-to-send-text-messages-sms-via-email-for-free/
It looks like the Nexmo lib you are using has an external dependency that you didn't copy over. 您正在使用的Nexmo库似乎具有未复制的外部依赖关系。
From the Nexmo library documentation page : 从Nexmo 库文档页面 :
Installation 安装
You need to copy the nexmo-sdk.jar to your application and ensure that it is in your classpath. 您需要将nexmo-sdk.jar复制到您的应用程序,并确保它在您的类路径中。 Additionally, there are some library dependencies under the /lib dir that must also be copied to your applications classpath if they are not already there. 此外,/ lib目录下还存在一些库依赖项,如果它们还不存在,则还必须将它们复制到应用程序的类路径中。
So, look in the /lib
directory of the SDK zipfile you downloaded, and copy those files wherever you put nexmo-sdk.jar 因此,请查看下载的SDK zip文件的/lib
目录,然后将这些文件复制到放置nexmo-sdk.jar的任何位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.