【发布时间】:2017-07-03 20:34:10
【问题描述】:
我有以下 PHP 脚本来使用 Twilio 发送验证文本:
<?php
require '/twilio-php-master/Twilio/autoload.php';
// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;
$AccountSid = "xxx"; // Your Account SID from www.twilio.com/console
$AuthToken = "xxx"; // Your Auth Token from www.twilio.com/console
$client = new Client($AccountSid, $AuthToken);
$number = $_GET['num'];
$country = $_GET['country'];
$receivingPhone = "+2".$number;
$code = rand(100000, 999999);
$client->messages->create(
// the number you'd like to send the message to
$receivingPhone,
array(
// A Twilio phone number you purchased at twilio.com/console
'from' => '+12562947081',
// the body of the text message you'd like to send
'body' => $code
)
);
$object = new stdClass();
$object->num = $code;
echo json_encode($object);
?>
当我使用 http://localhost/sms.php?num=01115465467&country=Egypt 运行它并将 autoload.php 文件的目录更改为 /Applications/XAMPP/xamppfiles/htdocs/twilio-php-master/Twilio/autoload.php (它安装在我的计算机),脚本工作正常。但是,我将它上传到远程服务器,并尝试使用目录 /var/www/html/group1/twilio-php-master/autoload.php (它在服务器上)并在http://188.226.144.157/group1/sms.php?num=01115465467&country=Egypt 上运行它,但是我的 android 应用在尝试运行脚本时返回错误代码 500。
【问题讨论】:
标签: php twilio twilio-php