我试图在twilio API的帮助下使用php发送短信。但是我在运行代码时遇到了一些错误。
我的代码
{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");
错误
警告:file_get_contents():SSL操作失败,代码为1. OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证在C:\ wamp \ www \ Pizza4U \ twilio \ Services \ Twilio \ HttpStream中失败。第62行的PHP
警告:file_get_contents():无法在第62行的C:\ wamp \ www \ Pizza4U \ twilio \ Services \ Twilio \ HttpStream.php中启用加密
有没有办法解决这个问题。谢谢
答案 0 :(得分:0)
要在测试时避免wampserver localhost上的SSL证书问题,请确保插入以下代码行:
CURLOPT_SSL_VERIFYPEER => false,
in
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,
);
在生产模式下删除该行。您托管的服务器将确保拥有正确的可信证书捆绑包。至少将此设置设置为false,localhost上的twilio应用程序将不会检查您的localhost是否有SSL证书。这样可以避免必须下载正确的证书并完全绕过问题。请参阅pflammer在https://github.com/twilio/twilio-php/issues/203发表的评论。