Selaa lähdekoodia

基础信令定义

刘威 6 kuukautta sitten
vanhempi
commit
1905062895
24 muutettua tiedostoa jossa 491 lisäystä ja 12 poistoa
  1. 177 0
      python-ESL-1.4.18/build/lib.macosx-10.9-x86_64-cpython-38/ESL.py
  2. BIN
      python-ESL-1.4.18/build/lib.macosx-10.9-x86_64-cpython-38/_ESL.cpython-38-darwin.so
  3. BIN
      python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/ESL_wrap.o
  4. BIN
      python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl.o
  5. BIN
      python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_buffer.o
  6. BIN
      python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_config.o
  7. BIN
      python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_event.o
  8. BIN
      python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_json.o
  9. BIN
      python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_oop.o
  10. BIN
      python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_threadmutex.o
  11. BIN
      python-ESL-1.4.18/dist/python_ESL-1.4.18-py3.8-macosx-10.9-x86_64.egg
  12. BIN
      src/__pycache__/__init__.cpython-39.pyc
  13. BIN
      src/core/__pycache__/__init__.cpython-39.pyc
  14. BIN
      src/core/callcenter/__pycache__/__init__.cpython-39.pyc
  15. 5 0
      src/core/callcenter/call.py
  16. 147 11
      src/core/callcenter/client.py
  17. BIN
      src/core/callcenter/constant/__pycache__/constant.cpython-38.pyc
  18. 1 0
      src/core/callcenter/constant/constant.py
  19. 2 0
      src/core/callcenter/handler/channel_park_handler.py
  20. 76 0
      src/core/callcenter/model.py
  21. 6 0
      src/core/callcenter/server.py
  22. BIN
      src/core/callcenter/utils/__pycache__/call_cache_util.cpython-38.pyc
  23. 77 0
      src/core/callcenter/utils/call_cache_util.py
  24. 0 1
      src/core/datasource.py

+ 177 - 0
python-ESL-1.4.18/build/lib.macosx-10.9-x86_64-cpython-38/ESL.py

