简体   繁体   English

通过PHP脚本进行SIP注册

[英]SIP Registration from PHP Script

The Goal: to use a LAMP server to register as and endpoint to a SIP server. 目标:使用LAMP服务器注册为SIP服务器并作为其端点。

Why: To intercept phone calls to a particular extension as they happen to interact with a PHP CRM. 原因:在碰到与PHP CRM交互的特定分机上的电话时,将其拦截。

The SIP server is not using Asterisk as has to be made generic enough to handle any SIP service. SIP服务器未使用Asterisk,因为必须使其足够通用以处理任何SIP服务。

I'm using a handy PHP SIP Library written by Level7Systems - Although there isn't many examples or support on this particular package. 我正在使用由Level7Systems编写的方便的PHP SIP库 -尽管此特定程序包没有很多示例或支持。

My code is: 我的代码是:

  $api1 = new PhpSIP('x.x.x.x'); //My Servers public IP
  $api1->setMethod('REGISTER');
  $api1->setFrom('sip:111@my-dns.com');
  $api1->setUri('sip:111@sip-server.com');

  $api1->setUsername('12345');
  $api1->setPassword('abc123');
  $res = $api1->send(); 

The code executes successful, creates a socket (and a lock file), binds to a port and supposedly sends a UDP packet to the SIP server... Although, when I run a tcpdump I don't see any UDP packets hitting port 5060 or 5061 to the destination server. 该代码成功执行,创建了一个套接字(和一个锁定文件),绑定到端口,并应该将UDP数据包发送到SIP服务器...尽管,当我运行tcpdump我看不到任何UDP数据包到达端口5060或5061到目标服务器。

The code will run for 10 seconds while it waits for a reply from the SIP server as it should return with an 404 response. 该代码等待SIP服务器的回复时将运行10秒钟,因为它应返回404响应。 But it never does. 但是它永远不会。

To be sure, I've also disabled my firewall. 可以肯定的是,我也禁用了防火墙。

Anyone had any experience registering a SIP endpoint using PHP? 任何人都有使用PHP注册SIP端点的经验吗?

Is there a better way to do it? 有更好的方法吗?

my suggestion is to add a try...catch to see what happens in your routine. 我的建议是添加一个try ... catch以查看例程中发生的情况。

try {
  $api1 = new PhpSIP('x.x.x.x'); //My Servers public IP
  $api1->setMethod('REGISTER');
  $api1->setFrom('sip:111@my-dns.com');
  $api1->setUri('sip:111@sip-server.com');

  $api1->setUsername('12345');
  $api1->setPassword('abc123');
  $res = $api1->send();

  echo "res: $res\n";

} catch (Exception $e) {

  echo $e->getMessage()."\n"; } 

But, if you are using SIP phones, another solution is to try with the action URL / active URI. 但是,如果您使用的是SIP电话,则另一种解决方案是尝试使用操作URL /活动URI。 Here a good guide to understand how to use them. 这里是了解如何使用它们的好指南

So it turned out that @sip-server.com wasn't actually an active SIP server. 因此,事实证明@sip-server.com实际上不是活动的SIP服务器。

It was more like @sip.sip-server.com that needed to be pinged, and once that change happened, everything worked as expected. 需要更像@sip.sip-server.com ,一旦发生更改,一切都会按预期进行。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM