twilio短信通过手机验证

时间:2015-02-25 11:57:15

标签: php sms twilio sms-gateway twilio-php

我测试了twilio sms代码,但我遇到了一些问题。该库可在https://www.twilio.com/docs/php/install找到。

以下是我使用的代码:

<?php

require "twilio-php/Services/Twilio.php";

// set your AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "*******";
$AuthToken = "*********";

$client = new Services_Twilio($AccountSid, $AuthToken);

$message = $client->account->messages->create(array(
"From" => "+14806669029",
"To" => "923331524145",
"Body" => "Test message!",
));

// Display a confirmation message on the screen
echo "Sent message {$message->sid}";

?>

运行时,会出现以下错误:

Fatal error: Uncaught exception 'Services_Twilio_TinyHttpException'
with message 'SSL certificate problem: self signed certificate in
certificate chain' in
C:\xampp\htdocs\sms\twilio-php\Services\Twilio\TinyHttp.php:119 Stack
trace: #0 C:\xampp\htdocs\sms\twilio-php\Services\Twilio.php(181):
Services_Twilio_TinyHttp->__call('post', Array) #1
C:\xampp\htdocs\sms\twilio-php\Services\Twilio.php(181):
Services_Twilio_TinyHttp->post('/2010-04-01/Acc...', Array,
'From=%2B1480666...') #2
C:\xampp\htdocs\sms\twilio-php\Services\Twilio\ListResource.php(92):
Base_Services_Twilio->createData('/2010-04-01/Acc...', Array) #3
C:\xampp\htdocs\sms\twilio-php\Services\Twilio\Rest\Messages.php(24):
Services_Twilio_ListResource->_create(Array) #4
C:\xampp\htdocs\sms\send-sms.php(15):
Services_Twilio_Rest_Messages->create(Array) #5 {main} thrown in
C:\xampp\htdocs\sms\twilio-php\Services\Twilio\TinyHttp.php on line
119

4 个答案:

答案 0 :(得分:0)

请参阅:https://github.com/twilio/twilio-php/blob/master/docs/faq.rst

它说:

SSL验证例外

如果您使用的是过时版本的libcurl,则可能会遇到SSL验证异常。如果您看到以下错误消息,则表示您有SSL验证异常:

Fatal error: Uncaught exception 'Services_Twilio_TinyHttpException'
with message 'SSL certificate problem, verify that the CA cert is OK.

Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate
verify failed' in [MY PATH]\Services\Twilio\TinyHttp.php:89

这意味着Twilio正在尝试提供证书以验证您是否实际连接到https://api.twilio.com,但您的curl客户端无法验证我们的证书。

答案 1 :(得分:0)

按照this link的skimbrel说明。然后从hairys评论中添加证书。你的问题应该解决了。

答案 2 :(得分:0)

我解决了从http://curl.haxx.se/docs/caextract.html下载cacert.pem并修改我的php.ini以包含下载文件的路径的问题(在我的情况下我将其复制到C:\ xampp \ php),添加了php.ini文件末尾的以下行:

curl.cainfo=c:\xampp\php\cacert.pem

保存文件并重新启动Apache后,错误消失了,我可以使用Twilio系统发送短信。

答案 3 :(得分:0)

第1步:下载文件并保存为&#39; cacert.pem&#39;进入项目根目录

https://www.thawte.com/roots/thawte_Premium_Server_CA.pem

第2步:打开php.ini文件(:\ xampp \ php \ php.ini),在最后添加以下行。

curl.cainfo="C:\xampp\htdocs\smstest\cacert.pem"

第3步:运行您的代码。

示例:

<?php 

require '/twilio-php/Services/Twilio.php';

$sid = "ACxxxxxxxxxxxxxxx"; // Your Account SID from www.twilio.com/user/account
$token = "Auth token"; // Your Auth Token from www.twilio.com/user/account

$client = new Services_Twilio($sid, $token);


$message = $client->account->messages->sendMessage(
  '+1123-456-0789', // From a valid Twilio number
  '+9112346790', // Text this number
  "Hello,you get an contact request from webiste"
);

print $message->sid;

?>