python 实现freeswitch 话单功能
1,python 搭建http 服务器
#coding=utf-8
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import json
class Resquest(SimpleHTTPRequestHandler):
def handler(self):
print("data:", self.rfile.readline().decode())
self.wfile.write(self.rfile.readline())
def do_GET(self):
print(self.requestline)
if self.path != '/hello':
self.send_error(404, "Page not Found!")
return
data = {
'result_code': '1',
'result_desc': 'Success',
'timestamp': '',
'data': {'message_id': '25d55ad283aa400af464c76d713c07ad'}
}
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps(data).encode())
def do_POST(self):
#print(self.headers)
#print(self.command)
req_datas = self.rfile.read(int(self.headers['content-length'])) #??????!
print (req_datas)
#print(req_datas.decode())
data = {
'result_code': '2',
'result_desc': 'Success',
'timestamp': '',
'data': {'message_id': '25d55ad283aa400af464c76d713c07ad'}
}
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps(data).encode('utf-8'))
if __name__ == '__main__':
host = ('127.0.0.1', 19002)
server =BaseHTTPServer.HTTPServer(host, Resquest)
print("Starting server, listen at: %s:%s" % host)
2, 配置/usr/local/freeswitch/conf/autoload_configs/xml_cdr.conf.xml
因为我本机起的http服务器,配置url为http服务器地址
配置encode为xml格式
3,如未加载 mod_xml_cdr. 可以用fs_cli -x “reload mod_xml_cdr” 加载
4,加载后,打电话挂断后,
http 服务器可以收到xml的输出
————————————————
原文链接:https://blog.csdn.net/PKU1254/article/details/102799538