Freeswitch使用mod_lcr和origin api

时间:2018-02-20 05:58:36

标签: freeswitch

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

我想发起一个调用,让mod_lcr根据lcr规则决定应该使用哪个网关(成本,可靠性等)。

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

谢谢。

1 个答案:

答案 0 :(得分:0)

我是这样做的。

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

lcr 1716 default as xml

其中1716是数字序列,默认是配置文件名称(您可以使用自己的配置文件名称替换默认值)

注意'作为xml'将返回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>
&#13;
&#13;
&#13;

然后我解析XML并抓住拨号串,在这种情况下

&#13;
&#13;
<dialstring>[lcr_carrier=carrier1,lcr_rate=0.15000]sofia/gateway/carrier1/1716</dialstring>
&#13;
&#13;
&#13;

然后我在我的originate命令中使用dialstring(带有一些额外的变量)。