我在下面有以下php文件。当我从终端运行它时,它工作得很好。但是,当我在浏览器中打开php文件时,我得到以下异常:
致命错误:未捕获的异常'Twilio\Exceptions\环境异常'在 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Http/CurlClient.php中带有消息'SSL证书问题:无法获得本地颁发者证书': 41 Stack trace:#0 /Applications/AMPPS/www/vendor/twilio/sdk/Twilio/Rest/Client.php(208):Twilio\Http\CurlClient-
这是我的代码:
<?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;
我正在使用作曲家来设置所有必要的文件。
谢谢大家!
Linux服务器通常有ca_cert. pem
https://support.twilio.com/hc/en-us/articles/235279367-Twilio-PHP-helper-library-SSL-certificate-problem-on-Windows
更新
这是我的代码
$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,