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

📄 u_ctdeliver.pas

📁 电信网关平台(V3.0)
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  end;
end;
function TCPCTDeliver.ExitCT: boolean;
var
  SMGPExit: TSMGPHead;
  SMGPExit_Resp: TSMGPHead;
  temp: Longword;
begin
  Result := False;
  FillChar(SMGPExit, sizeof(TSMGPHead), 0);
  FillChar(SMGPExit_Resp, sizeof(TSMGPHead), 0);
  with SMGPExit do
  begin
    SMGPExit.PacketLength := HostToNet(sizeof(TSMGPHead));
    SMGPExit.RequestID := HostToNet(xExit);
    SMGPExit.SequenceID := HostToNet(sSequence);
  end;
  try
    if HadLogin then
      if sizeof(TSMGPHead) = CTDeliver.SendBuf(SMGPExit, sizeof(TSMGPHead), 0) then
      begin
        AddsSeq;
        StatuTxt := '【' + datetimetostr(now()) + '】SP-->CT(MO)ExitCT Request 上行连接发送退出请求...';
        synchronize(showstatu);
      end;
     if CTDeliver.WaitForData(timeout) then
     begin
       if sizeof(TSMGPHead) = CTDeliver.ReceiveBuf(SMGPExit_Resp, sizeof(TSMGPHead)) then
       begin
         temp := winsock.Htonl(SMGPExit_Resp.RequestID);
         if temp = Exit_resp then
         begin
           CTDeliver.Close;
           Result := True;
           DCanExit := True;
           StatuTxt := '【' + datetimetostr(now()) + '】MO ExitCT 上行连接退出与电信的连接';
           synchronize(showstatu);
         end;
           {else
             NOExitRespReceive(SMGPExit_Resp.RequestID,SMGPExit_Resp.SequenceID,SMGPExit_Resp.PacketLength);}
       end;
     end
     else
     begin
       CTDeliver.Close;
       DCanExit := True;
       Result := True;
       StatuTxt := '【' + datetimetostr(now()) + '】MO ExitCT Request 上行连接发送退出请求超时,连接已经关闭';
       synchronize(showstatu);
     end;
  except
  end;
end;

function TCPCTDeliver.ReceiveTLVMsg(const MsgLen: integer; var LinkID:string;var DealReslt:byte):byte;
var
  tmpbuf:array of char;
  tag, Len:word;
  pos:integer;
  value:array of char;
begin
  SetLength(tmpbuf,MsgLen);
  result:=0;
  DealReslt:=0;
  if CTDeliver.ReceiveBuf(tmpbuf[0], MsgLen) = MsgLen then  //接收所有可选参数
  begin
    pos:=0;
    while(pos < MsgLen)do
    begin
      Len:=0;
      tag:=0;
      Move(tmpbuf[pos], tag, 2);
      Move(tmpbuf[pos+2], Len, 2);
      tag:=htons(tag);//标签
      len:=htons(len);
      SetLength(value,len);
      Move(tmpbuf[pos+4], value[0], Len);
      case tag of
        TLV_Lab_LinkID:
        begin
          //CopyMemory(@LinkID, @value, len);
          setLength(LinkID, len);
          Move(value[0],LinkID[1], len);
        end;
        TLV_Lab_SubmitMsgType:// 13 是同步定购, 15 是同步定购回复 0是正常上行
        begin
          //CopyMemory(@Result, @Value, 1);
          Move(value[0], Result, 1);
        end;
        TLV_Lab_SPDealReslt: //同步定购处理结果 0 成功,1 失败
        begin
          //CopyMemory(@DealReslt, @Value,1);
          Move(value[0], DealReslt, 1);
        end;
      end;
      value:=nil;
      inc(pos,4 + Len);
    end;
  end; 
  tmpbuf:=nil;
end;

//截取同步消息中的短信内容的业务代码,还有:号前面的部分
procedure TCPCTDeliver.DealWithSyncMsgCont(const msgcontent: string;
  var ServiceID, MsgContPart: string);
var
  pos1,pos2:integer;
