0

我正在创建一个页面,该页面接收存储为 JSON 的信息。例如:

"PatientContactHeader":{  
  "PatientID":14,
  "PhoneNumber":"+1558881414",
  "ContactType":"Phone Call",
  "DateTimeOfCall":"2015-06-25: 11:00:00AM",
  "TimeZone":"EST"
 } "PatientContactDetails":[  
  {  
     "MessageID":123,
     "RecordingURL":"http://examplerecording.com",
     "MessageTitle":"Greeting"
  }
 ]
}

初始页面将接收此 JSON 并使用它来创建出站呼叫。根据 Twilio 的 API,出站向某个 TwiML Url 发出请求。

 function initiateCall($fromNumber, $toNumber, $url) {

try {
    // Initiate a new outbound call
    $call = $client->account->calls->create(
        $fromNumber, // The number of the phone initiating the call
        $toNumber, // The number of the phone receiving call
        $url, // The URL Twilio will request when the call is answered
        array('IfMachine' =>'Continue')
    );
    echo 'Started call: ' . $call->sid;
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

}

我想要的是能够访问 TwiML 指令中的一些 JSON 信息。更具体地说,如果被呼叫的人应该接收多条消息,我希望能够遍历 JSON 数据并访问每条消息以进行回放。我的问题是我不知道如何将信息从发出调用请求的初始页面传递到包含 TwiML 的页面。解决此问题的合乎逻辑的方法似乎是会话变量,但我已经阅读(并发现)这些变量在进行出站呼叫时不起作用。这个问题有什么解决办法吗?

4

1 回答 1

2

如果您已经有一个存储了此信息的数据库,那么处理此问题的最快方法是在 TwiML url 的查询字符串中传递一条可用于查询数据库的数据(可能是 PatientID 或 MessageID},如下所示:

  $call = $client->account->calls->create(
        $fromNumber, // The number of the phone initiating the call
        $toNumber, // The number of the phone receiving call
        $url . "?PatientID=" . $patientID, // The URL Twilio will request when the call is answered
        array('IfMachine' =>'Continue')
    );

然后在为 TwiML 提供服务的文件中,您可以像这样访问该数据:

$patientID = $_GET['PatientID'];
// query your database with $patientID and get the info you need

希望有帮助!

于 2015-10-21T20:54:04.620 回答