无法使用nexmo或thilio发送短信

我正在尝试使用java发送短信,为此我首先尝试了thilio.But然后我得到了底部提到的错误。然后我下载,在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() + " ] ...");
        }
    }

}

错误如下

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);


你为什么试图使用库? 只要您知道承运人,您通常可以通过电子邮件发送短信。 通常是number@carrier.com或类似的东西。

以下是一个包​​含运营商地址列表的网站:http://20somethingfinance.com/how-to-send-text-messages-sms-via-email-for-free/


它看起来像你正在使用的Nexmo库有一个你没有复制的外部依赖。

从Nexmo图书馆文档页面:

安装

您需要将nexmo-sdk.jar复制到您的应用程序并确保它在您的类路径中。 另外,/ lib目录下还有一些库依赖项,如果它们不在那里,还必须复制到应用程序类路径中。

因此,请查看您下载的SDK zipfile的/lib目录,并将这些文件复制到nexmo-sdk.jar

链接地址: http://www.djcxy.com/p/5647.html

上一篇: unable to send sms using nexmo or thilio

下一篇: Use Browserify and Uglify with Babelify