我试图获得NexmoClient对象,但没有成功。
我用从Nexmo仪表板复制的值填写API_KEY和API_SECRET。
import com.nexmo.client.NexmoClient;
import com.nexmo.client.auth.AuthMethod;
import com.nexmo.client.auth.TokenAuthMethod;
import com.nexmo.client.sms.SmsSubmissionResult;
import com.nexmo.client.sms.messages.TextMessage;
public class SendSMS {
public static void main(String[] args) throws Exception {
AuthMethod auth = new TokenAuthMethod(1111,22222);
NexmoClient client = new NexmoClient(auth);
}
} ” 在Gradle运行之后,我应该像他们在文档https://www.nexmo.com/blog/2017/05/03/send-sms-messages-with-java-dr/中所写的那样,使用NexmoClient对象 继续下一步,但是我不知道在哪里插入以下信息
TextMessage message = new TextMessage(FROM_NUMBER, TO_NUMBER, "Hello from
Nexmo!");
SmsSubmissionResult[] responses =
client.getSmsClient().submitMessage(message);
for (SmsSubmissionResult response : responses) {
System.out.println(response);
}
答案 0 :(得分:0)
您可以将该代码放在初始化客户端的下面。您的整个班级将如下所示:
import com.nexmo.client.NexmoClient;
import com.nexmo.client.auth.AuthMethod;
import com.nexmo.client.auth.TokenAuthMethod;
import com.nexmo.client.sms.messages.TextMessage;
public class SendSMS {
private static final String FROM_NUMBER = "";
private static final String TO_NUMBER = "";
public static void main(String[] args) throws Exception {
AuthMethod auth = new TokenAuthMethod(1111, 22222);
NexmoClient client = new NexmoClient(auth);
TextMessage message = new TextMessage(FROM_NUMBER, TO_NUMBER, "Hello from Nexmo !");
SmsSubmissionResult[] responses = client.getSmsClient().submitMessage(message);
for (SmsSubmissionResult response : responses) {
System.out.println(response);
}
}
}
此博客文章实际上有点老,建议使用服务器SDK的旧版本。开发者门户网站上有一个更新的示例,因为新版本的SDK中发生了一些更改:https://developer.nexmo.com/messaging/sms/code-snippets/send-an-sms