【发布时间】:2020-04-29 04:55:12
【问题描述】:
我正在与 Twilio 合作开发一个 Laravel 项目,并编写了一个函数来回复传入的 SMS。 我在本地机器上测试了这个功能,效果很好。我将整个项目上传到 CPanel。 所有其他功能都可以正常工作,但会出现这样的错误。
Error: Class 'Twilio\Twiml\MessagingResponse' not found in file /home/user_name/subdomain_directory/app/Http/Controllers/Api/SMSController.php on line 104
Twilio\Rest\Client、Twilio\Security\RequestValidator 等其他类运行良好。
我检查了 CPanel 上供应商目录中的 MessagingResponse.php 文件。
以下是代码。我真的不知道为什么会这样。如果有人帮助我,我将非常感激。
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Twilio\Rest\Client;
use Twilio\Twiml\MessagingResponse;
class SMSController extends Controller
{
protected $twilio_number;
protected $twilio_sid;
protected $twilio_auth_token;
public function __construct() {
$this->twilio_number = env('TWILIO_PHONE');
$this->twilio_sid = env('TWILIO_SID');
$this->twilio_auth_token = env('TWILIO_AUTH_TOKEN');
}
public function reply(Request $request) {
$number_from = $request->input('From');
$message = "You have received a message from " . $number_from;
$client = new Client($this->twilio_sid, $this->twilio_auth_token);
$client->messages->create(
env("TWILIO_REDIRECT_REPLY_TO"),
array(
'from' => $this->twilio_number,
'body' => $message
)
);
$response = new MessagingResponse();
return response($response);
}
}
【问题讨论】:
标签: php laravel twilio twilio-api