@@ -0,0 +1,177 @@
+# This file was automatically generated by SWIG (https://www.swig.org).
+# Version 4.2.1
+#
+# Do not make changes to this file unless you know what you are doing - modify
+# the SWIG interface file instead.
+
+from sys import version_info as _swig_python_version_info
+# Import the low-level C/C++ module
+if __package__ or "." in __name__:
+    from . import _ESL
+else:
+    import _ESL
+
+try:
+    import builtins as __builtin__
+except ImportError:
+    import __builtin__
+
+def _swig_repr(self):
+    try:
+        strthis = "proxy of " + self.this.__repr__()
+    except __builtin__.Exception:
+        strthis = ""
+    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
+
+
+def _swig_setattr_nondynamic_instance_variable(set):
+    def set_instance_attr(self, name, value):
+        if name == "this":
+            set(self, name, value)
+        elif name == "thisown":
+            self.this.own(value)
+        elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
+            set(self, name, value)
+        else:
+            raise AttributeError("You cannot add instance attributes to %s" % self)
+    return set_instance_attr
+
+
+def _swig_setattr_nondynamic_class_variable(set):
+    def set_class_attr(cls, name, value):
+        if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
+            set(cls, name, value)
+        else:
+            raise AttributeError("You cannot add class attributes to %s" % cls)
+    return set_class_attr
+
+
+def _swig_add_metaclass(metaclass):
+    """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
+    def wrapper(cls):
+        return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
+    return wrapper
+
+
+class _SwigNonDynamicMeta(type):
+    """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
+    __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
+
+
+class ESLevent(object):
+    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
+    __repr__ = _swig_repr
+    event = property(_ESL.ESLevent_event_get, _ESL.ESLevent_event_set)
+    serialized_string = property(_ESL.ESLevent_serialized_string_get, _ESL.ESLevent_serialized_string_set)
+    mine = property(_ESL.ESLevent_mine_get, _ESL.ESLevent_mine_set)
+
+    def __init__(self, *args):
+        _ESL.ESLevent_swiginit(self, _ESL.new_ESLevent(*args))
+    __swig_destroy__ = _ESL.delete_ESLevent
+
+    def serialize(self, format=None):
+        return _ESL.ESLevent_serialize(self, format)
+
+    def setPriority(self, *args):
+        return _ESL.ESLevent_setPriority(self, *args)
+
+    def getHeader(self, header_name, idx=-1):
+        return _ESL.ESLevent_getHeader(self, header_name, idx)
+
+    def getBody(self):
+        return _ESL.ESLevent_getBody(self)
+
+    def getType(self):
+        return _ESL.ESLevent_getType(self)
+
+    def addBody(self, value):
+        return _ESL.ESLevent_addBody(self, value)
+
+    def addHeader(self, header_name, value):
+        return _ESL.ESLevent_addHeader(self, header_name, value)
+
+    def pushHeader(self, header_name, value):
+        return _ESL.ESLevent_pushHeader(self, header_name, value)
+
+    def unshiftHeader(self, header_name, value):
+        return _ESL.ESLevent_unshiftHeader(self, header_name, value)
+
+    def delHeader(self, header_name):
+        return _ESL.ESLevent_delHeader(self, header_name)
+
+    def firstHeader(self):
+        return _ESL.ESLevent_firstHeader(self)
+
+    def nextHeader(self):
+        return _ESL.ESLevent_nextHeader(self)
+
+# Register ESLevent in _ESL:
+_ESL.ESLevent_swigregister(ESLevent)
+class ESLconnection(object):
+    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
+    __repr__ = _swig_repr
+
+    def __init__(self, *args):
+        _ESL.ESLconnection_swiginit(self, _ESL.new_ESLconnection(*args))
+    __swig_destroy__ = _ESL.delete_ESLconnection
+
+    def socketDescriptor(self):
+        return _ESL.ESLconnection_socketDescriptor(self)
+
+    def connected(self):
+        return _ESL.ESLconnection_connected(self)
+
+    def getInfo(self):
+        return _ESL.ESLconnection_getInfo(self)
+
+    def send(self, cmd):
+        return _ESL.ESLconnection_send(self, cmd)
+
+    def sendRecv(self, cmd):
+        return _ESL.ESLconnection_sendRecv(self, cmd)
+
+    def api(self, cmd, arg=None):
+        return _ESL.ESLconnection_api(self, cmd, arg)
+
+    def bgapi(self, cmd, arg=None, job_uuid=None):
+        return _ESL.ESLconnection_bgapi(self, cmd, arg, job_uuid)
+
+    def sendEvent(self, send_me):
+        return _ESL.ESLconnection_sendEvent(self, send_me)
+
+    def sendMSG(self, send_me, uuid=None):
+        return _ESL.ESLconnection_sendMSG(self, send_me, uuid)
+
+    def recvEvent(self):
+        return _ESL.ESLconnection_recvEvent(self)
+
+    def recvEventTimed(self, ms):
+        return _ESL.ESLconnection_recvEventTimed(self, ms)
+
+    def filter(self, header, value):
+        return _ESL.ESLconnection_filter(self, header, value)
+
+    def events(self, etype, value):
+        return _ESL.ESLconnection_events(self, etype, value)
+
+    def execute(self, app, arg=None, uuid=None):
+        return _ESL.ESLconnection_execute(self, app, arg, uuid)
+
+    def executeAsync(self, app, arg=None, uuid=None):
+        return _ESL.ESLconnection_executeAsync(self, app, arg, uuid)
+
+    def setAsyncExecute(self, val):
+        return _ESL.ESLconnection_setAsyncExecute(self, val)
+
+    def setEventLock(self, val):
+        return _ESL.ESLconnection_setEventLock(self, val)
+
+    def disconnect(self):
+        return _ESL.ESLconnection_disconnect(self)
+
+# Register ESLconnection in _ESL:
+_ESL.ESLconnection_swigregister(ESLconnection)
+
+def eslSetLogLevel(level):
+    return _ESL.eslSetLogLevel(level)
+

BIN
python-ESL-1.4.18/build/lib.macosx-10.9-x86_64-cpython-38/_ESL.cpython-38-darwin.so


BIN
python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/ESL_wrap.o


BIN
python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl.o


BIN
python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_buffer.o


BIN
python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_config.o


BIN
python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_event.o


BIN
python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_json.o


BIN
python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_oop.o


BIN
python-ESL-1.4.18/build/temp.macosx-10.9-x86_64-cpython-38/esl_threadmutex.o


BIN
python-ESL-1.4.18/dist/python_ESL-1.4.18-py3.8-macosx-10.9-x86_64.egg


BIN
src/__pycache__/__init__.cpython-39.pyc


BIN
src/core/__pycache__/__init__.cpython-39.pyc


BIN
src/core/callcenter/__pycache__/__init__.cpython-39.pyc


+ 5 - 0
src/core/callcenter/call.py

@@ -1,3 +1,8 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
+
+class CallService:
+
+    def __init__(self):
+        pass

+ 147 - 11
src/core/callcenter/client.py

@@ -13,6 +13,9 @@ import socketserver
 import concurrent.futures
 from http.server import BaseHTTPRequestHandler
 from http.server import HTTPServer
+import src.core.callcenter.utils.call_cache_util as CacheUtil
+from src.core.callcenter.constant.constant import AT, CO, SK, saasId
+from src.core.callcenter.constant.esl_constant import SIP_HEADER, SPLIT, SOFIA, ORIGINATE, PARK
 import src.core.callcenter.utils.esl_event_util as EslEventUtil
 import src.core.callcenter.handler as event_handler
 from src.core.callcenter.handler.default_esl_event_handler import DefaultEslEventHandler
@@ -26,9 +29,11 @@ class InboundClient:
         self.is_stopping = False
         self.handler_table = self.scan_esl_event_handlers()
         self.default_event_handler = DefaultEslEventHandler(self)
+        self.host, self.port, self.password = 'localhost', '8021', '4918257983818884358'
         self.executors = {x: concurrent.futures.ThreadPoolExecutor(max_workers=1) for x in range(self.thread_num)}
 
-        self.host, self.port, self.password = 'localhost', '8021', '4918257983818884358'
+        gw = CacheUtil.getRouteGetway(saasId)
+        self.make_call(gw, '63366692', '13241676588', 'C111111111', 'D1111111')
 
     def scan_esl_event_handlers(self):
         import inspect
@@ -54,7 +59,7 @@ class InboundClient:
         self.con = ESL.ESLconnection(self.host, self.port, self.password)
         if self.con.connected():
             print('inbound esl connected ... ')
-            self.con.events('plain', 'all')
+            self.con.events('plain', 'all') #CHANNEL_ORIGINATE,CHANNEL_PROGRESS,CHANNEL_PROGRESS_MEDIA,CHANNEL_ANSWER,CHANNEL_HANGUP,CUSTOM,PLAYBACK_START,PLAYBACK_STOP,DETECTED_TONE
             while not self.is_stopping:
                 e = self.con.recvEvent()
                 # if e:
@@ -106,7 +111,147 @@ class InboundClient:
         except:
             traceback.print_exc()
 
