简体   繁体   中英

twilio sms verification through mobile

I have tested the twilio sms code but I am having some issues. The library can be found at 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

It says:

SSL Validation Exceptions

If you are using an outdated version of libcurl, you may encounter SSL validation exceptions. If you see the following error message, you have a SSL validation exception:

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.

Follow the instruction by skimbrel from this link . Then add the certificate from hairys comment. Your problem should be solved.

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:

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.

step 1 : download file and save as 'cacert.pem' into your project root directory

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.

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

step 3 : run your code.

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;

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM