dongniaocheng3773 2017-09-21 15:27
浏览 168
已采纳

使用PHP通过Twilio Rest API发送批量短信

I am using Twilio PHP Library, and i want to send SMS messages to a big list of people using Twilio PHP REST API. I have a text file, that contains the list of unique phone numbers (approx 1000 members).

Currently my plan was to create a cron job, which parses the text file, and makes a REST API call for each of the phone numbers in the file.

Ex:

<?php
require_once 'vendor/autoload.php';
use Twilio\Rest\Client;
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
$client = new Client($sid, $token);

$sms_sent = $client->messages->create(
    '+1xxxxxxxxxx',
    array(
        'from' => '+1xxxxxxxxxx',
        'body' => "XXXXXX XXXXXX",
        'statusCallback' => "http://myapplication_callback_url"
    )
);

But i wanted to know, whether Twilio can do the job for me (like i will upload the text file to Twilio, and Twilio will process the file and send SMS to each number in it).

Is there any option like this with Twilio? I have read about the BULK SMS option here, but that seems like it sends out a static message to all the users. I need to send unique message to each user. How is this possible with Twilio? Please let me know.

EDIT: 27-09-2017: I have heard about Twilio COPILOT, but not sure how to use that service.

  • 写回答

3条回答 默认 最新

  • duannue2455 2017-09-28 12:39
    关注

    Twilio developer evangelist here.

    Just to distill your problem, you need to send about 1000 unique messages to users, right?

    If that's the case, then this is what you need to do.

    Since the message is unique to each number, you need to make an API call to the Twilio REST API to send each message individually. Twilio caps the message sending at 1 message per number per second. If you are already over this limit, then Twilio will queue those messages up for you. It should not take 5 seconds per API call.

    This is the case if you use one number, like in your original example. For 1000 messages it will take almost 17 minutes to send them all.

    However, you can use a messaging service to speed this up. A messaging service is a pool of numbers and other services provided by Copilot (including geo matching numbers, alphanumeric sender fallback and other such things). For sending a lot of messages, like in this case, the number pool is the important part because each Twilio number you are sending from can send 1 message per second. So if you add 2 numbers to the messaging service you can send 2 messages per second, if you add 10 numbers to the pool you can send 10 a second.

    To send messages using a messaging service and number pool, like this, you need to create a messaging service in your Twilio console. Add or buy numbers for the pool. Then, get the messaging service SID:

    Find the messaging service SID in your Twilio console where you created the service.

    You can then use the messaging service SID in place of the from number in your call to the API.

    $sms_sent = $client->messages->create(
        '+1xxxxxxxxxx',
        array(
            'from' => 'MESSAGING SERVICE SID',
            'body' => "XXXXXX XXXXXX",
            'statusCallback' => "http://myapplication_callback_url"
        )
    );
    

    Then your messages will be fanned out by the messaging service.

    Notably, if you need to send 1000 messages in a day, we recommend you spread that out over at least 4 numbers as US carriers start to block long code numbers that are used more than that. Check out more in our guidelines for sending SMS messages to the US.

    Let me know if that helps at all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?
  • ¥15 C#连接不上服务器,