我在下面有以下php文件。当我从终端运行它时,效果很好。但是,当我在浏览器中打开php文件时,我得到以下异常:
致命错误:未捕获的异常'Twilio \ Exceptions \ EnvironmentException',并在/Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Http/CurlClient.php中显示消息“SSL证书问题:无法获取本地颁发者证书” :41堆栈跟踪:#0 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Rest/Client.php(208):Twilio \ Http \ CurlClient-> request('POST','{{3} } ...',Array,Array,Array,'AC9fc89840f15b3 ...','d1db324eb375a2e ...',NULL)#1 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Domain.php(70 ):Twilio \ Rest \ Client-> request('POST','https://api.twi ...',数组,数组,数组,NULL,NULL,NULL)#2 / Applications / AMPPS / www / vendor / twilio / sdk / Twilio / Version.php(64):Twilio \ Domain-> request('POST','2010-04-01 / Acco ...',Array,Array,Array,NULL,NULL,NULL) #3 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Version.php(216):Twilio \ Version-> request('POST','/ Accounts / AC9fc ...',Array,Array,数组,NULL,NULL,NULL)#4 / Applications / AMPPS / www / vendor / twilio / sdk / Twilio / Rest / Api / V2010 / Ac count / MessageList.php(70):第41行/Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Http/CurlClient.php中的twili
这是我的代码:
<?php // sendMessageTwilio.php
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$account_sid = 'XXXXXXXXXX';
$auth_token = 'XXXXXXXXXX';
// In production, these should be environment variables. E.g.:
// $auth_token = $_ENV["TWILIO_ACCOUNT_SID"]
// A Twilio number you own with SMS capabilities
$twilio_number = "+XXXXXXXX";
$client = new Client($account_sid, $auth_token);
$client->messages->create(
// Where to send a text message (your cell phone?)
'+XXXXXXXXXXX',
array(
'from' => $twilio_number,
'body' => 'Testing From Website New!'
)
);
$number = $question = '';
if (isset($_POST['number'])){
$number = $_POST['number'];
$out = "Number: $number";
}
if (isset($_POST['question'])){
$question = $_POST['question'];
$out = $out." Question: $question";
}
else $out = "";
echo <<<_END
<html>
<head>
<title>Student Feedback</title>
</head>
<body>
<pre>
Enter phone number and question
<b>$out</b>
<form method="post" action="sendMessageTwilio.php">
Phone Number: <input type="text" name="number" size="17">
Question: <input type="text" name="question" size="17">
<input type="submit" value="Send Message">
</form>
</pre>
</body>
</html>
_END;
我正在使用作曲家来设置所有必要的文件。
全部谢谢!
答案 0 :(得分:1)
Linux服务器通常具有ca_cert.pem。请按照以下步骤解决问题
<强>更新强>
这是我的代码
$http = new Services_Twilio_TinyHttp(
'https://api.twilio.com',
array('curlopts' => array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2,
))
);
$sid = 'ACfb185500bf13ce37c37fd2e13dsdfsdf';
$token = '4be5dcdb74e4cbd50d642a56b1fasdf2';
$client = new Services_Twilio($sid, $token, "2010-04-01", $http);
$message = $client->account->messages->sendMessage(
'+441231231231', // From a Twilio number in your account
'+441231231231,
'OTP for login is: 1234'
);
您需要设置curl选项以禁止SSL验证
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2,