[英]twilio sms verification through mobile
I have tested the twilio sms code but I am having some issues. 我测试了twilio短信代码,但我遇到了一些问题。 The library can be found at https://www.twilio.com/docs/php/install . 该库可以在https://www.twilio.com/docs/php/install找到。
Here is the code I used: 这是我使用的代码:
<?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}";
?>
When running this, the following error occurs: 运行此时,会发生以下错误:
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
Refer this: https://github.com/twilio/twilio-php/blob/master/docs/faq.rst 请参阅: https : //github.com/twilio/twilio-php/blob/master/docs/faq.rst
It says: 它说:
SSL Validation Exceptions SSL验证例外
If you are using an outdated version of libcurl, you may encounter SSL validation exceptions. 如果您使用的是过时版本的libcurl,则可能会遇到SSL验证异常。 If you see the following error message, you have a SSL validation exception: 如果您看到以下错误消息,则表示您具有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
This means that Twilio is trying to offer a certificate to verify that you are actually connecting to https://api.twilio.com , but your curl client cannot verify our certificate. 这意味着Twilio正在尝试提供证书以验证您实际连接到https://api.twilio.com ,但您的curl客户端无法验证我们的证书。
I solved the problem downloading the cacert.pem from http://curl.haxx.se/docs/caextract.html and modifying my php.ini to include the path of the downloaded file (in my case I copied it into C:\\xampp\\php), adding the following line at the end of the php.ini file: 我解决了从http://curl.haxx.se/docs/caextract.html下载cacert.pem并修改我的php.ini以包含下载文件的路径的问题(在我的情况下,我将其复制到C:\\ xampp \\ php),在php.ini文件的末尾添加以下行:
curl.cainfo=c:\xampp\php\cacert.pem
After saving the file and restarting Apache the error dissapeared and I was able to send sms using the Twilio system. 保存文件并重新启动Apache后,错误消失了,我可以使用Twilio系统发送短信。
step 1 : download file and save as 'cacert.pem' into your project root directory 步骤1:下载文件并将“cacert.pem”另存为项目根目录
https://www.thawte.com/roots/thawte_Premium_Server_CA.pem https://www.thawte.com/roots/thawte_Premium_Server_CA.pem
step 2: open php.ini file (:\\xampp\\php\\php.ini) add following line at the end. 第2步:打开php.ini文件(:\\ xampp \\ php \\ php.ini),最后添加以下行。
curl.cainfo="C:\xampp\htdocs\smstest\cacert.pem"
step 3 : run your code. 第3步:运行您的代码。
Example : 示例:
<?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;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.