⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 djsscx.pas

📁 自己写的用delphi封装东劲板卡api.
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit DjSSCx;

interface

uses
  SysUtils, Classes,DjBase,DjCBase,PubProc,uRecordcenter;

type
  //涉及到两个通道时的操作
  TOnLinkEvent = procedure(Sender:TObject;ChannelID1,ChannelID2:integer) of object;

  //内线摘机操作
  TOnHookUpEnvent = procedure(Sender:TObject;ChannelID:integer) of object ;

  //外线呼入时
  TOnDialInEvent = procedure(Sender:TObject;ChannelID:integer) of object ;

  //按键时
  TOnDTMFHitEvent = procedure(sender:TObject;ChannelID:integer;DTMFNum:string) of object;

  //异常时
  TOnDjExceptionEvent = procedure(Sender:TObject;ChannelID:integer;ErrorCode:integer;ErrorType:integer = 0) of object;
  TOnDjErrorEvent = procedure(Sender:TObject;ChannelID1,ChannelID2:integer;ErrorCode:integer) of object;

  TOnKeepEvent = procedure(Sender:TObject;KeepChnlID:integer;KeepResult:Integer) of object ;

  TBeforeGetKeepEvent = procedure(Sender:TObject;GetChnlID,KeepChnlID:integer) of object ;

  TOnGetKeepEvent = procedure(Sender:TObject;GetChnlID,KeepChnlID:integer;KeepResult:Integer) of object ;

  TOnThreeEvent = procedure(Sender:TObject;ChnlID1,ChnlID2,ChnlID3:integer) of object;

  TOnRecordEvent = procedure(Sender:TObject;Chnlid1,ChnlID2:integer;RecordFile:string) of object;

  TOnPlayFileBeginEvent=procedure(Sender:Tobject;ChnlID:integer;FileName:string) of object;

  TOnPlayFileEndEvent = procedure(Sender:Tobject;ChnlID:integer) of object;

  TDjSSCx = class(TDjCBase)
  private
    { Private declarations }
    FRecorded :boolean;
    FFirstOutNum :Shortstring;
    FFirstInNum :Shortstring;
    FSubPhoneLength:Integer;
    FPreDialNum:Shortstring;
    FIsMeet:boolean;
    FChannelList :TChannelList ;
    FRecordFilePath:Shortstring;
    FPackRate :integer;

    FOnHangUp:TOnLinkEvent;      //挂机
    FOnHookUp:TOnHookUpEnvent;   //内线摘机
    FOnDial:TOnDialInEvent ;     //外线呼入

    FOnDTMFHit:TOnDTMFHitEvent;  //接收到按键
    
    FOnException:TOnDjExceptionEvent ;  //异常

    FOnLink :TOnLinkEvent ;    //连通两条线路
    FOnClearLink:TOnLinkEvent;  //拆线

    FOnDialIn:TOnLinkEvent ;   //呼叫内线
    FOnDialBusy:TOnLinkEvent;   //被呼叫方忙
    FOnDialError:TOnLinkEvent;  //被呼叫号码错误

    FOnCallOut:TOnLinkEvent;    //外线呼出
    FOnCallBusy:TOnLinkEvent;   //呼出外线忙
    FOnCallError:TOnDjErrorEvent ; //呼出外线指定错误

    FOnKeep :TOnKeepEvent;   //当保持一个通道后
    FBeforeGetKeep :TBeforeGetKeepEvent;//当取一个保持通道前
    FOnGetKeep :TOnGetKeepEvent;   //取一个保持通道后

    FOnLinkThree:TOnThreeEvent;  //开始三方后
    FOnClearThree:TOnThreeEvent; //三方结束后

    FOnRecord : TOnRecordEvent;

    FOnPlayBegin:TOnPlayFileBeginEvent;
    FOnPlayEnd:TOnPlayFileEndEvent ;

    function InCallIn(Channel1, Channel2: PChannel):integer;overload;
    function InCallIn(ChnlID1,ChnlID2:integer):integer;overload;
    function InCallOut(Channel1, Channel2: PChannel;DialerPhone:string):integer;overload;
    procedure GetKeepChannel(ChnlIn,ChnlOut:PChannel); overload;
    function LinkThree(Channel1,Channel2:PChannel):integer;overload;  //开始一个三方
    function ClearThree(Channel1,Channel2:PChannel):integer;overload; //结束一个三方
    procedure SetFilePath(FilePath:Shortstring);
    procedure SetPackRate(aPackRate:Integer);
    //procedure test;//取保持
  protected
    { Protected declarations }
  public
    { Public declarations }
    //dfsaf:TChannelList
    constructor Create(AOwner:TComponent);override;
    destructor Destroy;override;
    procedure SetSubPhone(ChannelID:integer;Phone:String);
    procedure SetRecord(ChnlId,RecordChnlID:integer;RecordType:integer;IsAgc:boolean);
    procedure SetRecordFilePath(RecordFilePath:string);
    procedure SetUse(ChnlID:integer;IsUse:Boolean);
    function StartDjMonitor:boolean;
    procedure ReceiveDTMFHit(ChnlID:integer);
    procedure HangUp(ChnlID:Integer);       //挂机
    procedure FeedRealRing(ChnlID:Integer);
    procedure DialIn(OutChnlID,InChnlID:integer);
    function CheckDTMFNum(DTMFNum:string):integer;
    function InCallIn(ChnlID:Integer;DialPhone:String):integer;overload;
    function CheckIdleChannelState(SubPhone:string):TChannelState;
    procedure DefaultDial(ChnlID:integer;DTMFNum:string);
    function InCallOut(ChnlID:integer):Integer;overload; //与外线建立连接,手工拨号
    function InCallOut(Chnlid:integer;DTMFNum:String):integer;overload;//不建立连接,软件送号码
    function InCallOut(Chnlid:integer;CallerPhone,DTMFNum:String):integer;overload;//不不建立连接,指定外线,软件送号码
    procedure HangOff(ChnlID:Integer);  //振铃摘机坐席
    procedure OffHook(ChnlID:Integer);  //主动摘机坐席
    procedure KeepChannel(ChnlID:Integer) ;overload;//保留来电
    procedure KeepChannel(SubPhone:string) ;overload;//保留来电
    procedure GetKeepChannel(ChnlInID:integer;DTMFNum:string); overload;//取保持
    procedure GetKeepChannel(ChnlInID,ChnlOutID:integer); overload;//取保持
    procedure GetKeepChannel(ChnlInPhone,ChnlOutPhone:string); overload;//取保持
    function GetKeepChannel(KeepChannelList:Variant):integer;overload;//当前系统中保持的通道总数
    function LinkThree(ChnlID1:integer;ChnlID2:integer):integer;overload;  //开始一个三方
    function LinkThree(ChnlID:integer;CallerPhone:string):integer;overload;  //开始一个三方
    function ClearThree(ChnlId:integer;CallerPhone:string):integer;overload; //结束一个三方
    function ClearThree(ChnlId1:integer;ChnlID2:integer):integer;overload; //结束一个三方
    procedure PlayFile(ChnlID:integer;FileName:string);
    procedure StopPlayFile(ChnlId:integer);
    procedure test;
  published
    { Published declarations }
    property FirstOutNum:Shortstring read FFirstOutNum write FFirstOutNum;
    property FirstInNum :Shortstring read FFirstInNum write FFirstInNum ;
    property SubPhoneLength:integer read FSubPhoneLength write FSubPhoneLength ;
    property PreDialNum:Shortstring read FPreDialNum write FPreDialNum ;
    property IsMeet:boolean read FIsMeet write FIsMeet;
    property Recorded :boolean read FRecorded write FRecorded ;
    property RecordFilepath:Shortstring Read FRecordFilePath write SetFilePath;
    property PackRate :integer read FPackRate write SetPackRate;
    property OnHangUp : TOnLinkEvent read FOnHangUp write FOnHangUp;
    property OnHookUp : TOnHookUpEnvent read FOnHookUp write FOnHookUp ;
    property OnDial : TOnDialInEvent read FOnDial write FOnDial ;
    property OnDTMFHit:TOnDTMFHitEvent read FOnDTMFHit write FOnDTMFHit ;
    property ChannelList :TChannelList read FChannelList write FChannelList ;
    property OnException :TOnDjExceptionEvent read FOnException write FOnException;
    property OnDialIn:TOnLinkEvent read FOnDialIn write FOnDialIn ;
    property OnLink :TOnLinkEvent read FOnLink write FOnLink ;
    property OnClearLink:TOnLinkEvent read FOnClearLink write FOnClearLink;
    property OnDialBusy :TOnLinkEvent read FOnDialBusy write FOnDialBusy;
    property OnDialError:TOnLinkEvent read FOnDialError write FOnDialError ;
    property OnCallBusy :TOnLinkEvent read FOnCallBusy write FOnCallBusy ;
    property OnCallError:TOnDjErrorEvent read FOnCallError write FOnCallError ;
    property OnCallOut:TOnLinkEvent read FOnCallOut write FOnCallOut;
    property OnKeep :TOnKeepEvent read FOnKeep write FOnKeep ;
    property BeforeGetKeep:TBeforeGetKeepEvent read FBeforeGetKeep write FBeforeGetKeep;
    property OnGetKeep:TOnGetKeepEvent read FOnGetKeep write FOnGetKeep;
    property OnLinkThree:TOnThreeEvent read FOnLinkThree write FOnLinkThree;
    property OnClearThree :TOnThreeEvent read FOnClearThree write FOnClearThree ;
    property OnRecord:TOnRecordEvent read FOnRecord write FOnRecord;
    property OnPlayBegin:TOnPlayFileBeginEvent read FOnPlayBegin write FOnPlayBegin ;
    property OnPlayEnd:TOnPlayFileEndEvent read FOnPlayEnd write FOnPlayEnd;
  end;

procedure Register;

implementation

uses tc08a32,DjTc081AC,uMeetingCenter, Math;

procedure Register;
begin
  RegisterComponents('djbK', [TDjSSCx]);
end;

{ TDjSSCx }

constructor TDjSSCx.Create;
begin
  inherited;
  FPackRate := 0 ;  
end;

destructor TDjSSCx.Destroy;
begin

  inherited;
end;

procedure TDjSSCx.FeedRealRing(ChnlID: Integer);
begin
  tc08a32.FeedRealRing(ChnlID);
end;

procedure TDjSSCx.HangUp(ChnlID: Integer);
var
  Channel :PChannel;
begin
  Channel := ChannelList.Items[ChnlID];
  Channel.DialActor := MasterActor;
  DjTc081.HangUp(Channel);
end;

procedure TDjSSCx.DialIn(OutChnlID, InChnlID:integer);
var
  ChannelIn,ChannelOut: PChannel;
begin
  ChannelIn := ChannelList.Items[InChnlID];
  ChannelOut := ChannelList.Items[OutChnlID];
  if Assigned(ChannelIn) and (ChannelIn.ChannelType = UserChannel) then
  begin
    if ChannelIn.State <> Idle then
    begin
      if Assigned(FOnDialBusy) then
        FOnDialBusy(self,OutChnlID,InChnlID)
      else
        Self.HangUp(OutChnlID);
      exit;
    end;
  end
  else
  begin
    if Assigned(FOnDialError) then
      FOnDialError(Self,OutChnlID,InChnlID)
    else
      Self.HangUp(OutChnlID);
    exit;
  end;
  StartPlaySignal(OutChnlID,SIG_RINGBACK);//放回铃
  FeedRealRing(InChnlID);                 //给内线振铃
  ChannelIn.Ringing := true;
  ChannelIn.State := Dailing;
  ChannelIn.Step := 0;
  ChannelIn.ConnectChannel.ConState := OneConnect;
  ChannelIn.ConnectChannel.ConChnlId := OutChnlID ;
  ChannelIn.ConnectChannel.CallActive :=false ;
  ChannelIn.ConnectChannel.CallerPhone := ChannelOut.ConnectChannel.CallerPhone;
  ChannelIn.ConnectChannel.Channeler := nil ;

  ChannelOut.ConnectChannel.ConState := Ringing;
  ChannelOut.ConnectChannel.ConChnlId := InChnlID;
  ChannelOut.ConnectChannel.CallActive := false;
  ChannelOut.ConnectChannel.Channeler := nil ;

  ChannelOut.Step := 1001 ;
  if Assigned(FOnDialIn) then
  begin
    FOnDialIn(self,OutChnlID,InChnlID);
  end;
