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

📄 umulticat.pas

📁 一个队列的类,可以方便的进行队列的添加,删除,查询功能!
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      ret := MsgCat.Sendsms(Command, SPCode, sreport);
      if ret<>'y' then
      begin
        Result := False;
        exit;
      end
      else
        Result := True;
    end;
  finally
    FReady := True;
  end;
end;

procedure TMsgCat.SendMsgToClient;
var
//  Client : TSimpleClient;
  k: integer;
begin
  //给客户端发送信息
  k:=GetClentIndex(ServerMain.Clients,FUserID);
  if k>=0 then
  begin
    Client := ServerMain.Clients.Items[k];
    TIdPeerThread(Client.Thread).Connection.WriteLn(FMsg);
  end;
end;

{ TManageMsgCat }

procedure TManageMsgCat.ClearTask;
begin
  FTaskQueue.Clear;
  FTaskCount := 0;
end;

constructor TManageMsgCat.Create;
var
  i: integer;
begin
  inherited Create;
  FTaskCount := 0;
  FRetMsgcount := 0;
  FTaskQueue := TFFQueue.Create;     //任务队列。
  FRetMsgQueue := TFFQueue.Create;  //返回信息队列。
  for i:=Low(FMsgCats) to High(FMsgCats) do
    FMsgCats[i] := nil;
  //FthrTime := TThreadedTimer.Create(nil);
  //FthrTime.Enabled := False;
end;

destructor TManageMsgCat.Destroy;
var
  i: integer;
begin
  for i:=0 to High(FMsgCats) do
  begin
    if FMsgCats[i] <> nil then
      FMsgCats[i].Free;
  end;
  //FthrTime.Enabled := False;
  //FthrTime.Free;
  inherited Destroy;
end;

procedure TManageMsgCat.ExecuteReceiveMsgs;
begin

end;

procedure TManageMsgCat.ExecuteSendMsgs(Sender: TObject);
var
  i,j: integer;
  aPayInfo: TPayInfo;
  ret: Boolean;
  Balance,Amt,ServiceID, k: Integer;
  Msg: string;
  Client : TSimpleClient;
begin
  if FTaskStutas <> 2 then
  begin
    for j:=0 to FTaskQueue.DataCount-1 do
    begin
      for i:=Low(FMsgCats) to High(FMsgCats) do
      begin
        if FTaskQueue.DataCount <= 0 then exit;
        if (MsgCats[i] <> nil) and  MsgCats[i].Enable then
        begin
          if MsgCats[i].Ready then
          begin
            aPayInfo :=  TPayInfo(FTaskQueue.Pop^);
            aPayInfo.MsgCatID := -1;
            MsgCats[i].PayInfo := aPayInfo;
            MsgCats[i].Resume;
          end;
        end;
      end;
    end;
  end;
end;

function TManageMsgCat.GetMsgCat(index: Integer): TMsgCat;
begin
  if (index>=Low(FMsgCats)) and (index<=High(FMsgCats)) then
  begin
    Result := FMsgCats[index];
  end
  else
    Result := nil;
end;


//在所有的猫中,根据串口端口号返回短信猫ID  找不到返回-1
function TManageMsgCat.GetMsgCatID(PortID: integer): integer;
var
  i: integer;
begin
  Result := -1;
  for i:=low(FMsgCats) to high(FMsgCats) do
  begin
    if FMsgCats[i] <> nil then
    begin
      if FMsgCats[i].FConnected then
      begin
        FMsgCats[i].MsgCat.CommPort;
        if FMsgCats[i].MsgCat.CommPort = PortID then
        begin
          Result := FMsgCats[i].MsgCatID;
          exit;
        end;
      end;
    end;
  end;
end;


//任务执行状态。 0=空闲,1=执行中,2=暂停中,3=允许执行
//暂停任务,但当前执行的任务还会继续执行完。
procedure TManageMsgCat.PauseTask;
begin
  FTaskStutas := 2;
end;


//根据传入的参数(Enable=true,就启动短信猫)决定启动对应的短信猫.否则返回false。
procedure TManageMsgCat.RecvMsgs(Sender: TObject);
var
  msg: string;
  pMsg: pchar;
  p1: Pointer;
  aRetMsg: TRetMsg;
  pRetMsg: ^TRetMsg;
begin
   {$IFDEF _TEST}
