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

📄 main.~pas

📁 cmpp协议的delphi解析cmpp协议的点歌系统
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
               logrec.s_oper :='CmppRead_CONNECT操作';
               logrec.s_result :='失败';
               logrec.s_errcode :='0';
               logrec.s_err :=e.Message;
               logrec.s_time :=FormatDateTime('yyyy-mm-dd hh:mm:ss',now);
               WriteLog();
            end;

            memo1.Lines.Add( '发送CONNECT操作失败,错误信息' + e.Message+#13#10 );
    end;
    end; //try-except
end;

procedure TFrmMain.CmppRead_TERMINATE(ReadSock: TCustomWinSocket;
  Cmpp_Head: tCMPP_HEAD_tag);
type
    T_init = packed record
        head: TCMPP_HEAD_tag;
        body: TCMPP_TERMINATE_RESP_tag;
    end;
var
   bInit:T_init;
   i,int1,int2,int3:integer;
   sp_code,sp_address:string;
begin
        //取sp的source_addr
        for i:=0 to aryclientnum do
        begin
          if aryclient[i].CHandle = ReadSock.SocketHandle  then
          begin
              memo1.Lines.Add( '收到断开信息,'+
             'sp代码:'+sp_code+
             'sp地址:'+sp_address+
             '连接句柄:'+inttostr(aryclient[i].CHandle)+
             '当前时间:'+formatdatetime('yyyy-mm-dd hh:mm:ss',now)+
             '正在发送响应信息'+#13#10 );

             sp_code:=aryclient[i].CSP;
             sp_address:=aryclient[i].CAddress ;
             memo1.Lines.Add( 'SP代码:'+aryclient[i].CSP+' 地址:'+aryclient[i].CAddress +' 退出连接'+#13#10 );
             aryclient[i].CSP := '';
             aryclient[i].IsLogin :=false;
          end;
        end;
  try
        int1 := SizeOf( TCMPP_HEAD_tag );
        int2 := SizeOf( TCMPP_TERMINATE_RESP_tag );
        int3 := int1 + int2;

        FillChar( bInit.head, int1, 0 );
        FillChar( bInit.body, int2, 0 );

        bInit.head.Total_Length := htonl( int3 );
        bInit.head.Command_ID := htonl( CMPP_TERMINATE_RESP );
        bInit.head.Sequence_ID := Cmpp_Head.Sequence_ID ;

        if ReadSock.SendBuf( bInit, int3 ) <> int3 then
        begin
            exit;
        end;

        if LogRec.s_time='' then
        begin
             logrec.s_funcname:='CmppRead_TERMINATE';
             logrec.s_oper :='sp:'+sp_code+' 地址:'+sp_address+'退出登录!';
             logrec.s_result :='成功';
             logrec.s_errcode :='0';
             logrec.s_err :='';
             logrec.s_time :=FormatDateTime('yyyy-mm-dd hh:mm:ss',now);
             WriteLog();
        end;
  except on e:exception do
  begin
            if LogRec.s_time='' then
            begin
               logrec.s_funcname:='CmppRead_TERMINATE';
               logrec.s_oper :='CmppRead_TERMINATE操作';
               logrec.s_result :='失败';
               logrec.s_errcode :='0';
               logrec.s_err :=e.Message;
               logrec.s_time :=FormatDateTime('yyyy-mm-dd hh:mm:ss',now);
               WriteLog();
            end;

        memo1.Lines.Add( '发送TERMINATE操作失败,错误信息' + e.Message+#13#10 );
  end;
  end;
end;

procedure TFrmMain.CmppRead_BROCKEN(ReadSock: TCustomWinSocket;
  Cmpp_Head: tCMPP_HEAD_tag);
begin
  ServerSocket1.Close ;
  application.Terminate ;
  exit;
end;

procedure TFrmMain.CmppRead_ACTIVE_TEST(ReadSock: TCustomWinSocket;
  Cmpp_Head: tCMPP_HEAD_tag);
type
    T_init = packed record
        head: TCMPP_HEAD_tag;
        body: TCMPP_ACTIVE_TEST_RESP_tag;
    end;
var
   bInit:T_init;
   int1,int2,int3:integer;
begin
try
        int1 := SizeOf( TCMPP_HEAD_tag );
        int2 := SizeOf( TCMPP_ACTIVE_TEST_RESP_tag );
        int3 := int1 + int2;

        FillChar( bInit.head, int1, 0 );
        FillChar( bInit.body, int2, 0 );

        bInit.head.Total_Length := htonl( int3 );
        bInit.head.Command_ID := htonl( CMPP_ACTIVE_TEST_RESP );
        bInit.head.Sequence_ID := Cmpp_Head.Sequence_ID ;

        if ReadSock.SendBuf( bInit, int3 ) <> int3 then
        begin
            memo1.Lines.Add('发送ACTIVE_TEST_RESP消息失败!'+#13#10);
            exit;
        end;
except on e:exception do
begin
            if LogRec.s_time='' then
            begin
               logrec.s_funcname:='CmppRead_ACTIVE_TEST';
               logrec.s_oper :='CmppRead_ACTIVE_TEST操作';
               logrec.s_result :='失败';
               logrec.s_errcode :='0';
               logrec.s_err :=e.Message;
               logrec.s_time :=FormatDateTime('yyyy-mm-dd hh:mm:ss',now);
               WriteLog();
            end;
end;
end;
end;

procedure TFrmMain.CmppRead_ACTIVE_RESP_TEST(ReadSock: TCustomWinSocket;
  Cmpp_Head: tCMPP_HEAD_tag);
begin
{
        int3 := SizeOf( TCMPP_ACTIVE_TEST_RESP_tag );

        FillChar( bInit, int3, 0 );
        rev:=ReadSock.ReceiveBuf(bInit, int3);

        if  rev<> int3 then
        begin
           Memo1.Lines.Add('接收ACTIVE_TEST_RESP消息失败!'+'rev:='+inttostr(rev)+'int3:='+inttostr(int3));
           exit;
        end;
        }
end;

procedure TFrmMain.CmppRead_DELIVER_RESP( ReadSock: TCustomWinSocket;
    Cmpp_Head: tCMPP_HEAD_tag );
var
    bInit:TCMPP_DELIVER_RESP_tag;
    int1: integer;
    SqlStr:string;
    //timestr: string;
    interr:Integer;
begin
    try
        int1 := SizeOf( bInit );
        FillChar(bInit, int1, 0 );

         interr:=ReadSock.ReceiveBuf(bInit, int1);

        if interr <> int1 then
        begin
           Memo1.Lines.Add('接收DELIVER_RESP的包体出错' + '长度   '+IntTostr(interr)+'   包体长度:'+IntTostr(int1)+#13#10);
           exit;
        end;

        SqlStr:='update Dg_ivr_tmp_data with(rowlock) set isdel=1'+
                ' where msg_id_high='+''''+inttostr(binit.Msg_Id.LowPart)+''''+
                ' and msg_id_low='+''''+inttostr(binit.Msg_Id.HighPart)+'''';

        with Qry_ivr_tmp_data_upt do
        begin
          Close;
          SQL.Clear;
          SQL.Add(SqlStr);
          ExecSQL;
        end;
        memo1.Lines.Add( '接收DELIVER_RESP操作成功!'+
                         'msg_id_high:'+inttostr(binit.Msg_Id.HighPart)+
                         'msg_id_low'+inttostr(binit.Msg_Id.LowPart)+
                         'SOCKET句柄'+inttostr(ReadSock.SocketHandle)+#13#10);
    except  on e: exception do
    begin
            if LogRec.s_time='' then
            begin
               logrec.s_funcname:='CmppRead_DELIVER_RESP';
               logrec.s_oper :='DELIVER_RESP操作';
               logrec.s_result :='失败';
               logrec.s_errcode :='0';
               logrec.s_err :=e.Message;
               logrec.s_time :=FormatDateTime('yyyy-mm-dd hh:mm:ss',now);
               WriteLog();
            end;
            memo1.Lines.Add( '接收DELIVER_RESP操作失败,错误信息' + e.Message +#13#10);
    end;        
    end; //try-except
end;


procedure TFrmMain.CmppRead_SUBMIT(ReadSock: TCustomWinSocket;
  Cmpp_Head: tCMPP_HEAD_tag);
   type
    T_init = packed record
        head: TCMPP_HEAD_tag;
        body: TCMPP_SUBMIT_RESP_tag;
    end;
var
    bInit: T_init;
    int1, int2, int3: integer;
    timestr: string;

    SizeI1: integer;
    CMPP_SUBMIT_tag: tCMPP_SUBMIT_tag;
    SqlStr1:string;
    SqlStr2:string;
    SqlStr3:string;
    SqlStrValue:string;

    ///////////////////////////////////////////////
    play_time:Tdatetime;
    play_str_time:string;
    Src_terminal_id:string;
    Dest_terminal_id:string;
    Send_name:string;
    Send_name_len:string;
    Star_id:string;
    Bless_id:string;
    Song_id:string;
    Star_txt:string;
    Bless_txt:string;
    Song_txt:string;
    Play_order:string;
    Sequence_id:integer;
    Play_num:integer;
    sp_flag:string;
    Msg_id_high:string;
    Msg_id_low:string;
    Msg_id:Tulargeinteger;
    //Password:string;
     i:integer;
begin
 try

    SizeI1 := SizeOf(CMPP_SUBMIT_tag);
    FillChar(CMPP_SUBMIT_tag, SizeI1, 0);

    if ReadSock.ReceiveBuf(CMPP_SUBMIT_tag, SizeI1) <> SizeI1 then
    begin
        Memo1.Lines.Add('接收短信发送的包体出错'+#13#10);
        exit;
    end;

    Sequence_ID:=0;
    play_str_time:='';
    Src_terminal_id:='';
    Dest_terminal_id:='';
    Play_order:='';
    Song_id:='';
    Bless_id:='';
    Star_id:='';
    Send_name_len:='';
    Send_name:='';
    sp_flag:='';
    msg_id_high:='';
    msg_id_low:='';
    msg_id.LowPart :=0;
    msg_id.HighPart :=0;

    //str1:='标识'+inttostr(CMPP_SUBMIT_tag.Msg_id);
    Sequence_ID:=Cmpp_Head.Sequence_ID;
    play_str_time:=copy(CMPP_SUBMIT_tag.At_Time,1,length(CMPP_SUBMIT_tag.At_Time)) ;
    Src_terminal_id:=copy(CMPP_SUBMIT_tag.Src_Id,1,length(CMPP_SUBMIT_tag.Src_Id))  ;
    Dest_terminal_id:=copy(CMPP_SUBMIT_tag.Dest_terminal_Id,1,length(CMPP_SUBMIT_tag.Dest_terminal_Id))  ;
    Play_order:=copy(CMPP_SUBMIT_tag.Song_Name,1,2);
    Song_id:=copy(CMPP_SUBMIT_tag.Song_Name,3,6)  ;
    Bless_id:=copy(CMPP_SUBMIT_tag.Song_Name,9,4)  ;
    Star_id:=copy(CMPP_SUBMIT_tag.Song_Name,13,4)  ;
    Send_name_len:=copy(CMPP_SUBMIT_tag.Song_Name,17,2)  ;
    Send_name:=copy(CMPP_SUBMIT_tag.Song_Name,19,length(CMPP_SUBMIT_tag.Song_Name)-17)  ;

    for i:=0 to aryclientnum do
    begin
      if (aryclient[i].CHandle = ReadSock.SocketHandle) and
      (aryclient[i].CUsed) and (aryclient[i].IsLogin )  then
      begin
           sp_flag:=aryclient[i].CSP;
           break;
      end;
    end;

    memo1.Lines.Add( '接收点歌信息成功  '+
                     '当前时间:'+datetimetostr(now)+
                     '播放时间:'+play_str_time+
                     'play_order:'+play_order+
                     'Song_id:'+Song_id+
                     'Bless_id:'+Bless_id+
                     'Star_id:'+Star_id+
                     'SP代码:'+sp_flag+
                     'SOCKET句柄:'+inttostr(ReadSock.SocketHandle )+#13#10 );

    if (sp_flag='') then
    begin
       memo1.Lines.Add('连接句柄:'+inttostr(ReadSock.SocketHandle)+'此连接发送的submit消息体尚未登录'+#13#10);
       if LogRec.s_time='' then
       begin
         logrec.s_funcname:='CmppRead_SUBMIT';
         logrec.s_oper :='连接句柄:'+inttostr(ReadSock.SocketHandle)+'发送的submit消息体尚未登录';
         logrec.s_result :='失败';
         logrec.s_errcode :='0';
         logrec.s_err :='';
         logrec.s_time :=FormatDateTime('yyyy-mm-dd hh:mm:ss',now);
         WriteLog();
       end;
       exit;
    end;

    //sp_flag:=copy(CMPP_SUBMIT_tag.Reserve ,1,length(CMPP_SUBMIT_tag.Reserve))  ;
    msg_id:=Create_msg_id;
    msg_id_high:=inttostr(msg_id.HighPart );
    msg_id_low:=inttostr(msg_id.LowPart );

      if (play_str_time<>'0000-00-00 00:00:00') and (play_str_time<>'') then
      begin
        //play_time:=strToDateTime(play_str_time);

        if length(play_str_time)<19 then
        begin
          memo1.Lines.Add('SP传送的播放时间格式有误 '+play_str_time+#13#10);
          exit;
        end;
      end;
   except on e:exception do
   begin
       if LogRec.s_time='' then
       begin
          logrec.s_funcname:='CmppRead_SUBMIT';
          logrec.s_oper :='CmppRead_SUBMIT接收数据';
          logrec.s_result :='失败';
          logrec.s_errcode :='0';
          logrec.s_err :=e.Message;
          logrec.s_time :=FormatDateTime('yyyy-mm-dd hh:mm:ss',now);
          WriteLog();
       end;

       memo1.Lines.Add('SP传送的播放时间格式有误 '+play_str_time+#13#10);
       exit;
   end;
 end;

⌨️ 快捷键说明

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