尝试使用twilio发送消息时出现致命错误

时间:2016-10-15 06:43:34

标签: php twilio

我使用twilio工作了2个小时仍然无法解决这个致命的错误

Fatal error: Uncaught exception 'Twilio\Exceptions\RestException' with message '[HTTP 400] Unable to create record' in /membri/deathcrow/server/sms/twilio-php-master/Twilio/Version.php:87 Stack trace: #0 /membri/deathcrow/server/sms/twilio-php-master/Twilio/Version.php(207): Twilio\Version->exception(Object(Twilio\Http\Response), 'Unable to creat...') #1 /membri/deathcrow/server/sms/twilio-php-master/Twilio/Rest/Api/V2010/Account/MessageList.php(63): Twilio\Version->create('POST', '/Accounts/ACa81...', Array, Array) #2 /membri/deathcrow/server/sms/que.php(25): Twilio\Rest\Api\V2010\Account\MessageList->create(Array) #3 {main} thrown in /membri/deathcrow/server/sms/twilio-php-master/Twilio/Version.php on line 87

这是我的整页编码我出于安全原因隐藏了sid,令牌和数字

<?
 require_once ("../connect.php");
 require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
 use Twilio\Rest\Client;
 ignore_user_abort (true);
 $sql = "SELECT * FROM smsque ORDER BY id ASC LIMIT 1";
 $query = mysql_query ($sql);
 $row = mysql_fetch_object ($query);

 $id = $row->id;
 $msg = $row->message;
 $amount = $row->amount;
 $reciever = $row->reciever;

 $headers = 'From: noReply@anon.com';

// Your Account SID and Auth Token from twilio.com/console
$sid = '******************';
$token = '*************';

$client = new Client($sid, $token);
$client->account->messages->create(array(
  "From" => "**********",
  "To" => "*******",
  "Body" => "Test!"));

    //mail ($to, '', $msg, $headers);

 $amount--;

 if ($amount >= 1){
  $sql2 = "UPDATE smsque SET amount='$amount' WHERE id='$id'";
  $query2 = mysql_query ($sql2);
 }else {
    $sql2 = "DELETE from smsque WHERE id='$id'";
     $query2 = mysql_query ($sql2);
 }
?>

1 个答案:

答案 0 :(得分:0)

您的函数调用似乎不正确。要发送短信“to”数字是“create()”中的第一个参数,请参阅下面的通用调用

$sms = $client->account->messages->create(

    // the number we are sending to - Any phone number
    $number,

    array(
        // Change the 'From' number below to be a valid Twilio number 
        // that you've purchased
        'from' => "+**********", 
        // the sms body
        'body' => "the sms body here "
    )
);

所以你的代码应该与下面的代码相似

<?
 require_once ("../connect.php");
 require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
 use Twilio\Rest\Client;
 ignore_user_abort (true);
 $sql = "SELECT * FROM smsque ORDER BY id ASC LIMIT 1";
 $query = mysql_query ($sql);
 $row = mysql_fetch_object ($query);

 $id = $row->id;
 $msg = $row->message;
 $amount = $row->amount;
 $reciever = $row->reciever;

 $headers = 'From: noReply@anon.com';

// Your Account SID and Auth Token from twilio.com/console
$sid = '******************';
$token = '*************';

$client = new Client($sid, $token);
$client->account->messages->create( $reciever , 
        array(
                "From" => "**********",
                "Body" => "Test!"));

    //mail ($to, '', $msg, $headers);

 $amount--;

 if ($amount >= 1){
  $sql2 = "UPDATE smsque SET amount='$amount' WHERE id='$id'";
  $query2 = mysql_query ($sql2);
 }else {
    $sql2 = "DELETE from smsque WHERE id='$id'";
     $query2 = mysql_query ($sql2);
 }
?>

您可以阅读更多here

相关问题