//   msg := PChar('test'+inttostr(RetMsgcount));
   aRetMsg.ReceiveTime := Now;
   aRetMsg.ProcessStatus := 0;        //处理的状态 0=未处理;1=处理过
   aRetMsg.ProcessID := 1;  //TMsgCat(Sender).MsgCatID;
   aRetMsg.Msg := 'dfsdjafda';  // TMsgCat(Sender).MsgCat.NewMsg;

   {$ENDIF}

   {$IFDEF _RUN}
   aRetMsg.ReceiveTime := Now;
   aRetMsg.ProcessStatus := 0;        //处理的状态 0=未处理;1=处理过
   aRetMsg.ProcessID := GetMsgCatID(TSmsgate(Sender).CommPort);  //根据串口号返回CatID.
   aRetMsg.Msg := TSmsgate(Sender).NewMsg;
   //aRetMsg.Msg := TMsgCat(Sender).MsgCat.NewMsg;
   {$ENDIF}
   GetMem(pRetMsg,SizeOf(aRetMsg));
   pRetMsg^.ReceiveTime := aRetMsg.ReceiveTime;
   pRetMsg^.ProcessID := aRetMsg.ProcessID;
   pRetMsg^.ProcessStatus := aRetMsg.ProcessStatus;
   pRetMsg^.Msg := aRetMsg.Msg;
   FRetMsgQueue.Push(pRetMsg);
end;

function TManageMsgCat.SetCat(CatID: integer;  aCatParam: TCatParam): Boolean;
begin
  if (CatID>=Low(FMsgCats)) and (CatID<=High(FMsgCats)) then
  begin
    if aCatParam.Enable then
    begin
      try
        FMsgCats[CatID] := TMsgCat.Create;
        try
          if FMsgCats[CatID].Connect(aCatParam.ComPort,aCatParam.ComSeting,
            aCatParam.ServiceCode, CatID) then
          begin
            FMsgCats[CatID].MsgCatID := CatID;
            FMsgCats[CatID].Enable := aCatParam.Enable;
            FMsgCats[CatID].SPCode := aCatParam.SPCode;
            FMsgCats[CatID].SPPws := aCatParam.SPPws;
            FMsgCats[CatID].ServiceCode := aCatParam.ServiceCode;
            FMsgCats[CatID].CZML := aCatParam.CZML;
            FMsgCats[CatID].MsgCat.OnRecvMsg := RecvMsgs;
            FQueryArr[CatID] := TQuery.Create(nil);
            FQueryArr[CatID].DatabaseName := DataBaseName;
            Result := True;
          end
          else
          begin
            FMsgCats[CatID].Free;
            FQueryArr[CatID].Free;
            Result := False;
          end;
        except
          FMsgCats[CatID].Free;
          Result := False;
        end;
      except
        Result := False;
      end;
    end
    else
    begin
      if FMsgCats[CatID] <> nil then
      begin
        try
          if FMsgCats[CatID].Connected then
            FMsgCats[CatID].Disconnect;
          FMsgCats[CatID].Free;
          Result := True;
        except
          FMsgCats[CatID].Free;
          Result := false;
        end;
      end
      else
        Result := True;
    end;

  end
  else
    Result := False;
end;

//开始启动执行任务
procedure TManageMsgCat.StartTask;
begin
  FTaskStutas := 3;
end;


