📄 sm_sp_server.pas
字号:
p_ChargeNo := ResultDataFmt(SingleSendList,1); //付费号码
p_SvcType := ResultDataFmt(SingleSendList,2); //服务类型
p_Content := ResultDataFmt(SingleSendList,3); //信息内容
p_ChildSP := ResultDataFmt(SingleSendList,4);
p_Length := Length(p_Content); //信息内容长度
p_ScheduleTime := #0;
if p_ChargeNo='#0' then
p_ChargeNo:=#0;
if p_ChildSP='#0' then
p_ChildSP:=#0;
frm_smServer.lDestNo.Caption:='被叫号码:'+p_DestNo;
Oid:=SendSMSCSP(p_DestNo, p_SvcType, p_Length, p_Content, p_TpPid, p_TpUdhi,
p_ScheduleTime, p_ExpireTime, p_Times, p_Interval, p_ChargeNo, p_ChildSP);
if Oid>0 then
begin
if SingleSendList.Count>0 then SingleSendList.Delete(0);
if vRun>0 then Dec(vRun);
CurLogMsg(1,'=======数组元素:'+IntToStr(oid)+'========');
CurLogMsg(1,'被叫号码:'+p_DestNo);
CurLogMsg(1,'当前时间:'+DateTimeToStr(Now));
CurLogMsg(1,'发送状态:信息已发出...');
CurLogMsg(1,'信息内容:'+p_Content);
end else
if not stbar(Oid) then SingleSend:=False;
end;
{批量发送数据}
procedure TBatch_Thread.Batch_Senbuf;
var
n, i, Ln, Oid:Integer;
p_Length,p_ExpireTime, p_Times, p_Interval:word;
p_TpPid, p_TpUdhi:byte;
p_DestNo: string;
p_SvcType: string;
p_Content: string;
p_ScheduleTime: string;
p_ChargeNo:string;
p_ChildSP:string;
p_Oid:array of Integer;
begin
RI:=4;
batchSend:=False;
p_Length:= 0;
p_ExpireTime:= ExpireTime;
p_Times:= 1;
p_Interval:= Interval;
p_DestNo := ResultDataFmt(BatchSendList,0); //主叫号码
p_ChargeNo := ResultDataFmt(BatchSendList,1); //付费号码
p_SvcType := ResultDataFmt(BatchSendList,2); //服务类型
p_Content := ResultDataFmt(BatchSendList,3); //信息内容
p_ChildSP := ResultDataFmt(BatchSendList,4); //SP子号码
p_Length := Length(p_Content); //信息内容长度
Ln := (Length(p_DestNO) div 11);
setLength(p_Oid,Ln);
p_ScheduleTime := #0;
if p_ChargeNO='#0' then
p_ChargeNo:=#0;
if p_ChildSP='#0' then
p_ChildSP:=#0;
Oid:=SendBatchSMSCSP(p_DestNo, p_SvcType, p_Length, p_Content, p_ScheduleTime,
p_ExpireTime, p_Times, p_Interval, p_ChargeNo,p_ChildSP, p_Oid);
if Oid>0 then
begin
if batchSendList.Count>0 then BatchSendList.Delete(0);
for i:=0 to Ln-1 do
begin
if vRun>0 then Dec(vRun);
CurlogMsg(1,'数组元素:'+IntToStr(p_Oid[i]));
CurlogMsg(1,'发送状态:信息已发出...');
end;
end else
if not stbar(Oid) then BatchSend:=False;
end;
{信息接收}
procedure TRec_Thread.RecBuf;
var
i,retcode:integer;
Buffer:array[0..4095] of Char;
tmpBuf:array[0..400] of Char;
xDeliver:array [0..9] of TDeliverCSP;
xResult :array [0..9] of TResult;
p_MaxRecv:byte;
tmpSrcNo,tmpTime,tmpContent:string;
pRecvType:Integer;
pSrcNo,pSPNumber,pMsg,pSendMode,
pChargeNo,pState,pSendTime,pDestNo:string;
pCurrTime,pMsgLength,pTpUid,pTpUdhi,pEncoded,pOid:Integer;
begin
fillchar(tmpBuf,sizeof(tmpBuf),ord(' '));
fillchar(Buffer,sizeof(buffer),ord(' '));
fillchar(xDeliver,sizeof(xDeliver),ord(' '));
fillchar(xResult,sizeof(xResult),ord(' '));
Retcode:=0;
try
Retcode:=RecvMsgCSP(REC_UPT,Buffer);
except
on Exception do
raise EAbort.Create('''');
end;
if Retcode>0 then
begin
RI:=5;
str_Out('缓冲记录数:'+IntToStr(RetCode),1);
Move(Buffer,xDeliver,SizeOf(xDeliver));
Move(Buffer,xResult,SizeOf(xResult));
BufferRecord := retcode;
MsgReceive := MsgReceive+retcode;
for i:=0 to Retcode-1 do
begin
if Char(xDeliver[i].RecvType)='1' then
begin
pRecvType:=1;
CurLogMsg(0,'========记录类型:DELIVER========'); //Char(sDeliver.RecvType)
Move(xDeliver[i].SrcNo,tmpBuf,SizeOf(xDeliver[i].SrcNo));
CurLogMsg(0,'主叫号码:'+tmpBuf);
pSrcNo:=tmpBuf;
Move(xDeliver[i].SPNumber,tmpBuf,SizeOf(xDeliver[i].SPNumber));
pSPNumber:=tmpbuf;
CurLogMsg(0,'SP子号码:'+tmpBuf);
pTpUid:=xDeliver[i].TpUid;
CurLogMsg(0,'TpUid协议类型:'+IntToStr(xDeliver[i].TpUid));
pTpUdhi:=xDeliver[i].TpUdhi;
CurLogMsg(0,'TpUdhi协议类型:'+IntToStr(xDeliver[i].TpUdhi));
pEncoded:=xDeliver[i].Encoded;
CurLogMsg(0,'编码方式:'+IntToStr(xDeliver[i].Encoded));
CurLogMsg(0,'服务内容长度:'+IntToStr(xDeliver[i].MsgLength));
pMsgLength:=xDeliver[i].MsgLength;
Move(xDeliver[i].Msg,tmpBuf,SizeOf(xDeliver[i].Msg));
CurLogMsg(0,'服务请求内容:'+tmpBuf);
pMsg:=tmpBuf;
if pSPNumber='8165777' then StatemAssay(pSrcNo,pMsg) else
PostTranClient(pRecvType,0,0,'',pSrcNo,pSPNumber,pMsgLength,pMsg,Now,0);
PostDeliverMsg(pRecvType,pSrcNo,pSPNumber,pTpUid,pTpUdhi,pEncoded,pMsgLength,pMsg);
end else
begin
pRecvType:=2;
CurLogMsg(0,'========记录类型:RESULT========='); //Char(sResult.RecvType)
CurLogMsg(0,'数组元素:'+IntToStr(xResult[i].Oid));
pOid:=xResult[i].Oid;
CurLogMsg(0,'已发次数:'+IntToStr(xResult[i].CurrTimes));
pCurrTime:=xResult[i].CurrTimes;
Move(xResult[i].SendTime,tmpBuf,SizeOf(xResult[i].SendTime));
pSendTime:=tmpbuf;
CurLogMsg(0,'发送时间:'+tmpBuf);
Move(xResult[i].SendMode,tmpBuf,SizeOf(xResult[i].SendMode));
pSendMode:=tmpbuf;
CurLogMsg(0,'发送模式:'+tmpBuf);
Move(xResult[i].DestNo,tmpBuf,SizeOf(xResult[i].DestNo));
pSrcNo:=tmpbuf;
CurLogMsg(0,'被叫号码:'+tmpBuf);
case Char(xResult[i].State) of
'S':begin
CurLogMsg(0,'发送状态:发送成功...');
Inc(MsgRightNum);
end;
'F':begin
CurLogMsg(0,'发送状态:发送失败!');
WriteLog(CurLogFile,'发送失败:'+tmpSrcNo);
WriteLog(CurLogFile,'发送时间:'+tmpTime);
Inc(FailRecord);
if ReSend then AfreshSend(tmpSrcNo); //启用重发机制
end;
'T':begin
CurLogMsg(0,'发送状态:在有效期内没有返回状态报告!');
WriteLog(CurLogFile,'在有效期内没有返回状态报告:'+tmpSrcNo);
WriteLog(CurLogFile,'发送时间:'+tmpTime);
end ;
'N':CurLogMsg(0,'发送状态:没有对应的短信内容!');
else begin
CurLogMsg(0,'发送状态:未登记的错误!');
WriteLog(CurLogFile,'未登记的错误:'+tmpSrcNo);
WriteLog(CurLogFile,'发送时间:'+tmpTime);
Inc(FailRecord);
end;
end;
pState:=Char(xResult[i].State);
Move(xResult[i].ChargeNo,tmpBuf,SizeOf(xResult[i].ChargeNo));
pChargeNo:=tmpbuf;
CurLogMsg(0,'付费号码:'+tmpBuf);
PostResultMsg(pRecvType,pOid,pCurrTime,pSendTime,pSendMode,pSrcNo,pState,pChargeNo);
end;
end;
end;
stbar(RetCode);
end;
///======================================================================///
procedure Tfrm_smServer.BitBtn3Click(Sender: TObject);
var
frmSearchEventsLog:TfrmSearchEventsLog;
begin
frmSearchEventsLog := TfrmSearchEventsLog.Create(self);
frmSearchEventsLog.ShowModal;
end;
procedure Tfrm_smServer.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @NotifyIcon);
end;
procedure Tfrm_smServer.N15Click(Sender: TObject);
var
I:Integer;
begin
sgrList.Cells[1,sgrList.Row]:='';
sgrList.Cells[2,sgrList.Row]:='';
for I:=1 to sgrList.RowCount-1 do
if sgrList.Cells[2,I]='' then
with sgrList do
begin
Cells[1,I]:=Cells[1,I+1];
Cells[2,I]:=Cells[2,I+1];
Cells[1,I+1]:='';
Cells[2,I+1]:='';
end;
end;
procedure Tfrm_smServer.N16Click(Sender: TObject);
var
I:Integer;
sDestNo, sSvcType, sChargeNo, sContent:string;
b:boolean;
begin
if rgCell.ItemIndex=1 then sChargeNo := '#0'; //#0被叫号码付费
if rgCell.ItemIndex=0 then sChargeNo := '0'; //0SP付费
sSvcType := Trim(lSvcType.Text); //服务类型
sContent := Trim(m_Sen_Content.Text);
if SearchSvcType(sSvcType,1)<>1
then begin
lSvcType.SetFocus;
ErrorMsg(1,'错误的服务类型!');
Exit;
end;
if Length(m_Sen_Content.Text)<1 then
begin
m_Sen_Content.SetFocus;
ErrorMsg(1,'信息内容不能为空!');
Exit;
end;
for I:=1 to sgrList.RowCount-1 do
begin
if (Trim(sgrList.Cells[1,I])<>'')and
(Trim(sgrList.Cells[2,I])='√')
then begin
b:=True;
sDestNo:=Trim(sgrList.Cells[1,I]);
if not CheckPhone(11,sDestNo)
then begin
ErrorMsg(1,'被叫号码错误!');
sgrList.Row:=I;
Exit;
end;
end;
end;
if not b then
begin
sgrList.SetFocus;
ErrorMsg(1,'请选择有效的号码!');
sgrList.Row:=1;
Exit;
end;
for i:=1 to sgrList.RowCount-1 do
begin
if (Trim(sgrList.Cells[1,I])<>'')and
(Trim(sgrList.Cells[2,I])='√')
then begin
sDestNo:=Trim(sgrList.Cells[1,i]);
if sDestNo<>'' then
PostMess(2,1,sDestNo,sChargeNo,sSvcType,Now,sContent,SPNumber);
end;
b_SendSMS.Enabled:=False;
end;
end;
procedure Tfrm_smServer.N17Click(Sender: TObject);
var
I:Integer;
sDestNo, sSvcType, sChargeNo, sContent:string;
b:boolean;
begin
if rgCell.ItemIndex=1 then sChargeNo := '#0'; //#0被叫号码付费
if rgCell.ItemIndex=0 then sChargeNo := '0'; //0SP付费
sSvcType := Trim(lSvcType.Text); //服务类型
sContent := Trim(m_Sen_Content.Text);
sDestNo:=Trim(sgrList.Cells[1,sgrList.Row]);
if SearchSvcType(sSvcType,1)<>1
then begin
lSvcType.SetFocus;
ErrorMsg(1,'错误的服务类型!');
Exit;
end;
if Length(m_Sen_Content.Text)<1
then begin
m_Sen_Content.SetFocus;
ErrorMsg(1,'信息内容不能为空!');
Exit;
end;
if sDestNo<>''
then begin
if not CheckPhone(11,sDestNo) then
begin
ErrorMsg(1,'错误的号码!');
sgrList.SetFocus;
Exit;
end;
end else
begin
ErrorMsg(1,'被叫号码不能为空!');
sgrList.SetFocus;
Exit;
end;
PostMess(2,1,sDestNo,sChargeNo,sSvcType,Now,sContent,SPNumber);
b_SendSMS.Enabled:=False;
end;
procedure Tfrm_smServer.tTimeCycleTimer(Sender: TObject);
begin
//对数据库进行搜索如果满足条件//
TSearchSend.Create(False);
TSearchTranClient.Create(False);
if ProgressAction then
begin
Progress.Free;
ProgressAction:=False;
end;
end;
procedure Tfrm_smServer.TimeICOTimer(Sender: TObject);
begin
Shell_NotifyIcon(NIM_MODIFY, @NotifyIcon);
Case RI Of
0:begin
NotifyIcon.hIcon := Image1.Picture.Icon.Handle;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
end;
1:begin
//NotifyIcon.hIcon := Appslication.Icon.Handle;
NotifyIcon.hIcon := Image4.Picture.Icon.Handle;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
end;
2:begin
NotifyIcon.hIcon := Image5.Picture.Icon.Handle;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
if RI = 2 then RI:=1
else
RI:=3;
end;
3:begin
Shell_NotifyIcon(NIM_MODIFY, @NotifyIcon);
end;
4:begin
NotifyIcon.hIcon := Image2.Picture.Icon.Handle;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
end;
5:begin
NotifyIcon.hIcon := Image3.Picture.Icon.Handle;
Shell_NotifyIcon(NIM_ADD, @NotifyIcon);
end;
end;
end;
//============================向客户端下发信息===========================//
procedure TSearchTranClient.SearchTranClient;
var
xDeliverClient:TDeliverClient;
xResultClient:TResultClient;
tmpbuf:array[0..255] of Char;
buffer:array[0..1023] of Char;
pHandle:DWord;
pCommandID,pSrcNo,pRequesMsg,pSPNumber:string;
pHand,pRecNo,pRecvType,pMsgLength,pResultValue,I:Integer;
begin
with frmServerDB.qryTranClient do
begin
Close;
Parameters.ParamByName('pFalg').Value:='1';
Open;
end;
if frmServerDB.qryTranClient.RecordCount>0 then
begin
frmServerDB.qryTranClient.First;
while not frmServerDB.qryTranClient.Eof do
begin //. 5
with frmServerDB.qryTranClient do
begin //..1
pRecNo :=Fields[0].Value;
pRecvType :=Fields[1].Value;
pHandle :=Fields[2].Value;
pHand :=Fields[3].Value;
pCommandID :=Fields[4].Text;
pSrcNo :=Trim(Fields[5].Text);
pSPNumber :=Trim(Fields[6].Text);
pMsgLength :=Fields[7].Value;
pRequesMsg :=Trim(Fields[8].Text);
pResultValue:=Fields[10].Value;
end; //..1
for i := 0 to frm_smServer.ServerReceiveSend.Socket.ActiveConnections -1 do
begin //. 4
if frm_smServer.ServerReceiveSend.Socket.Connections[I].Handle=pHandle
then
begin //. 3
CurLogMsg(3,'==========下发客户机数据==========');
CurLogMsg(3,'网络句柄:'+IntToStr(pHandle));
CurLogMsg(3,'命令码:'+CommandID);
CurLogMsg(3,'信息内容:'+MsgResult);
CurLogMsg(3,'返回值:'+IntToStr(pResultValue));
fillchar(xResultClient,SizeOf(xResultClient),' ');
fillchar(buffer,SizeOf(buffer),' ');
fillchar(tmpbuf,SizeOf(tmpbuf),' ');
xResultClient.RecvType:=1; //返回类型
xResultClient.Hand:=pHand; //套接字1
StrPCopy(tmpbuf,CommandID); //命令字
Move(tmpbuf,xResultClient.CommandID,SizeOf(xResultClient.CommandID));
xResultClient.ResultValue:=pResultValue; //返回值
StrPCopy(tmpbuf,MsgResult); //返回信息内容
Move(tmpbuf,xResultClient.ResultMsg,SizeOf(xResultClient.ResultMsg));
Move(xResultClient,buffer,SizeOf(xResultClient));
if frm_smServer.ServerReceiveSend.Socket.Connections[I].SendBuf(buffer,SizeOf(buffer))>0 then
begin //. 2
with frmServerDB.updTranClient do
begin //. 1
Close;
Parameters.ParamByName('pRecNo').Value:=pRecNo;
ExecSQL;
end; //. 1
end; //. 2
end; //. 3
end; //. 4
frmServerDB.qryTranClient.Next;
end; //. 5
end; //. 6
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -