asterisk-java的测试使用
一个可用于FreePBX的封装库
asterisk-java
用于asteriskPBX集成的免费Java库。
https://github.com/asterisk-java/asterisk-java
最新版本为3.39.0
<dependency>
<groupId>org.asteriskjava</groupId>
<artifactId>asterisk-java</artifactId>
<version>3.39.0</version>
</dependency>
测试用例
import java.io.IOException;
import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.OriginateAction;
import org.asteriskjava.manager.response.ManagerResponse;
public class TestManager {
private ManagerConnection managerConnection;
public static void main(String[] args) throws Exception
{
TestManager helloManager;
helloManager = new TestManager();
helloManager.run();
}
public TestManager() throws IOException
{
ManagerConnectionFactory factory = new ManagerConnectionFactory(
"172.18.12.4", 5038,"admin", "MQ5d8RRKnMFz");
this.managerConnection = factory.createManagerConnection();
}
public void run() throws IOException, AuthenticationFailedException,
TimeoutException
{
OriginateAction originateAction;
ManagerResponse originateResponse;
// connect to Asterisk and log in
originateAction = new OriginateAction();
originateAction.setChannel("pjsip/1001");
// originateAction.setContext("default");
originateAction.setContext("from-internal");
originateAction.setExten("1001");
originateAction.setCallerId("9119");
originateAction.setPriority(new Integer(1));
originateAction.setTimeout(new Long(30000));
originateAction.setApplication("Playback");
originateAction.setData("custom/cp1");
managerConnection.login();
// send the originate action and wait for a maximum of 30 seconds for Asterisk
// to send a reply
originateResponse = managerConnection.sendAction(originateAction, 30000);
// print out whether the originate succeeded or not
System.out.println(originateResponse.getResponse());
// and finally log off and disconnect
managerConnection.logoff();
}
}
成功给向分机pjsip/1001发起播放custom/cp1录音
标签:asteriskjava,java,originateAction,asterisk,manager,测试,org,import From: https://blog.51cto.com/u_12668715/7010043