【问题标题】:Outgoing call from Twilio is not working in Laravel 5.5来自 Twilio 的拨出电话在 Laravel 5.5 中不起作用
【发布时间】:2018-09-26 09:52:41
【问题描述】:

我是 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;
    }

}

【问题讨论】:

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


    【解决方案1】:

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

    use Response;
    

    【讨论】:

    • 我也在处理相同的功能,我正在获取此流程的 URL 部分,您能详细说明一下吗?我正在尝试一种方式,我正在制作 XML 文件并将其上传到 S3,然后将 URL 提供给 twillio 但它说你之前遇到过同样的错误?
    • 您提供的 URL,它应该是 Twilio 读取您正在创建的 XML 文件的函数的路径。 HTTP 方法应该是 GET。
    • 好的,我知道 twillio 只会读取具有有效域的 URL,而不是来自 localhost、S3 或任何其他公共域。就我而言,它仅适用于我为我的产品购买的域。
    • 是的,您可以从 localhost 发送短信,但对于呼叫,您应该有一个有效的域。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多