dongzhang3482 2019-04-23 15:36
浏览 470
已采纳

无法使用Twilio批量发送短信(错误52182)

Twilio tells me Error - 52182 Messaging Service not specified, so I obviously don't understand how to specificy if, even though I thought I did. The body of the Twilio debugger says Messaging service SID must be specified

I've not found anything that has helped so far on stack, so I'm chancing a question. The same goes for the Twilio docs.

$recipients = [];

foreach ($userIds as $userId) {
    $user = Craft::$app->users->getUserById($userId);

    $number = !empty($user->mobil);

    if ($number) {
        try {
            $number = $twilio->lookups->v1->phoneNumbers($user->mobil)->fetch(['countryCode' => 'NO'])->phoneNumber;
            $recipients[] = '{"binding_type":"sms", "address":"'.$number.'"}';
        } catch (\Exception $e) {
            continue;
        }
    }
}

$twilio = new Client('xxx', 'xxx');

$service = $twilio->notify->v1->services->create();

$twilio->notify->services($service->sid)
    ->notifications->create([
        "toBinding" => $recipients,
        "body" => $body
    ]);

I thought I was specifying the service sid here $twilio->notify->services($service->sid), but apparently I'm not.

Previously I would send one SMS at a time in a loop, but that times out due to a growing list of subscribers.

Thank you for shedding any light on this.

  • 写回答

1条回答 默认 最新

  • dongxuan2577 2019-04-25 10:39
    关注

    I found this guide on youtube: https://www.youtube.com/watch?v=EMOYY58jyKk which seems to have solved my issues, it's not for PHP but the steps were pretty much the same.

    In any case, my final code ended up like so

    $notifySid = 'ISxxxx';
    
    // Bulk send the SMS
    $notification = $twilio->notify->v1->services($notifySid)
        ->notifications->create([
            "toBinding" => $recipients,
            "body" => $body
        ]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?