我正在使用twilio發送批量短信。假設有些客戶認爲他們不想再收到消息,所以他們回覆「停止」,並將其添加到黑名單中。我很難編碼電話號碼,因爲我仍然在自己的手機上進行測試。我注意到,當我沒有從我的代碼中刪除黑名單上的數字時,我收到一條錯誤消息,並且我的腳本停止在該點。Twilio黑名單規則致命錯誤
將來,我可能會使用存儲在數據庫或文件中的數字。在那種情況下,如果發生這種情況,我該如何克服這個問題。基本上我想要做的是:如果一個號碼在黑名單中,轉到下一個號碼,並避免使用異常或類似的錯誤。 錯誤消息和代碼如下。
謝謝,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Send SMS</title>
<?php
/* Send an SMS using Twilio. You can run this file 3 different ways:
*
* 1. Save it as sendnotifications.php and at the command line, run
* php sendnotifications.php
*
* 2. Upload it to a web host and load mywebhost.com/sendnotifications.php
* in a web browser.
*
* 3. Download a local server like WAMP, MAMP or XAMPP. Point the web root
* directory to the folder containing this file, and load
* localhost:8888/sendnotifications.php in a web browser.
*/
// Step 1: Get the Twilio-PHP library from twilio.com/docs/libraries/php,
// following the instructions to install it with Composer.
//require_once "vendor/autoload.php";
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
use Twilio\Rest\Client;
// Step 2: set our AccountSid and AuthToken from https://twilio.com/console
$AccountSid = "something";
$AuthToken = "something";
// Step 3: instantiate a new Twilio Rest Client
$client = new Client($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"+1757" => "Chris",
"+17571234568" => "Hussam"
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->create(
// the number we are sending to - Any phone number
$number,
array(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased
'from' => "+184444444444",
// the sms body
'body' => "Hey $name, this is Hussam. Testing Twilio SMS API!"
)
);
// Display a confirmation message on the screen
echo "Sent message to $name.\n";
}
?>
嚴重錯誤(!):未捕獲的異常 'Twilio \例外\ RestException' 與消息「[HTTP 400]無法創建記錄:消息從/到對違反了黑名單規則「。在第86行(!)Twilio \ Exceptions \ RestException:[HTTP 400]中的C:\ wamp64 \ www \ Twilio \ twilio-php-master \ Twilio \ Version.php無法創建記錄:郵件從/到對違反了黑名單規則。在C:\ wamp64 \ WWW \ Twilio \ twilio-PHP-主\ Twilio \ Version.php上線86調用堆棧
太棒了!有效!!謝謝.. –
沒問題!祝好運與您的其他應用程序! – philnash
你在開玩笑嗎?當某人被列入黑名單時,爲什麼你會崩潰?你不能只是返回一個錯誤代碼?這是非常不專業的。 –