Twilio的去电在Laravel 5.5中不起作用

时间:2018-09-26 09:52:42

标签: php twilio laravel-5.5 twiml twilio-programmable-voice

我是Twilio的新手。我正在使用Twilio进行我的应用程序的电话验证。我正在使用Laravel 5.5作为后端和API。我已成功将SMS发送到电话。我从Twilio接到电话,但它显示应用程序错误。它没有阅读我想听的内容。

下面,我将详细介绍我的代码。

composer require twilio/sdk用于Twilio。

这是我的控制器。

use Twilio\Rest\Client;
use Twilio\Twiml;

class AppUserController extends Controller{
    private $account_sid;
    private $auth_token;
    private $twilio_number;

    public function __construct(){
        $this->account_sid = Config::get('envvalue.account_sid');
        $this->auth_token = Config::get('envvalue.auth_token');
        $this->twilio_number = Config::get('envvalue.twilio_number');
    }

    public function reVerification(Request $request){
        $client = new Client($this->account_sid, $this->auth_token);
        try {
            $client->account->calls->create(
                $receiverNumber,
                $this->twilio_number,
                array(
                    "url" => "http://demo.bitcanny.com/marine-admin/public/api/twiml/"
                )
            );

            return response()->json([
                'success' => true,
                'statusCode' => '200',
                'message' => 'Otp send again'
            ], 200);
        }
        catch (Exception $e) {
            return $e->getMessage();
        }
    }

    public function twiml(){
        // A message for Twilio's TTS engine to repeat
        $sayMessage = 'Hello.';

        $twiml = new Twiml();
        $twiml->say($sayMessage);

        $response = Response::make($twiml, 200);
        $response->header('Content-Type', 'text/xml');
        return $response;
    }

}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。有一个愚蠢的错误。我没有在控制器的标题中使用Response。

use Response;