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格式

<param name="url" value="http://localhost:19002"/>

<param name="encode" value="textxml"/>

3,如未加載 mod_xml_cdr. 可以用fs_cli -x "reload mod_xml_cdr"  加載

4,加載後,打電話掛斷後,

http 服務器可以收到xml的輸出

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章