我如何发送不止一条消息?

时间:2019-07-11 18:43:05

标签: java nexmo

我想开发一个简单的应用程序,使我能够向多个号码发送短信 和几个数字。

在下面的代码中,我从5555发送到6666。例如,我也想从7777发送到8888。

我需要在代码中添加什么?

同时,我尝试复制TextMessage消息,但没有成功。

package getstarted;

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("xxxxx","yyyy");
        NexmoClient client = new NexmoClient(auth);

        TextMessage message = new TextMessage("5555", "6666", "Hello from Nexmo!");
        SmsSubmissionResult[] responses = client.getSmsClient().submitMessage(message);

        for (SmsSubmissionResult response : responses) {
            System.out.println(response);
        }
    }
}

1 个答案:

答案 0 :(得分:2)

只需实例化另一个TextMessage

TextMessage message2 = new TextMessage("7777", "8888", "Hello from Nexmo!");
SmsSubmissionResult[] responses2 = client.getSmsClient().submitMessage(message2);

for (SmsSubmissionResult response : responses2) {
    System.out.println(response);
}