begin
//  DG+空格+业务代码+双空格+受惠用户的终端号码+冒号+用户输入的内容
// DG mbqy010500  05974581934:05911234567
//  QX+空格+业务代码+双空格+受惠用户的终端号码+冒号+用户输入的内容
  if msgcontent ='00000' then
  begin
    ServiceID := msgcontent;
    FServiceID := msgcontent;
    MsgContPart := msgcontent;
    exit;
  end;
  pos1:=AnsiPos(#32,  msgcontent);
  pos2:=AnsiPos(#32#32,  msgcontent);
  ServiceID := MidStr(msgcontent, pos1+1, pos2-pos1-1);
  FServiceID := ServiceID;
  pos1:= AnsiPos(':',  msgcontent);
  if pos1=0 then
    MsgContPart := msgcontent
  else
    MsgContPart:= MidStr(msgcontent, 1, pos1-1);// 截取冒号前面得字串
end;
//截取用户输入得短信内容,
function TCPCTDeliver.GetInstruct(const msgcontent: string): string;
var
  pos:integer;
begin
  if msgcontent ='00000' then //正向取消所有业务得时候
  begin
    result:= msgcontent;
    exit;
  end;
  pos:=AnsiPos(':',  msgcontent);
  if pos=0 then
    result:= msgcontent
  else
    result:=strutils.RightStr(msgcontent, length(msgcontent)-pos);
end;

procedure TCPCTDeliver.AddSyncOrdCelMsg(aDeliver: TCTDeliver;const LinkID:string);
var
  PSubmit: PxSubmit;
  srcMsg, ServiceID, MsgContent:string;
begin
  srcMsg:=Copy(aDeliver.MsgContent, 0, aDeliver.MsgLength);
  DealWithSyncMsgCont(srcMsg, ServiceID, MsgContent);
  new(PSubmit);
  PSubmit^.Resend := 0;
  PSubmit^.SequenceID := 0;
  PSubmit^.Then_DateTime := 0;
  PSubmit^.sSubmit.Mid := 'syc'+Formatdatetime('MMDDHHNNSS',now());
  PSubmit^.sSubmit.MsgType := 6;
  PSubmit^.sSubmit.NeedReport := 0;
  PSubmit^.sSubmit.Priority := 0;
  PSubmit^.sSubmit.ServiceID := ServiceID;//业务代码用短信内容体里的业务代码
  PSubmit^.sSubmit.FeeType := '0';
  PSubmit^.sSubmit.FeeCode := '0';
  PSubmit^.sSubmit.FixedFee := '0';
  PSubmit^.sSubmit.MsgFormat := 15;
  PSubmit^.sSubmit.SrcTermID := aDeliver.DestTermID;
  PSubmit^.sSubmit.ChargeTermID := aDeliver.SrcTermID;
  PSubmit^.sSubmit.DestTermIDCount := 1;
  PSubmit^.sSubmit.DestTermID := aDeliver.SrcTermID;
  PSubmit^.sSubmit.MsgLength := Length(MsgContent);
  PSubmit^.sSubmit.LinkID := LinkID;
  PSubmit^.sSubmit.MsgContent := MsgContent;//StringReplace(aSubmit.MsgContent, #13, '', [rfReplaceAll]); //去除回车符
  PSubmit^.sSubmit.SubmitMsgType := 15;  
  SubmitList.Add(PSubmit);
end;

procedure TCPCTDeliver.ReceiveBody(CTRequestID, CTsequence, Len: Longword);
begin
  if CTDeliver.Connected then
  begin
    Active_test_time := now;
    if Active_test_resp = CTRequestID then
    begin {//电信发送链路测试回复}
      StatuTxt := '【' + datetimetostr(now) + '】(MO)Active_Test_Resp 电信回复上行链路正常...' + inttostr(CTsequence);
      LogList.AddLog('08' + StatuTxt);
      synchronize(showstatu);
      //提示信息
      if (MinutesBetween(now, LastSendWarnMsgTime) >= NoReceiveDeliver) and (MinutesBetween(now, ReceiveDeliverTime) >= NoReceiveDeliver) and (SendWarn) and (Counter < SendCount) then
      begin
        LogList.AddLog('10' + '电信网关于上次上行或登陆时间' + datetimetostr(ReceiveDeliverTime) + '到目前时间' + datetimetostr(now) + '已经超过' + inttostr(MinutesBetween(now, ReceiveDeliverTime)) + '分钟没有上行,请相关人员注意运行情况(系统将连续提醒' + inttostr(SendCount) + '次)');
        inc(Counter);
        if Counter = SendCount then
        begin
          LastSendWarnMsgTime := now;
          Counter := 0;
        end;
      end;
    end
    else if Deliver = CTRequestID then
    begin {//上行短信}
      ReceiveDeliver(CTsequence, Len);
      {ReceiveDeliverTime := now;
      Counter := 0;
      if 69 = CTDeliver.ReceiveBuf(xDeliver, 69) then
        if xDeliver.MsgLength = CTDeliver.ReceiveBuf(xDeliver.MsgContent, xDeliver.MsgLength) then
          if 8 = CTDeliver.ReceiveBuf(xDeliver.Reserve, 8) then
          begin    //再收可选参数
            if (len - sizeof(CTSMSHeader) > 69+ xDeliver.MsgLength + 8) then
            begin//接收可选参数
              SubmitMsgType := ReceiveTLVMsg(len - (77 + xDeliver.MsgLength), LinkID, DealResult)
            end;
            SP_Deliver_Resp(xDeliver.Msgid, CTsequence); //上行短信回馈CP-->CT
            isRep := xDeliver.IsReport;
            if isRep = 1 then //状态报告
              WriteReport(xDeliver.Msgid, xDeliver.MsgContent)
            else
            begin
              msg:=Copy(xDeliver.MsgContent,0, xDeliver.MsgLength);
              case SubmitMsgType of
                13://需要回复15的下行, SubmitMsgType = 15,LinkID也需要, 内容体为"DG+空格+业务代码+双空格+受惠用户的终端号码
                   //还需要再把短信内容只取用户输入的内容部分
                   begin //正向定制,取消
                     AddSyncOrdCelMsg(xDeliver, LinkID);//写入submit队列,                     
                     FillChar(xDeliver.MsgContent,sizeof(xDeliver.MsgContent),0);
                     StrpCopy(xDeliver.MsgContent, GetInstruct(msg));  //上行短信内容改为用户输入内容
                   end;
                15://反向定制,取消回复,需要把 ReSycQX+1个空格+ 上内容 + 1个空格 + DealReslt
                   begin
                      FillChar(xDeliver.MsgContent,sizeof(xDeliver.MsgContent),0);
                      StrpCopy(xDeliver.MsgContent, 'ReSyc '+ msg + #32 + inttostr(DealResult));
                   end;
              end;
              SaveToDeliverList(xDeliver, LinkID);
              synchronize(AddCou);
              showDeliver(xDeliver,LinkID);
            end; }
            {try
             fs:=Tfilestream.create( 'd:\Stream\D'+formatdatetime('ddhhnnss',now)+'.txt',fmCreate	);
             fs.WriteBuffer(xDeliver,sizeof(xDeliver));
            finally
             fs.free;
            end;}
//          end;
    end
    else if Active_test = CTRequestID then
    begin {电信发送上行链路检测包}
      StatuTxt := '【' + datetimetostr(now) + '】CT-->SP(MO)ActiveTest 电信发送上行链路测试 ' + inttostr(CTsequence);
      synchronize(showstatu);
      MO_ActiveTest_Resp(CTsequence);
    end
    else if Exit_resp = CTRequestID then
    begin {退出回复}
      CTDeliver.Close;
      DCanExit := True;
      StatuTxt := '【' + datetimetostr(now()) + '】MO ExitCT --> 上行链路退出与中国电信的连接';
      LogList.AddLog('11' + StatuTxt);
      synchronize(showstatu);
      SockCanExit := True;
      MOExit := False;
    end
    else
    begin //错误的包头命令字
      {try
        setlength(ErrMsg, Len - 12);
        CTDeliver.ReceiveBuf(ErrMsg, Len - 12);
        ErrMsg := nil;
      except
      end;
      StatuTxt := '【' + datetimetostr(now()) + '】MO 接收到类型错误的消息包';
      synchronize(showstatu); }
      CTDeliver.Close;
    end;
  end;
end;

procedure TCPCTDeliver.MOSocketError(Sender: TObject; SocketError: integer);
var
  Error: integer;

⌨️ 快捷键说明

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