2

我在 PHP 中使用 Asterisk 管理接口 (AMI) 来发起出站呼叫。下面是我正在使用的代码片段:

// snippet
// $num is the number to dial e.g. 0207 121 3456
// $ext is the extension use to make the call e.g. 101
// $name is the name of the caller e.g. Fred Flintstone
//
fputs($socket, "Action: Originate\r\n" );
fputs($socket, "Channel: SIP/$ext\r\n" );
fputs($socket, "Exten: $num\r\n" );
fputs($socket, "Context: from-internal\r\n");
fputs($socket, "Priority: 1\r\n" );
fputs($socket, "CallerID: \"".$name."\" <".$num.">\r\n" );
fputs($socket, "Async: yes\r\n\r\n" );

如何设置呼叫者姓名 ( $name) 或写入到asteriskcdrdb始发脚本中的出站呼叫的其他详细信息?理想情况下,我想以与设置dst入站呼叫字段相同的方式设置字段。

4

3 回答 3

1

您可以将任何变量置于操作中:

    fputs($socket, "Action: Originate\r\n" );
    fputs($socket, "Channel: SIP/201\r\n" );
    fputs($socket, "Exten: 1234\r\n" );
    fputs($socket, "Account: FOOBAR\r\n" );
    fputs($socket, "Context: from-internal\r\n" );
    fputs($socket, "Priority: 1\r\n" );
    fputs($socket, "WaitTime: 15\r\n" );
    fputs($socket, "Callerid: 123456\r\n" );
    fputs($socket, "Variable: CDR(userfield)=AnyData\r\n\r\n" );
    $wrets=fgets($socket,128);
    echo $wrets;
于 2020-09-01T07:14:25.033 回答
0

您不需要使用 Action: Setvar 来设置 CDR(accountcode) ,您只需在呼叫发起期间添加以下行

           fputs($socket, "Account: FOOBAR\r\n" );

下面是完整的例子

       fputs($socket, "Action: Originate\r\n" );
        fputs($socket, "Channel: SIP/201\r\n" );
        fputs($socket, "Exten: 1234\r\n" );
        fputs($socket, "Account: FOOBAR\r\n" );
        fputs($socket, "Context: from-internal\r\n" );
        fputs($socket, "Priority: 1\r\n" );
        fputs($socket, "WaitTime: 15\r\n" );
        fputs($socket, "Callerid: 123456\r\n\r\n" );
        $wrets=fgets($socket,128);
        echo $wrets;
于 2015-02-28T21:22:58.290 回答
0

在origin 之后,您可以解析输出以查找频道 ID,然后您可以使用 Setvar 设置 CDR(userfield) 或 CDR(accouncode) ...等

我的例子:

fputs($socket, "Action: Originate\r\n");
fputs($socket, "Channel: $userExt\r\n");
fputs($socket, "Context: $AMIcntx\r\n");
fputs($socket, "Exten: $phoneNum\r\n");
fputs($socket, "Priority: 1\r\n");

$chan=true;
$channelID=0;

while (!feof($socket))
{
    if ($chan && preg_match("#Channel: ([a-zA-Z0-9\\/-]+)#", $wrets, $cm))
    {
        $channelID = $cm[1];        
        fputs($socket, "Action: Setvar\r\n");
        fputs($socket, "Channel: $channelID\r\n");
        fputs($socket, "Variable: CDR(userfield)\r\n");
        fputs($socket, "Value: FOOBAR\r\n\r\n");        
        fputs($socket, "Action: Logoff\r\n\r\n");
        $chan = false; //There are various Channel response, not overwrite.
    }
    //Further parsing of the AMI response go heres
}

SetVar仅设置指定通道的变量。您必须在通话结束之前尽早发送 setvar 命令。

如果您可以编辑您的拨号计划(我不能,因为我使用 freepbx),另一种方法是为 ami 调用创建一个特定的上下文,将一些变量从起源传递到上下文,将这个变量设置为拨号计划中的 CDR .

于 2013-10-01T08:48:10.253 回答