星号..PHP.如果我知道SIP,如何获得电话号码


Asterisk. PHP. How to get phone number if I know SIP?

我们有星号服务器和GSM网关。我需要知道在当前时间呼叫星号的电话号码。现在我可以使用命令core show channels获取 SIP,但我不知道如何获取电话号码。我使用 phpAGI 库:

$agi_manager = new AGI_AsteriskManager(null, $agi_config);
$connect = $agi_manager->connect();
$result = $agi_manager->command('core show channels');

"核心显示频道"输出的第一行是频道 ID。 使用它发出命令core show channel <id>(频道末尾没有"s"!)以查看有关频道的更多信息,包括主叫方的号码。

foreach(explode("'n", $result) as $line) {
   $cols = explode(" ", $line);
   $result2 = $agi_manager->command('core show channel '.$col[0]);
   if(preg_match('/Connected Line ID:'s*('d+)/', $result2, $matches) {
      printf("Phone number: %s'n", $matches[1]);
   }
   else {
      printf("No phone number found for SIP Channel ID %s'n", $col[0]);
   }
}

使用Asterisk 1.8进行测试,您的版本可能会给出不同的结果。只需检查 core show channel 的示例输出。