+    def make_call(self, route_gateway, display, called, call_id, device_id, timeout=30, originate_timeout=30, *sip_headers):
+
+        # called = f"{called}{AT}{route_gateway.media_host}{CO}{route_gateway.media_port}"
+        if route_gateway.caller_prefix:
+            display = f"{route_gateway.caller_prefix}{display}"
+        if route_gateway.called_prefix:
+            called = f"{route_gateway.called_prefix}{called}"
+
+        sip_buffer = []
+        if sip_headers:
+            sip_buffer = [f"{SIP_HEADER}{header}" for header in sip_headers]
+
+        params = {
+            "callId": call_id,
+            "deviceId": device_id,
+            "caller": display,
+            "called": called,
+        }
+
+        if route_gateway.sip_header1:
+            sip_header1 = self.expression(route_gateway.sip_header1, params)
+            sip_buffer.append(f"{SIP_HEADER}{sip_header1}")
+
+        if route_gateway.sip_header2:
+            sip_header2 = self.expression(route_gateway.sip_header2, params)
+            sip_buffer.append(f"{SIP_HEADER}{sip_header2}")
+
+        if route_gateway.sip_header3:
+            sip_buffer.append(f"{SIP_HEADER}{route_gateway.sip_header3}")
+
+        builder = [
+            "{return_ring_ready=true,",
+            f"sip_contact_user={display},",
+            "ring_asr=true,",
+            "absolute_codec_string=codecs,",  # Assuming codecs is defined somewhere
+            f"origination_caller_id_number={display},",
+            f"origination_caller_id_name={display},",
+            f"origination_uuid={device_id},",
+        ]
+
+        if originate_timeout:
+            builder.append(f"originate_timeout={originate_timeout},")
+
+        if sip_buffer:
+            builder.append(f"{SPLIT}".join(sip_buffer))
+
+        builder.append("}")
+        builder.append(f"{SOFIA}{SK}{route_gateway.profile}{SK}{called}{PARK}")
+        cmd = "".join(builder)
+        print(cmd)
+        # self.con.bgapi(ORIGINATE, cmd)
+
+    def call_timeout(self, call_id, device_id, timeout):
+        """呼叫超时主动挂机"""
+        pass
+
+    def send_args(self, device_id, name, arg):
+        msg = ESL.ESLevent("sendmsg", device_id)
+        msg.addHeader("call-command", "execute")
+        msg.addHeader("execute-app-name", name)
+        msg.addHeader("execute-app-arg", arg)
+        self.con.sendEvent(msg)
+
+    def bridge_call(self, call_id, device_id1, device_id2):
+        """桥接电话"""
+        pass
+
+    def transfer_call(self, _from, _to):
+        """转接"""
+        pass
+
+    def answer(self, device_id):
+        """应答"""
+        pass
+
+    def hangup_call(self, call_id, device_id):
+        """挂机"""
+        pass
+
+    def play_file(self, call_id, device_id, file):
+        """放音"""
+        pass
+
+    def broadcast(self, uuid, path, smf):
+        pass
+
+    def break0(self, uuid, all, sync):
+        pass
+
+    def hold(self, smf, uuid, display):
+        pass
+
+    def get_var(self, uuid, var):
+        pass
+
+    def set_var(self, uuid, var, val):
+        pass
+
+    def multi_set_var(self, uuid, params):
+        pass
+
+    def record(self, uuid, action, path, limit):
+        pass
+
+    def transfer(self, uuid, smf, dest, dialplan, context):
+        pass
+
+    def insert(self, device_id):
+        """强插"""
+        pass
+
+    def bridge_break(self, device_id):
+        """拆线"""
+        pass
+
+    def stop_play(self, device_id):
+        """关闭播放音乐"""
+        pass
+
+    def hold_play(self, device_id, play):
+        """向a-leg插播tts音乐(无限播放)"""
+        pass
+
+    def play_timeout(self, call_id, timeout):
+        """播放超时主动挂机"""
+        pass
+
+    def listen(self, device_id1, device_id2, aleg, bleg):
+        """监听"""
+        pass
+
+    def expression(self, template, params):
+        # Placeholder for the expression processing logic
+        for key, value in params.items():
+            template = template.replace(f"${{{key}}}", str(value))
+        return template
+
     def stop(self):
+        for k, v in self.executors.items():
+            v.shutdown()
+        self.con.disconnect()
         self.is_stopping = True
 
 
@@ -162,12 +307,3 @@ class InboundClient:
 #         with socketserver.TCPServer((HOST, PORT), self.ESLRequestHandler) as server:
 #             print(f"ESL server listening on {HOST}:{PORT}")
 #             server.serve_forever()
-
-def main():
-    on = InboundClient()
-    # out = OutboundClient()
-    # threading.Thread(target=out.start, args=()).start()
-    threading.Thread(target=on.start, args=()).start()
-
-if __name__ == '__main__':
-    main()

BIN
src/core/callcenter/constant/__pycache__/constant.cpython-38.pyc


+ 1 - 0
src/core/callcenter/constant/constant.py

