Twilio新手使用测试帐号。我按照此处列出的说明安装Twilio php: https://www.twilio.com/docs/quickstart/php/sms
因为我收到证书错误,我的主机提供商建议我更改了CURLOPT_SSL_VERIFYPEER =>假(来自真实)。但现在我收到了这个错误。怎么修?: 致命错误:未捕获异常'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";
}
答案 0 :(得分:0)
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
,则应该按预期工作。