简体   繁体   English

使用twilio错误时无法发送短信

[英]Can't send sms using twilio error occured

I tried to send sms using php with the help of twilio API. 我试图在twilio API的帮助下使用php发送短信。 But I have occeured fallowing errors when running code. 但是我在运行代码时遇到了一些错误。

my code 我的代码

{require ('./twilio/Services/Twilio.php'); // Loads the library


$accountSid = 'AC****************************';
$authToken  = 'ec****************************'; 
$client = new Services_Twilio($accountSid, $authToken);

$sms = $client->account->sms_messages->create("number", "number", "Jenny please?! I love you <3");

errors 错误

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in C:\\wamp\\www\\Pizza4U\\twilio\\Services\\Twilio\\HttpStream.php on line 62 警告:file_get_contents():SSL操作失败,代码为1. OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证在C:\\ wamp \\ www \\ Pizza4U \\ twilio \\ Services \\ Twilio \\ HttpStream.php中失败62

Warning: file_get_contents(): Failed to enable crypto in C:\\wamp\\www\\Pizza4U\\twilio\\Services\\Twilio\\HttpStream.php on line 62 警告:file_get_contents():无法在第62行的C:\\ wamp \\ www \\ Pizza4U \\ twilio \\ Services \\ Twilio \\ HttpStream.php中启用加密

Is there a way to fix this. 有没有办法解决这个问题。 Thank you 谢谢

To avoid SSL certificate issues on wampserver localhost whilst testing, make sure that you insert the following line of code: 要在测试时避免wampserver localhost上的SSL证书问题,请确保插入以下代码行:

CURLOPT_SSL_VERIFYPEER => false,

in

twilio/sdk/Twilio/Http/CurlClient.php (from line 113 onwards) twilio / sdk / Twilio / Http / CurlClient.php(从第113行开始)

public function options($method, $url, $params = array(), $data = array(),
                        $headers = array(), $user = null, $password = null,
                        $timeout = null) {

    $timeout = is_null($timeout)
        ? self::DEFAULT_TIMEOUT
        : $timeout;
    $options = $this->curlOptions + array(
        CURLOPT_URL => $url,
        CURLOPT_HEADER => true,
        CURLOPT_RETURNTRANSFER => true,
        //added here during localhost wampserver testing to avoid SSL issues
        //CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_INFILESIZE => Null,
        CURLOPT_HTTPHEADER => array(),
        CURLOPT_TIMEOUT => $timeout,
    );

Remove the line once you are in production mode. 在生产模式下删除该行。 The server that you are hosted on will I'm sure have the correct bundle of trusted certificates. 您托管的服务器我肯定会拥有正确的可信证书包。 At least with this setting set to false, your twilio application on localhost will not be checking your localhost for SSL certificates. 至少将此设置设置为false,localhost上的twilio应用程序将不会检查您的localhost是否有SSL证书。 This avoids having to download the correct certificates and bypasses the issues completely. 这样可以避免必须下载正确的证书并完全绕过问题。 See pflammer's comment at https://github.com/twilio/twilio-php/issues/203 . 请参阅https://github.com/twilio/twilio-php/issues/203上的 pflammer的评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM