Twilio可编程语音无效

问题描述 投票:0回答:2

当我尝试使用[TwilioVoice Call]方法从我的应用程序传递param时,我无法在twiML应用程序上获得这些参数。但是当我尝试使用FormData从POSTMAN传递相同的数据时,它的工作正常并且还能成功地创建调用。

请问如何帮助我如何使用从我的iOS应用程序传递到twiML的param

PHP中的TwiML应用程序:

<?php
/*
 * Makes a call to the specified client using the Twilio REST API.
 */
include('./vendor/autoload.php');
include('./config.php');
$to = isset($_GET["to"]) ? $_GET["to"] : "";
if (!isset($to) || empty($to)) {
    $to = isset($POST["to"]) ? $_POST["to"] : "";
}
$from = isset($_GET["from"]) ? $_GET["from"] : "";
if (!isset($from) || empty($from)) {
    $from = isset($POST["from"]) ? $_POST["from"] : "";
}

use Twilio\Twiml;
$response = new Twiml();
$dial = $response->dial(['callerId' => $from]);
$dial->client($to);
echo $response;

iOS Objective-C:

self.call = [TwilioVoice call:[self fetchAccessToken]
                           params:@{@"to": @"1",@"from":@"2"}
                             uuid:uuid
                         delegate:self];

Twilio Error我尝试从iOS传递param时记录

警告 - 13224拨号:Twilio不支持呼叫此号码或号码无效

enter image description here

参考TwiML应用程序代码

https://github.com/twilio/voice-quickstart-server-php

objective-c twilio twilio-api twilio-php twiml
2个回答
1
投票

Twilio开发者传道者在这里。

来自Twilio的12100 error无法解析从服务器返回的TwiML。在这种情况下,这是因为你的PHP没有返回TwiML,它正在尝试make a call using the REST API

它应该返回一个嵌套<Dial><Client>。您也可以使用帮助程序库来构建它。尝试将代码更改为:

<?php
    include('./vendor/autoload.php');
    include('./config.php');

    $to = isset($_REQUEST["To"]) ? $_REQUEST["To"] : "";
    $to = str_replace("client:", "", $to);

    $from = isset($_REQUEST["From"]) ? $_REQUEST["From"] : "";

    use Twilio\Twiml;

    $response = new Twiml();
    $dial = $response->dial(['callerId' => $from]);
    $dial->client($to);

    echo $response;

如果有帮助,请告诉我。


0
投票

步骤1.在名称中,您必须传递用户的名称(您想要的任何东西)

步骤2.您需要使用3个参数生成令牌

第3步。您需要创建VoiceGrant的对象

第4步。您需要传递Id

步骤5.您需要从twilio设置PUSH通知Id生成

$name = $this->input->post('name');
            //$PUSH_CREDENTIAL_SID = 'CRaf1a66dd4a7656876e16c7820ef5c01e';
             $outgoingApplicationSid = 'APf9b1b789ba690b8789d95a42511f2018';
              // choose a random username for the connecting user
             $identity = $name;
             // Create access token, which we will serialize and send to the client


             $token = new AccessToken(
             $this->twilioAccountSid,
             $this->twilioApiKey,
             $this->twilioApiSecret,
             3600,
             $identity
              );
          //     $chatGrant = new ChatGrant( $pushCredentialSid= "CRaf1a66dd4a7656876e16c7820ef5c01e");
          //
          // print_r($chatGrant);die;
             // Create Chat grant
             // $voiceGrant = new VoiceGrant($serviceSid = 'IS840a7e5f64634ab6bf179c3f8b0adfc4',$pushCredentialSid = 'CRaf1a66dd4a7656876e16c7820ef5c01e');
             $voiceGrant = new VoiceGrant();
             $voiceGrant->setOutgoingApplicationSid($outgoingApplicationSid);

             // Optional: add to allow incoming calls
             $voiceGrant->setIncomingAllow(true);

             $voiceGrant->setPushCredentialSid('CRaf1a66dd4a7656876e16c7820ef5c01e');


             // Add grant to token
             $token->addGrant($voiceGrant);

             // render token to string
            $voice_token = $token->toJWT();
             if($voice_token){
                $data['token'] = $voice_token;
                 $this->response = array('status'=>1,'data'=>$data);
             }else{
                 $this->response = array('status'=>0,'message'=>'Not found');
             }
© www.soinside.com 2019 - 2024. All rights reserved.