Freeswitch 使用 mod_lcr 和 originate api

Freeswitch use mod_lcr with originate api

有没有办法将 mod_lcr 与 originate 命令一起使用?

我想发起呼叫并让 mod_lcr 根据 lcr 规则(成本、可靠性等)决定应使用哪个网关。

当在拨号方案中使用 mod_lcr 时,它将使用拨号字符串填充变量 ${lcr_auto_route}。我如何使用与 originate 相同的逻辑?

谢谢。

这是我的做法。

我通过ESL连接到freeswitch并执行命令

lcr 1716 default as xml

其中 1716 是数字序列,默认是个人资料名称(您可以用自己的个人资料名称替换默认值)

注意 'as xml' 将 return 一个 XML 响应。响应如下所示:

<result>
  <row id="1">
    <prefix>1716</prefix>
    <carrier_name>carrier1</carrier_name>
    <rate>0.15000</rate>
    <codec></codec>
    <cid></cid>
    <limit></limit>
    <dialstring>[lcr_carrier=carrier1,lcr_rate=0.15000]sofia/gateway/carrier1/1716</dialstring>
    <event>
      <headers>
        <Event-Name>REQUEST_PARAMS</Event-Name>
        <Core-UUID>151c590b-cce8-4eb3-b3ae-f48bad397870</Core-UUID>
        <FreeSWITCH-Hostname>freeswitch</FreeSWITCH-Hostname>
        <FreeSWITCH-Switchname>freeswitch</FreeSWITCH-Switchname>
        <FreeSWITCH-IPv4>172.16.124.130</FreeSWITCH-IPv4>
        <FreeSWITCH-IPv6>%3A%3A1</FreeSWITCH-IPv6>
        <Event-Date-Local>2018-02-20%2007%3A33%3A42</Event-Date-Local>
        <Event-Date-GMT>Tue,%2020%20Feb%202018%2006%3A33%3A42%20GMT</Event-Date-GMT>
        <Event-Date-Timestamp>1519108422660002</Event-Date-Timestamp>
        <Event-Calling-File>mod_lcr.c</Event-Calling-File>
        <Event-Calling-Function>route_add_callback</Event-Calling-Function>
        <Event-Calling-Line-Number>633</Event-Calling-Line-Number>
        <Event-Sequence>786</Event-Sequence>
        <lcr_digits>1716</lcr_digits>
        <lcr_carrier_name>carrier1</lcr_carrier_name>
        <lcr_rate_field>0.15000</lcr_rate_field>
        <lcr_gw_prefix>sofia/gateway/carrier1/</lcr_gw_prefix>
        <lcr_lead_strip>0</lcr_lead_strip>
        <lcr_trail_strip>0</lcr_trail_strip>
      </headers>
    </event>
  </row>
  <row id="2">
    <prefix>1</prefix>
    <carrier_name>carrier2</carrier_name>
    <rate>0.12000</rate>
    <codec></codec>
    <cid></cid>
    <limit></limit>
    <dialstring>[lcr_carrier=carrier2,lcr_rate=0.12000]sofia/external/0716@proxy.carrier2.net:5060</dialstring>
    <event>
      <headers>
        <Event-Name>REQUEST_PARAMS</Event-Name>
        <Core-UUID>151c590b-cce8-4eb3-b3ae-f48bad397870</Core-UUID>
        <FreeSWITCH-Hostname>freeswitch</FreeSWITCH-Hostname>
        <FreeSWITCH-Switchname>freeswitch</FreeSWITCH-Switchname>
        <FreeSWITCH-IPv4>172.16.124.130</FreeSWITCH-IPv4>
        <FreeSWITCH-IPv6>%3A%3A1</FreeSWITCH-IPv6>
        <Event-Date-Local>2018-02-20%2007%3A33%3A42</Event-Date-Local>
        <Event-Date-GMT>Tue,%2020%20Feb%202018%2006%3A33%3A42%20GMT</Event-Date-GMT>
        <Event-Date-Timestamp>1519108422660002</Event-Date-Timestamp>
        <Event-Calling-File>mod_lcr.c</Event-Calling-File>
        <Event-Calling-Function>route_add_callback</Event-Calling-Function>
        <Event-Calling-Line-Number>633</Event-Calling-Line-Number>
        <Event-Sequence>787</Event-Sequence>
        <lcr_digits>1</lcr_digits>
        <lcr_carrier_name>carrier2</lcr_carrier_name>
        <lcr_rate_field>0.12000</lcr_rate_field>
        <lcr_gw_prefix>sofia/external/</lcr_gw_prefix>
        <lcr_gw_suffix>%40proxy.carrier2.net%3A5060</lcr_gw_suffix>
        <lcr_lead_strip>1</lcr_lead_strip>
        <lcr_trail_strip>0</lcr_trail_strip>
        <lcr_prefix>0</lcr_prefix>
      </headers>
    </event>
  </row>
</result>

然后我解析 XML 并获取本例中的拨号字符串

<dialstring>[lcr_carrier=carrier1,lcr_rate=0.15000]sofia/gateway/carrier1/1716</dialstring>

然后我在 originate 命令中使用拨号字符串(带有一些额外的变量)。