1

Twilio 新手使用测试帐户。我按照此处列出的说明安装 Twilio php: https ://www.twilio.com/docs/quickstart/php/sms

因为我收到证书错误,所以我的主机提供商建议我更改 CURLOPT_SSL_VERIFYPEER => false(从 true)。但现在我收到了这个错误。如何修复?:致命错误:未捕获的异常“Services_Twilio_RestException”与消息“未找到请求的资源/2010-04-01/Accounts//Messages.json”

require "Services/Twilio.php";

// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "ACbxxxxxxx";
$AuthToken = "0cfxxxxxxx";

// Step 3: instantiate a new Twilio Rest Client
//$client = new Services_Twilio($AccountSid, $AuthToken);
    $http = new Services_Twilio_TinyHttp(
        'https://api.twilio.com',
        array('curlopts' => array(
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => 2,
        ))
    );

    $client = new Services_Twilio($sid, $token, "2010-04-01", $http);

// 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(
    "+13121111111" => "Curious George",
//  "+14158675311" => "Virgil",
);

// 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->sendMessage(

    // Step 6: Change the 'From' number below to be a valid Twilio number 
    // that you've purchased, or the (deprecated) Sandbox number
        "929-xxx-xxxx", 

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

        // the sms body
        "Hey $name, Monkey Party at 6PM. Bring Bananas!"
    );

    // Display a confirmation message on the screen
    echo "Sent message to $name";
}
4

1 回答 1

0

Twilio 开发人员布道者在这里。

首先,你不应该CURLOPT_SSL_VERIFYPEER在生产中设置为 false 。从卷曲手册

警告:禁用证书验证允许坏人在你不知情的情况下进行通信。禁用验证会使通信不安全。仅对传输进行加密是不够的,因为您无法确定您正在与正确的端点进行通信。

为了让您使用 Twilio,尽管您的问题在于您正在使用的变量名。

在您设置的文件顶部:

$AccountSid = "ACbxxxxxxx";
$AuthToken = "0cfxxxxxxx";

但是,当您创建 Twilio 时,您使用$sid$token.

$client = new Services_Twilio($sid, $token, "2010-04-01", $http);

如果您将其更改为$AccountSid$AuthToken它应该可以按预期工作。

于 2015-10-23T16:05:51.877 回答