{
procedure TManageMsgCat.thrTimeTimer(Sender: TObject);
var
  i: integer;
  aPayInfo: TPayInfo;
  ret: Boolean;
  Balance,Amt,ServiceID, k: Integer;
  Msg: string;
  Client : TSimpleClient;
begin
  if FTaskStutas <> 2 then
  begin
    for i:=Low(FMsgCats) to High(FMsgCats) do
    begin
      if MsgCats[i].Enable then
      begin
        if MsgCats[i].Ready then
        begin
          if FTaskQueue.DataCount <=0 then  exit;
          aPayInfo :=  TPayInfo(FTaskQueue.Pop^);
          if MsgCats[i].SendMsg(aPayInfo.CZML, aPayInfo.PhoneCode,aPayInfo.Amt) then
            ret := True//成功后,记录数据库信息。
          else
          begin
            ret := false;
            if MsgCats[i].SendMsg(aPayInfo.CZML, aPayInfo.PhoneCode,aPayInfo.Amt) then
              ret := True
            else
             ret := false;
          end;
          if ret then
          begin
            if not aPhoneCost.AddBalance(aPayInfo.UserID, -StrToInt(aPayInfo.Amt)) then  //扣除用户话费
            begin
              ShowMessage('缴费失败!更新数据库出错');
              exit;
            end;
            Balance:= round(aPhoneCost.GetBalance(aPayInfo.UserID));//交费后的余额
            FQueryArr[i].Close;
            FQueryArr[i].SQL.Clear;
            FQueryArr[i].SQL.Add('insert into PaymentLOG (UserID,PhoneCode,Amt,PostTime,'
              +'Task,TaskStatus,TaskTime,SuccessTime,ProcessID,PaymentID,ServiceID)') ;
            FQueryArr[i].SQL.Add('values (:UserID,:PhoneCode,:amt,:PostTime,:Task,:TaskStatus,:TaskTime,:SuccessTime,:ProcessID,:PaymentID,:ServiceID)');
            FQueryArr[i].ParamByName('UserID').AsString:=aPayInfo.UserID;      //用户名
            FQueryArr[i].ParamByName('PhoneCode').AsString:=aPayInfo.PhoneCode; //缴费号码
            FQueryArr[i].ParamByName('Amt').AsFloat:=StrToFloat(aPayInfo.Amt);
            FQueryArr[i].ParamByName('PostTime').AsDateTime:=now;
            FQueryArr[i].ParamByName('Task').AsString:='缴费';
            FQueryArr[i].ParamByName('TaskStatus').AsString:='处理';
            FQueryArr[i].ParamByName('TaskTime').AsString:='';
            FQueryArr[i].ParamByName('SuccessTime').AsString:='';
            FQueryArr[i].ParamByName('ProcessID').AsInteger:=i;
            FQueryArr[i].ParamByName('PaymentID').AsInteger:=aPayInfo.PaymentID;
            FQueryArr[i].ParamByName('ServiceID').AsInteger:=aPayInfo.ServiceID;
            FQueryArr[i].ExecSQL ;

            Msg :='*'+aPayInfo.UserID+'*#'+'YDJF#@'+aPayInfo.PhoneCode+'@##'+aPayInfo.Amt+'##&'+DateTimeToStr(Now)+
                  '&**CG**A'+inttostr(aPayInfo.PaymentID)+'AB'+inttostr(Balance)+'B' ;
            Msg := Trim(Msg);

            //短信回复确认表
            FQueryArr[i].Close;
            FQueryArr[i].SQL.Clear;
            FQueryArr[i].SQL.Add('insert into NewsRestoreVerif (UserID,Content,DeliveryTime) values (:UserID,:Content,:DeliveryTime)');
            FQueryArr[i].ParamByName('UserID').AsString:=aPayInfo.UserID;
            FQueryArr[i].ParamByName('Content').AsString:=Msg;
            FQueryArr[i].ParamByName('DeliveryTime').AsDateTime:=Now;
            FQueryArr[i].ExecSQL;
            //给客户端发送信息
            k:=GetClentIndex(ServerMain.Clients,aPayInfo.UserID);
            if k>=0 then
            begin
              Client := ServerMain.Clients.Items[k];
              TIdPeerThread(Client.Thread).Connection.WriteLn(Msg);
            end;
          end
          else
          begin
            //交费失败  #功能#@返回内容@**XB**    把失败记录写入数据表  recordfailurezhong
            Msg :='#YDJF#**XB**' ;

            k:=GetClentIndex(ServerMain.Clients,aPayInfo.UserID);
            if k>=0 then
            begin
              Client := ServerMain.Clients.Items[k];
              TIdPeerThread(Client.Thread).Connection.WriteLn(Msg);
            end;
            FQueryArr[i].Close;
            FQueryArr[i].SQL.Clear;
            FQueryArr[i].SQL.Add('insert into recordfailure (UserID,PhoneCode,Amt,PostTime,'
              +'Task,TaskStatus,PaymentID)') ;
            FQueryArr[i].SQL.Add('values (:UserID,:PhoneCode,:amt,:PostTime,:Task,:TaskStatus,:PaymentID)');
            FQueryArr[i].ParamByName('UserID').AsString:=aPayInfo.UserID;  //用户名
            FQueryArr[i].ParamByName('PhoneCode').AsString:=aPayInfo.PhoneCode;   //缴费号码
            FQueryArr[i].ParamByName('Amt').AsFloat:=StrToFloat(aPayInfo.Amt);
            FQueryArr[i].ParamByName('PostTime').AsDateTime:=now;
            FQueryArr[i].ParamByName('Task').AsString:='缴费';
            FQueryArr[i].ParamByName('TaskStatus').AsString:='失败';
            FQueryArr[i].ParamByName('PaymentID').AsInteger:=aPayInfo.PaymentID;
            FQueryArr[i].ExecSQL ;
            {
            if not DelPaymentTask(yhm,PaymentID) then   //如果2次发送失败删除该条记录
            begin
              WaitAndPass(500);
              if not DelPaymentTask(yhm,PaymentID) then
                MsgCatReady := False;  //2次删除出错就停止短信猫缴费。
            end;
            MessageContent := yhm+'短信发送失败,请处理13909237799';
            dxcgf:=Smsgate1.Sendsms(MessageContent, mobile1,sReport);
            IF dxcgf ='y' then
            begin

            end
            else
            begin
              waitTime := 30;
              Smsgate1.CallPhone(mobile1,waitTime); //发短息失败后,电话通知
            end;
            
          end;
        end;
      end;
    end;
  end;
end;
}

end.

⌨️ 快捷键说明

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