@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
+saasId = "mdj"
 UTF_8 = "UTF-8"
 SPACE = " "
 EMPTY = ""

+ 2 - 0
src/core/callcenter/handler/channel_park_handler.py

@@ -16,6 +16,8 @@ class ChannelParkHandler(EslEventHandler):
         service = event.getHeader("variable_service")
         if service:
             self.process_fxo_calling(event)
+            return
+
 
     def process_fxo_calling(self, event):
         destination = '1001'

+ 76 - 0
src/core/callcenter/model.py

@@ -1,6 +1,7 @@
 #!/usr/bin/env python3
 # encoding:utf-8
 
+import json
 from urllib.parse import urlparse
 
 
@@ -62,6 +63,14 @@ class AgentInfo:
         """
         return self.fs_user is None or self.fs_user is True
 
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        return cls(**data)
+
 
 class CallInfo:
     def __init__(self, core_uuid=None, call_id=None, conference=None, company_id=None, group_id=None,
@@ -122,6 +131,14 @@ class CallInfo:
         self.next_commands = next_commands  # 执行下一步命令
         self.call_details = call_details  # 电话流程
 
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        return cls(**data)
+
     # def __repr__(self):
     #     return (f"CallInfo(core_uuid={self.core_uuid}, call_id={self.call_id}, conference={self.conference}, "
     #             f"company_id={self.company_id}, group_id={self.group_id}, hidden_customer={self.hidden_customer}, "
@@ -175,6 +192,14 @@ class DeviceInfo:
         self.record_start_time = record_start_time  # 录音开始时间
         self.state = state  # 当前设备状态
 
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        return cls(**data)
+
     # def __repr__(self):
     #     return (f"DeviceInfo(call_id={self.call_id}, conference={self.conference}, device_id={self.device_id}, "
     #             f"agent_key={self.agent_key}, agent_name={self.agent_name}, device_type={self.device_type}, "
@@ -198,6 +223,14 @@ class NextCommand:
         # 执行参数
         self.nextValue = nextValue
 
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        return cls(**data)
+
 
 class CallDetail:
     def __init__(self, id=None, cts=None, start_time=None, end_time=None, call_id=None,
@@ -217,9 +250,52 @@ class CallDetail:
         self.ext2 = ext2  # 扩展字段2
         self.status = status  # 状态
 
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        return cls(**data)
+
     # def __repr__(self):
     #     return (f"CallDetail(id={self.id}, cts={self.cts}, start_time={self.start_time}, "
     #             f"end_time={self.end_time}, call_id={self.call_id}, detail_index={self.detail_index}, "
     #             f"transfer_type={self.transfer_type}, transfer_id={self.transfer_id}, reason={self.reason}, "
     #             f"month={self.month}, ext1={self.ext1}, ext2={self.ext2}, status={self.status})")
 
+
+class RouteGateway:
+    def __init__(self, id=None, saas_id=None, cts=None, uts=None, name=None, media_host=None,
+                 media_port=None, caller_prefix=None, called_prefix=None,
+                 profile='gateway/gateway-fxo', sip_header1='P-WDH-CallId=#{[callId]}',
+                 sip_header2='P-WDH-deviceId=#{[deviceId]}', sip_header3=None, status=None):
+        self.id = id  # PK
+        self.saas_id = saas_id
+        self.cts = cts  # 创建时间
+        self.uts = uts  # 修改时间
+        self.name = name  # 号码
+        self.media_host = media_host  # 媒体地址
+        self.media_port = media_port  # 媒体端口
+        self.caller_prefix = caller_prefix  # 主叫号码前缀
+        self.called_prefix = called_prefix  # 被叫号码前缀
+        self.profile = profile  # 媒体拨号计划文件
+        self.sip_header1 = sip_header1  # SIP头1
+        self.sip_header2 = sip_header2  # SIP头2
+        self.sip_header3 = sip_header3  # SIP头3
+        self.status = status  # 状态
+
+    def to_json_string(self):
+        return json.dumps(self.__dict__, ensure_ascii=False)
+
+    @classmethod
+    def from_json(cls, json_string):
+        data = json.loads(json_string)
+        return cls(**data)
+
+    # def __repr__(self):
+    #     return (f"RouteGateway(id={self.id}, cts={self.cts}, uts={self.uts}, name={self.name}, "
+    #             f"media_host={self.media_host}, media_port={self.media_port}, caller_prefix={self.caller_prefix}, "
+    #             f"called_prefix={self.called_prefix}, profile={self.profile}, "
+    #             f"sip_header1={self.sip_header1}, sip_header2={self.sip_header2}, "
+    #             f"sip_header3={self.sip_header3}, status={self.status})")

+ 6 - 0
src/core/callcenter/server.py

@@ -1,7 +1,9 @@
 #!/usr/bin/env python3
 # encoding:utf-8
+import threading
 
 from flask import Flask
+from src.core.callcenter.client import InboundClient
 
 app = Flask(__name__)
 
@@ -103,4 +105,8 @@ def num_generate():
 
 
 if __name__ == '__main__':
+    on = InboundClient()
+    # out = OutboundClient()
+    # threading.Thread(target=out.start, args=()).start()
+    threading.Thread(target=on.start, args=()).start()
     app.run(host='127.0.0.1', port=5000, debug=True)

BIN
src/core/callcenter/utils/__pycache__/call_cache_util.cpython-38.pyc


+ 77 - 0
src/core/callcenter/utils/call_cache_util.py

@@ -0,0 +1,77 @@
+#!/usr/bin/env python3
+# encoding:utf-8
+
+import json
+from src.core.callcenter.constant.constant import *
+from src.core.callcenter.model import AgentInfo, CallInfo, RouteGateway
+from src.core.datasource import RedisHandler
+
+cacheDay = 7
+deviceCall = {}
+redis_handler = RedisHandler()
+print(redis_handler.redis.info())
+
+
+def getAgentInfo(agentKey):
+    text = redis_handler.get(AGENT_INFO + agentKey)
+    if not text:
+        return None
+    return AgentInfo.from_json(text)
+
+
+def refleshAgentToken(agentKey, token):
+    redis_handler.set(AGENT_TOKEN + token, agentKey, cacheDay*24*60*60)
+
+
+def deleteKey(key):
+    redis_handler.redis.delete(key)
+
+
+def getAgentKey(token):
+    return redis_handler.get(AGENT_TOKEN + token)
+
+
+# 缓存坐席
+def addAgentInfo(agentInfo: AgentInfo):
+    redis_handler.set(AGENT_INFO + agentInfo.agent_number, json.dumps(agentInfo), cacheDay*24*60*60)
+
+
+# 缓存CALL_INFO
+def addCallInfo(callInfo: CallInfo):
+    redis_handler.set(AGENT_INFO + callInfo.call_id, json.dumps(callInfo), cacheDay*24*60*60)
+
+
+def getCallInfoByDeviceId(deviceId):
+    callId = deviceCall.get(deviceId)
+    if not callId:
+        return getCallInfo(callId)
+
+
+# 获取callInfo
+def getCallInfo(callId):
+    text = redis_handler.get(CALL_INFO+callId)
+    if not text:
+        return CallInfo.from_json(text)
+
+
+def removeCallInfo(callId):
+    callInfo = getCallInfo(callId)
+    if callInfo and callInfo.device_info_map:
+        for k, v in callInfo.device_info_map.items():
+            deviceCall.pop(k)
+    deleteKey(CALL_INFO + callId)
+
+
+def addDevice(device, callId):
+    deviceCall[device] = callId
+
+
+def getRouteGetway(saasId):
+    return RouteGateway(id=1,
+                        saas_id=saasId,
+                        name='63366692',
+                        media_host='192.168.20.99',
+                        media_port=5060,
+                        caller_prefix='',
+                        called_prefix='',
+                        status=0)

+ 0 - 1
src/core/datasource.py

@@ -11,7 +11,6 @@ import traceback
 import pymysql
 import os
 from redis import StrictRedis, ConnectionPool
-from src.core.constant import *
 
 # from constant import *