end;

procedure TDjSSCx.ReceiveDTMFHit(ChnlID: integer);
var
  Channel:PChannel;
begin
  //StartPlaySignal(ChnlID, SIG_DIALTONE);
  Channel := ChannelList.Items[ChnlID];
  case  Channel.ChannelType of
    UserChannel:
    begin
      StartPlaySignal(ChnlID, SIG_DIALTONE);
    end;
    TrunkChannel:
    begin
      Tc08a32.OffHook(ChnlID);
    end;
  end;
  InitDtmfBuf(ChnlID); 

  Channel.Step := 100 ;
  //Channel.state := occupy;
end;

procedure TDjSSCx.SetSubPhone(ChannelID: integer; Phone: String);
var
  Channel:PChannel;
begin
  Channel := ChannelList.items[ChannelID] ;
  Channel.Phone := Phone ;
end;

function TDjSSCx.StartDjMonitor: boolean;
begin
  if not Assigned(DjTc081) then
  begin
    DjTc081 := TDjTc081AC.Create(Self);
  end;
  DjTc081.InitRecordChannel; //录音初始化
  FChannelList := DjBase.ChannelList ;
  if FIsMeet then
  begin
    if not Assigned(DjMC) then
    begin
      DjMC := TDjMeetingCenter.Create(Self);
    end;
  end;
  if Recorded then
  begin
    if Not Assigned(RecordCenter) then
    begin
      RecordCenter := TRecordCenter.Create ;
      RecordCenter.RecordPath := FRecordFilePath ;
    end;
  end;
