擴充套件Asterisk1 8 7的AMI介面

2021-09-08 08:40:21 字數 3830 閱讀 2319

asterisk

的ami

介面已經很豐富了,如果需要擴充套件,可以參考本文。

一、擴充套件

asterisk

的ami介面

涉及檔案:

main/manager.c

1、函式註冊

新增 myoriginate介面

在函式int __init_manager(int reload)

中新增如下**:

ast_manager_register_xml("

myoriginate

", event_flag_originate,action_myoriginate); //

add by mike

2、功能實現:

//

add by mike

static

int action_myoriginate(struct mansession *s, const

struct message *m)

char filename[1024]=;

sprintf(filename,

"/var/spool/asterisk/outgoing/%s.call

",tmp);

//file *fp = fopen("/var/spool/asterisk/outgoing/1.call","w");

file *fp = fopen(filename,"w"

);

char buf[1024]=;

sprintf(tmp,

"channel: %s\r\n

",name);

strcpy(buf,tmp);

sprintf(tmp,

"callerid: %s\r\n

",callerid);

strcat(buf,tmp);

strcat(buf,

"maxretries: 1\r\n");

strcat(buf,

"retrytime: 1\r\n");

//sprintf(tmp,"waittime: %s\r\n",timeout);

sprintf(tmp,"

waittime: %s\r\n

","30");

strcat(buf,tmp);

sprintf(tmp,

"context: %s\r\n

",context);

strcat(buf,tmp);

sprintf(tmp,

"extension: %s\r\n

",exten);

strcat(buf,tmp);

sprintf(tmp,

"extension: %s\r\n

",exten);

strcat(buf,tmp);

fwrite((

void*)buf,strlen(buf),1

,fp);

fclose(fp);

return0;

}

二、配置

asterisk 1

、編譯安裝

make && make install 2

、新增撥號方案

在檔案/etc/asterisk/extension.conf中加入以下**:

[dlpn_meetingwithoutrecord]

exten =>

_63xx,1

,answer

()exten =>

_63xx,n

,meetme(

$,mw,1234)

exten =>

_63xx,n

,hangup()

三、ami呼叫測試(

python):

#

! /usr/bin/python

import

socket

defstrlogin(usr,pwd):

msg = "

action: login\r\n

"msg += "

events: off\r\n

"msg += "

username:

" + usr + "

\r\n

"msg += "

secret:

" + pwd + "

\r\n

"msg += "

\r\n

"return

msgdef

strcall(strnum,strcallid):

msg = "

action: myoriginate\r\n

"msg += "

channel: sip/

"+strnum+"

\r\n

"msg += "

waittime: 1\r\n

"msg += "

callerid:

"+strcallid+"

\r\n

"msg += "

exten:

"+strcallid+"

\r\n

"msg += "

context: dlpn_meetingwithoutrecord\r\n

"msg += "

priority: 1\r\n

"msg += "

\r\n

"return

msgdef

strlogoff():

return

"action: logoff\r\n\r\n

"def

strhangup(strnum):

msg = "

action: hangup\r\n

"msg += "

channel: sip/

"+strnum

return

msgdef

main():

s =socket.socket(socket.af_inet, socket.sock_stream)

s.connect((raw_input(

"ip :

"), 5038))

ifnot

s :

print

"connect fail!

"return

else : print

"connect success!

"strnum = raw_input("

input number to dail:")

strcallerid = raw_input("

input caller id :")

msg = ""

msg += strlogin(raw_input("

username :

"),raw_input("

password"))

msg +=strcall(strnum,strcallerid)

msg +=strlogoff()

s.send(msg)

while

true:

data = s.recv(1024)

ifnot data : break

else : print

data

s.close()

if__name__ == '

__main__':

main()

#raw_input("press enter to continue")

好,就這些了,希望對你有幫助。

asterisk的配置文件

用兩個sip 通過asterisk服務互通打 需要配置sip.conf,extension.conf sip.conf general context default 預設進入的撥號方案 allowoverlap no bindport 5060 監聽埠 bindaddr 0.0.0.0 監聽所有過...

asterisk 的應用文摘

在freepbx中,有多處需要設定dial rules,設定規則如下 x代表乙個0 9中的任意乙個數字 z代表乙個1 9中的任意乙個數字 n代表乙個2 9中的任意乙個數字 1237 9 匹配括號內的任何數字或字母 在這個例子中匹配1,2,3,7,8,9 萬用字元,匹配乙個或多個字元 不允許在 或 之...

asterisk 的三方通話

1001 呼1002 1002接通,1001 按 00後1001,1002進入會議,接著按要撥打的1003 以 結束。這是1001和 1003建立通話但,1001按 11 把1003加入會議,實現了三方通話。注意 在sip.conf 的號碼定義時 一定要把允許的編碼 在 你asterisk自帶的編碼...