我有以下使用Twilio发送验证文本的PHP脚本:
<?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。
发布于 2017-06-24 09:22:27
您为服务器上的文件位置输入的URL是错误的,您错过了一个目录http://188.226.144.157/group1/twilio-php-master/autoload.php返回404
而这在http://188.226.144.157/group1/twilio-php-master/Twilio/autoload.php中是有效的
尝尝这个
require '/var/www/html/group1/twilio-php-master/Twilio/autoload.php'
https://stackoverflow.com/questions/44727166
复制相似问题