end;

function TDjSSCx.CheckDTMFNum(DTMFNum: string): integer;
var
  Channel:PChannel ;
  SubPhone:string;
begin
  result := 0 ;
  if FFirstOutNum = FFirstInNum then
    raise Exception.Create('内线与外线预拨号码重复,不能区分内线/外线');
  if DTMFNum = FirstOutNum then
  Begin
    Result := 1;
    exit;
  end;
  if Length(DTMFNum) > Length(FFirstInNum) then
    if copy(DTMFNum,1,length(FFirstInNum)) = FFirstInNum then
    begin
      SubPhone := copy(DTMFNum,length(FFirstInNum)+1,Length(DTMFNum)- Length(FFirstInNum));
      Channel := ChannelList.GetChannelFromPhone(SubPhone);
      if Assigned(Channel) then
        Result := 2
      else
        if Length(DTMFNum) >= SubPhoneLength then
          result := -1 ;
    end
    else
      Result := -1;
end;

function TDjSSCx.InCallIn(ChnlID: Integer; DialPhone: String): integer;
var
  Channel:PChannel;
  SubPhone:string;
begin
  SubPhone := copy(DialPhone,Length(FFirstInNum)+1,Length(DialPhone)-Length(FFirstInNum));
  Channel := ChannelList.GetChannelFromPhone(SubPhone);
  if not Assigned(Channel) then
   Result := -6
  else
    if Channel.ChannelType <> UserChannel then
      Result := -7
    else
      if Channel.State <> Idle then
      begin
        Result := -8;
        if Assigned(FOnCallBusy) then
          FOnCallBusy(Self,ChnlID,Channel.ChannelID)
        else
          Self.HangUp(ChnlID);
      end
      else
      begin
        if Assigned(FOnCallOut) then
          FOnCallOut(self,ChnlID,Channel.ChannelID);
        Result := InCallIn(ChannelList.Items[ChnlID],Channel);
      end;
end;

function TDjSSCx.InCallIn(Channel1, Channel2: PChannel): integer;
var
  ChnlID1,ChnlID2:integer;
begin
  ChnlID1 := Channel1.ChannelID;
  ChnlID2 := Channel2.ChannelID;
  //////FeedRealRing(ChnlID2);  屏蔽
  //Channel1.State := Calling ;
  Channel1.ConnectChannel.ConState := OneConnect ;
  Channel1.ConnectChannel.ConChnlId := ChnlID2 ;
  Channel1.ConnectChannel.CallActive := false;
  Channel1.ConnectChannel.CallerPhone := '';
  Channel1.ConnectChannel.Channeler := Channel2 ;
  Channel1.Step := 1001 ;
  Channel1.CallActor := CallerActor;
  Channel2.State := Dailing ;
  Channel2.Ringing := True ;
  Channel2.ConnectChannel.ConState := OneConnect ;
  Channel2.ConnectChannel.ConChnlId := ChnlID1;
  Channel2.ConnectChannel.CallActive := False;
  Channel2.ConnectChannel.CallerPhone := Channel1.Phone;
  Channel2.ConnectChannel.Channeler := Channel1 ;
  Channel2.Step := 0 ;
  Channel2.CallActor := DialerActor ;
  if Assigned(FOnDialIn) then
    FOnDialIn(Self,ChnlID1,ChnlID2);
  //SetLink(ChnlID1,ChnlID2);
end;

function TDjSSCx.CheckIdleChannelState(SubPhone: string): TChannelState;
var
  Channel:PChannel;
begin
  Result := NotingState;
  Channel := ChannelList.GetChannelFromPhone(SubPhone);
  if Assigned(Channel) then Result := Channel.State;
end;

procedure TDjSSCx.DefaultDial(ChnlID:integer;DTMFNum: string);
var
  ChannelIn:PChannel ;
  ChannelOut:PChannel;
  Caller :integer;
begin
  //SeatRecord := //.GetSeatFromChnlID(ChannelID);
  ChannelOut := ChannelList.Items[ChnlID];
  case  ChannelOut.ChannelType of
    TrunkChannel:
    begin
      if Length(DTMFNum) <= SubPhoneLength then
      begin
        ChannelIn := ChannelList.GetChannelFromPhone(DTMFNum);
        if ChannelIn = nil then
        begin
          if Length(DTMFNum) = SubPhoneLength then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -