如果没有我所做的 foreach,我如何批量发送给所有客户。我只想通过 1 条消息发送给所有人。
public function sendToMany(Request $request){ $number = getenv('TWILIO_NUMBER'); //Twilio's number $sid = getenv('TWILIO_ACCOUNT_SID');////////////////////// $token = getenv('TWILIO_AUTH_TOKEN'); // API credentials // $twilio = new Client($sid, $token); ////////////////////// $otp = $request->message;//message from the form $receiver = array("+xxxxxxxxxxxx", "+xxxxxxxxxxxx", "+xxxxxxxxxxxx"); foreach ($receiver as $receiver_number){ $message = $twilio->messages ->create("whatsapp:".$receiver_number, // to array( "from" => "whatsapp:".$number, "body" => $otp //message to send ) ); }//end of for loop }//end of method
没有用于使用 Twilio API 通过 WhatsApp 发送消息的批量 API。我们建议您循环遍历您的数字,就像您在此处所做的那样,或者循环遍历并排队独立发出 API 请求的后台作业。