gpt4 book ai didi

java - 如何通过 asterisk-java 调用一个人

转载 作者:行者123 更新时间:2023-12-02 05:47:56 25 4
gpt4 key购买 nike

我在 manager.conf 中创建了一个名为 : mark 的用户管理器,在“sip.conf”中创建了名为“utilisateur”的用户 我想通过 Asterisk-java 调用用户:“utilisateur”,我尝试了这段代码:

  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 HelloManager
{
private ManagerConnection managerConnection;

public HelloManager() throws IOException
{
ManagerConnectionFactory factory = new ManagerConnectionFactory(
"localhost", "mark", "1234");

this.managerConnection = factory.createManagerConnection();
}

public void run() throws IOException, AuthenticationFailedException,
TimeoutException
{
OriginateAction originateAction;
ManagerResponse originateResponse;

originateAction = new OriginateAction();
originateAction.setChannel("SIP/utilisateur");
originateAction.setContext("default");
originateAction.setExten("2222");
originateAction.setPriority(new Integer(1));
originateAction.setTimeout(new Integer(30000));

// connect to Asterisk and log in
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();
}

public static void main(String[] args) throws Exception
{
HelloManager helloManager;

helloManager = new HelloManager();
helloManager.run();
}
}

And in extension.conf i added this extension :

[default]
exten => 2222,1,Dial(SIP/utilisateur)
exten => 2222,2,Answer

我从asterisk服务器收到此错误,有人可以帮助我吗:

 Exception in thread "main" org.asteriskjava.manager.TimeoutException: Timeout waiting for response to Originate
at org.asteriskjava.manager.internal.ManagerConnectionImpl.sendAction(ManagerConnectionImpl.java:809)
at org.asteriskjava.manager.DefaultManagerConnection.sendAction(DefaultManagerConnection.java:289)
at HelloManager.run(HelloManager.java:40)
at HelloManager.main(HelloManager.java:54)

最佳答案

您未在出站调用者中设置要调用的号码。

originateAction.setCallerId(<phonenumber>);

关于java - 如何通过 asterisk-java 调用一个人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23865978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com