【问题标题】:twilio Uncaught exception errortwilio 未捕获的异常错误
【发布时间】:2015-10-23 15:58:06
【问题描述】:

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";
}

【问题讨论】:

    标签: twilio twilio-php


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    首先,您不应该在生产环境中将 CURLOPT_SSL_VERIFYPEER 设置为 false。来自curl manual:

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

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

    在您设置的文件的顶部:

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

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

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

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

    【讨论】:

    • philnash,修复成功了!作为一个新手,我想我对所有新信息感到不知所措,我没有看到这个非常简单的错误。
    • 另外,我将创建新的 stackoverflow 帖子来讨论这个证书问题。
    • 很高兴它现在可以工作了!我们过去都犯过这样的错误!您可能想查看有关 SSL 错误的常见问题解答,看看是否有任何修复对您有帮助:github.com/twilio/twilio-php/blob/master/docs/…
    猜你喜欢
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多