FreeSWITCH及VOIP,Openser,电话机器人等产品中文技术资讯、交流、沟通、培训、咨询、服务一体化网络。QQ群:293697898
__author__ = 'lihao,18621575908'
#https://github.com/websocket-client/websocket-client
import websocket
try:
import thread
except ImportError: # TODO use Threading instead of _thread in python3
import _thread as thread
import time
import sys
import json
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
def run(*args):
s = '{"Agent":"8000","Password":"1234","Extension":"1001"}'
ws.send(s)
time.sleep(1)
thread.start_new_thread(run, ())
if __name__ == "__main__":
websocket.enableTrace(True)
if len(sys.argv) < 2:
host = "ws://139.196.40.50:8084/fsgui"
else:
host = sys.argv[1]
ws = websocket.WebSocketApp(host,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.on_open = on_open
ws.run_forever()
##除登录认证或单独说明外,其它的接口均为控制,则回应值
###正常的为:"code": "0", "msg": "successed", "sessionid": uuid
###不正常的为: "code": "1", "msg": "failed", "sessionid": uuid
###属于没注册的或token失效则为: "Not Authorized"
websocket地址: host = "ws://139.196.40.50:8084/fsgui"
送的认证模块数据: '{"Agent":"8000","Password":"1234","Extension":"1001"}'
那么就会源源不断地从远程服务器获得数据
curl -d '{"username": "admin", "password": "admin"}' -H "Content-Type:application/json" http://192.168.1.115:8082/api/login
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/get_uuid
//idle or busy
//idle意为设置为闲
//busy意为设置为忙
curl -H "Content-Type: application/json" -d '{"Extension":"1002","Value":"idle" }' -H "Authorization:Nway token " http://192.168.1.115:8085/api/extension_seatstatus
//up or down
//up为上线
//down为下线
curl -H "Content-Type: application/json" -d '{"Extension":"1002","Value":"up" }' -H "Authorization:Nway token " http://192.168.1.115:8085/api/extension_seatstate
//ring,talking,ivr,ready
//ring 振铃中
//talking通话中
//ivr 语音导航中
//ready 准备就绪,可以通话
curl -H "Content-Type: application/json" -d '{"Extension":"1002","Value":"ring" }' -H "Authorization:Nway token " http://192.168.1.115:8085/api/extension_callstate
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/extension_info/1002
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/get_phone_uuid/1002
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/hangup/1002
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/hold/1002
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/unhold/1002
//Job_uuid 源主叫uuid get_uuid获得
Callername sip里的name
Callernum aleg 号码
Calleenum bleg 号码
A_gatewayname 如果a是外线,则要指定a的出局网关
B_gatewayname 如果b是外线,则要指定b的出局网关
A_effective_caller_id_num a到b显示的号码
B_effective_caller_id_num b到a在a上显示的号码
A_external false,true,标记a是不是外线
B_external false,true,标记b是不是外线
curl -H "Content-Type: application/json" -d '{"Job_uuid":"1234","Callername":"1002","Callernum":"1002","Calleenum":"1000","A_gatewayname":"","B_gatewayname":"","A_effective_caller_id_num":"1002","B_effective_caller_id_num":"1000","A_external":"false","B_external":"false"}' -H "Authorization:Nway token " http://192.168.1.115:8085/api/originate
这个接口可以替代原上一个接口originage,即我们不指定播放的ring_id即可
Job_uuid 源主叫uuid get_uuid获得
Callername sip里的name
Callernum aleg 号码
Calleenum bleg 号码
A_gatewayname 如果a是外线,则要指定a的出局网关
B_gatewayname 如果b是外线,则要指定b的出局网关
A_effective_caller_id_num a到b显示的号码
B_effective_caller_id_num b到a在a上显示的号码
A_external false,true,标记a是不是外线
B_external false,true,标记b是不是外线
Ring_id , 上传后的彩铃id,在这里以字符串发送
先呼内线再呼外线
curl -H "Content-Type: application/json" -d '{"Job_uuid":"1234","Callername":"1001","Callernum":"1001","Calleenum":"018621575908","A_gatewayname":"nwaycall","B_gatewayname":"nwaycall","A_effective_caller_id_num":"18621575908","B_effective_caller_id_num":"13671947488","A_external":"false","B_external":"true","Ring_id":"35"}' -H "Authorization:Nway token" http://127.0.0.1:8085/api/originate_playring
先呼外线再呼内线
curl -H "Content-Type: application/json" -d '{"Job_uuid":"1234","Callername":"18621575908","Callernum":"018621575908","Calleenum":"1001","A_gatewayname":"nwaycall","B_gatewayname":"nwaycall",
"A_effective_caller_id_num":"18621575908",
"B_effective_caller_id_num":"13671947488","A_external":"true","B_external":"false","Ring_id":"35"}' -H "Authorization:Nway token" http://127.0.0.1:8085/api/originate_playring
两线均为外线
curl -H "Content-Type: application/json" -d '{"Job_uuid":"1234","Callername":"18621575908","Callernum":"018621575908","Calleenum":"013671947488","A_gatewayname":"nwaycall","B_gatewayname":"nwaycall","A_effective_caller_id_num":"18621575908","B_effective_caller_id_num":"13671947488","A_external":"true","B_external":"true","Ring_id":"35"}' -H "Authorization:Nway token" http://127.0.0.1:8085/api/originate_playring
Job_uuid 源主叫uuid get_uuid获得
Callername sip里的name
Callernum aleg 号码
Calleenum bleg 号码
A_gatewayname 如果a是外线,则要指定a的出局网关
B_gatewayname 如果b是外线,则要指定b的出局网关
A_effective_caller_id_num a到b显示的号码
B_effective_caller_id_num b到a在a上显示的号码
A_external false,true,标记a是不是外线
B_external false,true,标记b是不是外线
Ring_id , 上传后的彩铃id,在这里以字符串发送
Cdr_url , 当遇到有cdr时,应post到的地址
Event_url , 当有消息事件时,应post到的地址
返回值:
成功: w.WriteJson(map[string]string{"code": "1", "msg": "BackMsg_19", "sessionid": myOri.Job_uuid})
失败: w.WriteJson(map[string]string{"code": "2", "msg": "BackMsg_20", "sessionid": myOri.Job_uuid})
curl -H "Content-Type: application/json" -d '{"Job_uuid":"1234","Callername":"1002","Callernum":"1002",
"Calleenum":"1000","A_gatewayname":"","B_gatewayname":"","A_effective_caller_id_num":"1002",
"B_effective_caller_id_num":"1000","A_external":"false","B_external":"false","Ring_id":"35",
"Cdr_url":"http://123.1.2.2/cdr/","Event_url":"http://123.1.2.2/event/"}'
-H "Authorization:Nway token" http://192.168.1.115:8085/api/originate_yn
从配的GatewayGroupId中的网关中随机获取一个gateway,然后进行a路和b路的呼叫,其它值同11c
curl -H "Content-Type: application/json" -d '{"Job_uuid":"1234","Callername":"1002","Callernum":"1002",
"Calleenum":"1000","A_effective_caller_id_num":"1002","GatewayGroupId":"1",
"B_effective_caller_id_num":"1000","A_external":"false","B_external":"false","Ring_id":"35",
"Cdr_url":"http://123.1.2.2/cdr/","Event_url":"http://123.1.2.2/event/"}'
-H "Authorization:Nway token" http://192.168.1.115:8085/api/originate_ext
这里是通过我们的应用来实现,把平台呼出外线反作为外线呼入来处理,从而可以更方便地进行功能扩展
curl -H "Content-Type: application/json" -d '{"Job_uuid":"1234","Callername":"1002","Callernum":"1002",
"GroupNum":"8000","A_gatewayname":"nway",
"A_effective_caller_id_num":"1002","
"B_effective_caller_id_num":"1000","A_external":"false", "Ring_id":"35"}'
-H "Authorization:Nway token" http://192.168.1.115:8085/api/originate_to_group
curl -H "Content-Type: application/json" -d '{"Job_uuid":"1234","Callernum":"1002",
"Calleenum":"1000","A_gatewayname":"","A_effective_caller_id_num":"1002",
"B_effective_caller_id_num":"1000","A_external":"false"}'
-H "Authorization:Nway token" http://192.168.1.115:8085/api/to_dialplan
curl -H "Content-Type: application/json" -d '{"Job_uuid":"feew32223dd3e32re32e32", "Callernum":"18621575908", "Calleenum":"999888", "A_gatewayname":"nway1", "A_effective_caller_id_num":"021168686868", "A_external":"true",
"Cdr_url":"http://127.0.0.1:8085/fs/cdr", "Event_url":"http://127.0.0.1:8085/fs/callstate", "Record_file":"mytest.wav"}' -H "Authorization:Nway TOKEN" http://127.0.0.1:8085/api/originate_i
curl -H "Content-Type: application/json" -d '{"Job_uuid":"feew32223dd3e32re32e32", "Callernum":"18621575908", "Calleenum":"999888", "A_gatewayname":"nway1", "A_effective_caller_id_num":"021168686868", "A_external":"true", "Cdr_url":"http://127.0.0.1:8085/fs/cdr", "Event_url":"http://127.0.0.1:8085/fs/callstate", "Record_file":"mytest.wav"}' -H "Authorization:Nway TOKEN" http://127.0.0.1:8085/api/originate_i_da
curl -H "Content-Type: application/json" -d '{"Job_uuid":"feew32223dd3e32re32e32", "Callernum":"18621575908", "A_gatewayname":"nway1", "A_effective_caller_id_num":"021168686868", "A_external":"true"}' -H "Authorization:Nway TOKEN" http://127.0.0.1:8085/api/originate_echo
curl -H "Content-Type: application/json" -d '{"Job_uuid":"feew32223dd3e32re32e32", "Callernum":"18621575908", "A_gatewayname":"nway1", "A_effective_caller_id_num":"021168686868", "A_external":"true","Filename":"/hold.wav"}' -H "Authorization:Nway TOKEN" http://127.0.0.1:8085/api/originate_playback
curl -H "Content-Type: application/json" -d '{"Job_uuid":"feew32223dd3e32re32e32", "Callernum":"18621575908", "A_gatewayname":"nway1", "A_effective_caller_id_num":"021168686868", "A_external":"true"}' -H "Authorization:Nway TOKEN" http://127.0.0.1:8085/api/originate_park
A_uuid A的uuid
B_uuid B的uuid
curl -H "Content-Type: application/json" -d '{"A_uuid":"aleguuid","B_uuid":"bleguuid"}' -H "Authorization:Nway token " http://192.168.1.115:8085/api/bridge
``` 同上,把uuid直接使用号码
``` curl -H "Content-Type: application/json" -d '{"A_phone":"1002","B_phone":"1003"}' -H "Authorization:Nway token " http://192.168.1.115:8085/api/bridge_phone
挂起一个号码
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/park/1002
把最后一个来电抢接过来
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/intercept/1002
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/answer/1002
EvdedPhone 被监听的号码
EvdPhone 由哪个号码监听
EvdGateway 如果是外线号码进行监听,则需要指定网关
curl -H "Content-Type: application/json" -d '{"EvdedPhone":"1002","EvdPhone":"1003","EvdGateway":""}' -H "Authorization:Nway token " http://192.168.1.115:8085/api/eavesdrop
为了减少代码量,所以使用了和监听一样的名称
EvdedPhone 邀请加入多方通话的的号码
EvdPhone 邀请加入的多方通话里有哪个号码在通话
EvdGateway 如果是外线号码,则需要指定网关
curl -H "Content-Type: application/json" -d '{"EvdedPhone":"1002","EvdPhone":"1003","EvdGateway":""}' -H "Authorization:Nway token " http://192.168.1.115:8085/api/threeway
为了减少代码量,所以使用了和监听一样的名称
EvdedPhone 被监听的的号码
EvdPhone 监听的号码
EvdGateway 如果是外线号码,则需要指定网关
curl -H "Content-Type: application/json" -d '{"EvdedPhone":"1002","EvdPhone":"1003","EvdGateway":""}' -H "Authorization:Nway token " http://192.168.1.115:8085/api/whisper
curl -H "Authorization:Nway token. . " http://192.168.1.115:8085/api/preanswer/1002
```
PhoneNumber 准备放音的号码 FilePath 语音文件路径 Loopplay 不间断循环 ``` curl -H "Content-Type: application/json" -d '{"PhoneNumber":"1002","FilePath":"D:\nwaytest.wav","Loopplay":"true"}' -H "Authorization:Nway . . " http://192.168.1.115:8085/api/playback
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/break/1002
PhoneNumber 准备录音的号码
FilePath 语音文件路径
Flag 开始就录制
Limit 0即通话哪怕是一秒也录制,如果是5,则如果通话低于5就不保存
curl -H "Content-Type: application/json" -d '{"PhoneNumber":"1002","Filepath":"nwaytestr.wav","Flag":"start","Limit":"0"}' -H "Authorization:Nway token " http://192.168.1.115:8085/api/record
``` PhoneNumber 准备发送dtmf的号码 Dtmf dtmf
``` curl -H "Content-Type: application/json" -d '{"PhoneNumber":"1002","Dtmf":"18621575908"}' -H "Authorization:Nway token " http://192.168.1.115:8085/api/senddtmf
``` PhoneNumber 目标号码 GatewayName gw名称,如果为空,则只是发到内线的 FaxFile 传真文件名,是转成的tiff文件
```
curl -H "Content-Type: application/json" -d '{"PhoneNumber":"02112345678","GatewayName":"fax","FaxFile","/tmp/av.tiff" }' -H "Authorization:Nway token " http://192.168.1.115:8085/api/send_fax
为了减少代码量,所以使用了和监听一样的名称
EvdedPhone 正在通话的号码
EvdPhone 要转出的号码
EvdGateway 如果是外线号码,则需要指定网关
```
curl -H "Content-Type: application/json" -d '{"EvdedPhone":"1002","EvdPhone":"1003","EvdGateway":""}' -H "Authorization:Nway token" http://192.168.1.115:8085/api/transfer
```
``` 参数: Uuid, FilePath, Loopplay, Channel string
curl -H "Content-Type: application/json" -d '{"PhoneNumber":"1002","FilePath":"D:\nwaytest.wav","Loopplay":"true","Channle":"aleg"}' -H "Authorization:Nway . . " http://192.168.1.115:8085/api/uuid_playback ```
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/uuid_break/uuid
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/uuid_hangup/uuid
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/uuid_park/uuid
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/uuid_hold/uuid
curl -H "Authorization:Nway token " http://192.168.1.115:8085/api/uuid_answer/uuid
``` 参数: EvdedUuid, EvdPhone, EvdGateway string
curl -H "Content-Type: application/json" -d '{"EvdedUuid":"uuid","EvdPhone":"1102","EvdGateway ":"nway1"}' -H "Authorization:Nway . . " http://192.168.1.115:8085/api/uuid_transfer ```
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","PhoneNumber":"1002","GatewayName":""}' -H "Authorization:Nway token" http://192.168.1.115:8082/api/conference_create
"/conference_create"
//由系统呼叫号码为1002的号码,不经过落地网关,IsMute为默认是禁止发方与否
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","PhoneNumber":"1002","GatewayName":"","IsMute":"false"}' -H "Authorization:Nway token" http://192.168.1.115:8082/api/conference_add
"/conference_add"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","CallerNumber":"1002"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_memberid
"/conference_memberid"
curl -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_kick_all/3000
"/conference_kick_all/:conference"
//param on/off
//level a number
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","param":"on","level":"4"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_agc
"/conference_agc"
curl -H "Authorization:Nway token. . " http://192.168.1.115:8082/api/conference_chkrecord/3000
"/conference_chkrecord"
//memberid是用getmemberid获得 //Flag |all|last|non_moderator
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":""}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_deaf
"/conference_deaf"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":"", "Dtmf":"520"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_dtmf
"/conference_dtmf"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":"", "Newval":"520"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_energy
"/conference_energy"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"3","Filename":""}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_enter_sound
"/conference_enter_sound"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"3","Filename":""}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_exit_sound
"/conference_exit_sound"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":""}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_floor
"/conference_floor"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":""}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_hup
"/conference_hup"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":""}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_kick
"/conference_kick"
curl -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_list/pretty
"/conference_list/:flag"
curl -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_lock/3000
"/conference_lock/:conference"
curl -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_unlock/3000
"/conference_unlock/:conference"
//////////////////////////////////////////
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":"","Quiet":"quiet"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_mute
"/conference_mute"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":"","Quiet":"quiet"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_unmute
"/conference_unmute"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"all"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_norecord
"/conference_norecord"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"all"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_pause
"/conference_pause"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"all"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_pin
"/conference_pin"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"all"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_play
"/conference_play"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"all"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_record
"/conference_record"
// recording start
// recording check
// recording stop |all
// recording pause
// recording resume
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"start","Filename":"/home/recording/abc.wav"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_recording
"/conference_recording"
//Flag
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Flag":"/home/recording/abc.wav"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_resume
"/conference_resume"
"/conference_say"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Param":"Value","Filename":"/home/recording/abc.wav"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_set
"/conference_set"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":""}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_stop
"/conference_stop"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":"","Quiet":"quiet"}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_tmute
"/conference_tmute"
curl -H "Content-Type: application/json" -d '{"ConferenceName":"3000","Member_id":"3","Flag":""}' -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_undeaf
"/conference_undeaf"
//////////////////////////////////////////
curl -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_nopin/3000
"/conference_nopin/:conference"
curl -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_pause_play/3000
"/conference_pause_play/:conference"
curl -H "Authorization:Nway token " http://192.168.1.115:8082/api/conferences
curl -H "Authorization:Nway token " http://192.168.1.115:8082/api/conference_members/3000