java esl连接freeswitch发送拨打电话<第二篇>_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java esl连接freeswitch发送拨打电话<第二篇>

java esl连接freeswitch发送拨打电话<第二篇>

 2017/8/7 18:31:18  喧嚣求静  程序员俱乐部  我要评论(0)
  • 摘要:javaesl连接freeswitch发送拨打电话<第二篇>publicclassCopyOfEventEslInboundTestBak{privatestaticfinalLoggerlog=LoggerFactory.getLogger(CopyOfEventEslInboundTestBak.class);privatestaticStringhost="127.0.0.1";privatestaticintport=8021
  • 标签:Java 连接

java esl连接freeswitch发送拨打电话<第二篇>

class="java" name="code">public class CopyOfEventEslInboundTestBak {
    private static final Logger log = LoggerFactory.getLogger(CopyOfEventEslInboundTestBak.class);
    private static String host = "127.0.0.1";
    private static int port = 8021;
    private static String password = "ClueCon";

    public static Client inBand() {

        final Client client = new Client();
        try {
            client.connect(host, port, password, 20);
        } catch (InboundConnectionFailure e) {
            log.error("Connect failed", e);
            return null;
        }

        // 注册事件处理程序
        client.addEventListener(new IEslEventListener() {
            public void eventReceived(EslEvent event) {
                // System.out.println("Event received [{}]" +
                // event.getEventHeaders());
                // 记录接听次数和时间
                if (event.getEventName().equals("CHANNEL_ANSWER")) {
                    System.err.println("CHANNEL_ANSWER");
                }
                if (event.getEventName().equals("CHANNEL_BRIDGE")) {
                    System.err.println("CHANNEL_BRIDGE");
                }

                if (event.getEventName().equals("CHANNEL_DESTROY")) {
                    System.err.println("CHANNEL_DESTROY");
                }

                if (event.getEventName().equals("CHANNEL_HANGUP_COMPLETE")) {
                    System.err.println("CHANNEL_HANGUP_COMPLETE");
                }

            }

            public void backgroundJobResultReceived(EslEvent event) {
                String uuid = event.getEventHeaders().get("Job-UUID");
                log.info("Background job result received+:" + event.getEventName() + "/" + event.getEventHeaders());// +"/"+JoinString(event.getEventHeaders())+"/"+JoinString(event.getEventBodyLines()));
            }

        });
        client.setEventSubscriptions("plain", "all");
return client;
}

public static void main(String[] args) throws InterruptedException {
        Client client = inBand();
        dialPhone(client, "xxxxxxx电话号码");
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
    public static void dialPhone(Client client, String mobile){
        if(client != null){
            client.sendSyncApiCommand( "bgapi originate", "sofia/external/" + mobile + "@FreeSwitch的IP &playback(ivr/8000/mydoctestv2.wav)" );
            //String response = client.sendAsyncApiCommand( "originate", "sofia/external/" + mobile + "@192.168.188.222 &playback(ivr/8000/mydoctestv2.wav)" );  //mydoctestv2
           // System.err.println("reponse--->" + response);
        }
    }

?

发表评论
用户名: 匿名