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

问题描述 投票:0回答:1

Twilio告诉我Error - 52182 Messaging Service not specified,所以我显然不明白如果具体,如果,即使我以为我做了。 Twilio调试器的主体说Messaging service SID must be specified

到目前为止,我还没有找到任何有助于堆叠的东西,所以我正在追问一个问题。 Twilio文档也是如此。

$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
    ]);

我以为我在这里指定服务sid $twilio->notify->services($service->sid),但显然我不是。

以前我会在循环中一次发送一条短信,但由于订阅者名单不断增加而超时。

谢谢你对此有所了解。

php twilio
1个回答
0
投票

我在youtube上找到了这个指南:https://www.youtube.com/watch?v=EMOYY58jyKk似乎解决了我的问题,它不适用于PHP,但步骤几乎相同。

无论如何,我的最终代码最终都是这样的

$notifySid = 'ISxxxx';

// Bulk send the SMS
$notification = $twilio->notify->v1->services($notifySid)
    ->notifications->create([
        "toBinding" => $recipients,
        "body" => $body
    ]);
© www.soinside.com 2019 - 2024. All rights reserved.