如何使用Twilio Java SDK发送批量短信?

kulphzqa  于 2023-01-11  发布在  Java
关注(0)|答案(3)|浏览(294)

我已经找到了大量的信息,关于如何发送大量的短信与JS,Python,PHP SDK,但没有关于如何实现这一点使用Java
下面是一段代码片段,演示了Python的实现。

from twilio.rest import Client

account = "AC98e9a2817c2e0b4d38b42d1445ef42d9"
token = "your_auth_token"
client = Client(account, token)

notification = client.notify.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")\
   .notifications.create(
    to_binding=[
        "{\"binding_type\":\"sms\",\"address\":\"+15555555555\"}",
        "{\"binding_type\":\"facebook-messenger\",\"address\":\"123456789123\"}"
    ],
    body="Hello Bob")
rlcwz9us

rlcwz9us1#

Twilio开发人员传道者在这里。
有一个sending bulk SMS messages with Java in the documentation for Twilio Notify的例子。
下面是一个例子:

import java.util.Arrays;
import java.util.List;
import com.twilio.Twilio;
import com.twilio.rest.notify.v1.service.Notification;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static final String SERVICE_SID = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

  public static void main(String[] args) {
    // Initialize the client
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    List<String> toBindings = Arrays.asList(
    "{\"binding_type\":\"sms\",\"address\":\"+15555555555\"}",
    "{\"binding_type\":\"facebook-messenger\",\"address\":\"123456789123\"}");

    Notification notification = Notification
        .creator(SERVICE_SID)
        .setBody("Hello Bob")
        .setToBinding(toBindings)
        .create();

    System.out.println(notification.getSid());
  }
}
fhg3lkii

fhg3lkii2#

下面是如何在java中做到这一点的官方指南:
https://www.twilio.com/docs/libraries/java

i86rm4rw

i86rm4rw3#

Twilio开发人员传道者在这里。你可以从这里开始免费的学分,应该持续你一个月或两个月,如果你用它为个人使用。https://www.twilio.com/try-twilio
有关使用试用帐户的更多详细信息,请单击此处:https://www.twilio.com/docs/usage/tutorials/how-to-use-your-free-trial-account

相关问题