📄 sp_dll.pas
字号:
unit SP_dll;
interface
uses
Windows, Forms, SysUtils, Classes, Registry, Math, Gauges;
const
//返回值
h40 = $01;
h41 = $02;
h42 = $03;
h43 = $04;
h44 = $05;
h45 = $06;
h46 = $07;
h47 = $08;
h48 = $09;
h49 = $10;
h4A = $11;
h4B = $12;
h4C = $13;
h4D = $14;
h4E = $15;
//命令列表
h01 = 'SecurityATT';
h02 = 'GetHostPort';
h03 = 'GetREC_UPT';
h04 = 'GetSND_UPT';
h05 = 'GetSeurity';
h06 = 'GetWarning';
h07 = 'GetMangPhone';
h08 = 'GetAnswerTime';
h09 = 'GetInterval';
h0A = 'GetExpireTime';
h0B = 'GetSenAnswTime';
h0C = 'GetCurLogChk';
h0D = 'ReadCXRecord';
h0E = 'ReadSNDRecord';
h0F = 'GetCharge';
h10 = 'Get_Time';
h11 = 'GetSvcTypeTran';
h12 = 'GetSPSvcType';
h13 = 'GetReSend';
h14 = 'GetSendTry';
h15 = 'SetHostPort';
h16 = 'SetREC_UPT';
h17 = 'SetSND_UPT';
h18 = 'SetSeurity';
h19 = 'SetWarning';
h1A = 'SetMangPhone';
h1B = 'SetAnswerTime';
h1C = 'SetInterval';
h1D = 'SetExpireTime';
h1E = 'SetSenAnswTime';
h1F = 'SetCurLogChk';
h20 = 'SetCharge';
h21 = 'SetTime';
h22 = 'SetSvcTypeTran';
h23 = 'SetSPSvcType';
h24 = 'SetReSend';
h25 = 'SetSendTry';
h26 = 'ServerRunStatus';
h27 = 'SendSMS';
h28 = 'SendBatchSMS';
h29 = 'ReadSvcContent';
h2A = 'SetTimeCycle';
h2B = 'SetFeeDate';
h2C = 'SetFeeTime';
h2D = 'SetSPNumber';
h2E = 'GetTimeCycle';
h2F = 'GetSPNumber';
h30 = 'GetFeeTime';
h31 = 'GetFeeDate';
hFD = 'PostMess';
var
Progress :TGauge;
pRect :TRect;
FeeDate :Integer; //包月收费日期
SPNumber :string; //SP子号码
FeeTime :string; //包月收费时间
SvcTypeTran:string; //触发器服务类型
MangPhone :string; //管理员手机号码
CurLogFile :string; //日志文件
SendTime :string;
p_SrcNo :string;
p_ChargeNo :string;
p_SvcType :string;
p_Content :string;
IPAddress :string;
RemoteRec :string;
SP_SvcType :string; //SP服务代码
SvcTypeName:string; //服务类型名称
MsgResult :string; //返回远程数据
CommandID :string;
MsgReceive : LongWord=0; //接收记录
MsgRightNum : LongWord=0; //正确记录
FailRecord : LongWord=0; //失败记录
WaitCommandRun: Byte; //等待数量
BufferRecord : Byte; //缓冲数量
CommandRunNum : Byte; //命令数量
SingleSendList: TStringList; //信息单条列表
BatchSendList : TStringList; //信息批量列表
MonthFeeList : TStringList; //包月收费
ResultCode : TStringList; //错误代码
SvcTypeCode : TStringList; //服务代码列表
ProgressAction:Boolean; //进度条活动标志
SingleSend :Boolean; //单条发送
BatchSend :Boolean; //批量发送
MonthFee :Boolean; //包月收费发送
CurLogChk :Boolean; //日志选择
Security :Boolean;
Warning :Boolean;
ReSend :Boolean;
ResultCharegNo:Integer;
ResultValue :Integer; //返回条件
HostPort :Integer; //主机端口
Interval :Integer; //信息延时时间(分钟)
ExpireTime :Integer; //信息生成时间(分钟)
REC_UPT :Integer;
SND_UPT :Integer;
ReSendTry :Integer; //数据重发次数
RI :Integer; //状态参数
vRun :Integer; //正在执行命令数量
// NID :Integer; //客户端连接号
// NetHandle :DWord; //网络套接字;
{type
PNetHandle = ^TNetHandle;
TNetHandle = Record
NID:DWord;
Handle:DWord;
end; }
//接收远程客户机数据包
type
TReceiveClient = Record
Hand:byte;
IPAddress:array [0..29] of byte;
User:array [0..19] of byte;
PassWord:array [0..19] of byte;
CommandID:array [0..14] of byte;
DestNo: array [0..251] of byte;
ChargeNo: array [0..21] of byte;
SvcType: array [0..10] of byte;
Content: array [0..254] of byte;
SPNumber:array [0..9] of byte;
end;
//下发客户端MO请求结果
type
TDeliverClient = Record
RecvType:byte;
Hand:byte;
SrcNo:array [0..10] of Char;
SPNumber:array [0..14] of Char;
MsgLength:Integer;
RequestMsg:array [0..160] of Char;
RequestDateTime:array [0..14] of Char;
end;
//下发客户端返回结果
type
TResultClient = Record
RecvType:byte;
Hand:byte;
CommandID: array [0..14] of byte;
ResultValue:Integer;
ResultMsg:array [0..160] of byte;
end;
{//下发客户端转发接收的数据
type
TDeliverClient = Record
RecvType:byte;
SrcNo:array [0..21] of byte;
Msg:array [0..160] of byte;
end;
}
type
TResult = Record
RecvType:byte;
Oid:Integer;
CurrTimes:Integer;
SendTime:array [0..14] of byte;
SendMode: array [0..8] of byte;
DestNo: array [0..21] of byte;
State:byte;
ChargeNo: array [0..21] of byte;
Reserve: array [0..130] of byte;
end;
type
TDeliverCSP = Record
RecvType:byte;
SrcNo: array [0..21] of byte;
SPNumber: array [0..21] of byte;
TpUid:byte;
TpUdhi:byte;
Encoded:byte;
MsgLength:Word;
Msg: array [0..160] of byte;
end;
function SendSMSCSP(P_DestNo:string;//被叫手机号码,C字符串,最长21字节
p_SvcType:string; //服务类型,C字符串,最长10字节
p_Length:Integer; //发送内容长度,无符号整形,4字节
p_Content:string; //发送的内容,字符型,长度为p_Length
p_TpPid:byte; //通常为0,仅用于向非NOKIA手机发送铃声和图片
p_TpUdhi:byte; //通常为0,仅用于向非NOKIA手机发送铃声和图片
p_ScheduleTime:string; //发送时间,C字符串,长度为14,格式为YYYYMMDDhhmmss,空串表示立即发送
p_ExpireTime:Word; //有效时间(分钟),无符号短整型,2字节,0为使用短信中心缺省值
p_Times:Word; //发送次数,无符号短整型,2字节,0无效
p_Interval:Word; //每次发送的间隔时间(分钟),无符号短整型,2字节,0无效
p_ChargeNo:string;
p_ChildSP:string):Integer;cdecl;external 'xboxdll.dll';
//付费号码,C字符串,最长21字节;如为NULL或空串("\0")表示由被叫付费;如为"0"表示由SP付费
//stdcall;external cdecl\
function SendBatchSMSCSP(P_DestNo:string;//被叫手机号码,C字符串,最长21字节
p_SvcType:string; //服务类型,C字符串,最长10字节
p_Length:word; //发送内容长度,无符号整形,4字节
p_Content:string; //发送的内容,字符型,长度为p_Length
p_ScheduleTime:string; //发送时间,C字符串,长度为14,格式为YYYYMMDDhhmmss,空串表示立即发送
p_ExpireTime:word; //有效时间(分钟),无符号短整型,2字节,0为使用短信中心缺省值
p_Times:word; //发送次数,无符号短整型,2字节,0无效
p_Interval:word; //每次发送的间隔时间(分钟),无符号短整型,2字节,0无效
p_ChargeNo:string; //付费号码,C字符串,最长21字节;如为NULL或空串("\0")表示由被叫付费;如为"0"表示由SP付费
p_ChildSP:string;
p_Oid:array of integer):integer;cdecl;external 'xboxdll.dll';
//无符号整型数组,元素个数等于被叫号码的个数,用于存放返回的OID
function RecvMsgCSP(p_MaxRecv:byte;p_Buffer:array of Char):Integer; //最多接收DELIVER和RESULT的条数,1字节
cdecl;external 'xboxdll.dll'; //存放返回结果的缓冲区
function SendMonthFee(p_DestNo,p_SvcType:string;p_FeeValue:Integer):Integer;
cdecl;external 'xboxdll.dll'; //包月收费短信
//============================================================================//
procedure WriteLog(FileName:string;Context:string);
procedure CurLogMsg(Falg:integer;Msg:string);
procedure ErrorMsg(Falg:Integer;ErrMsg:PChar);
procedure strChanging(str:PChar;RI:Integer);
procedure LoadResultCode;
procedure ProgressBar;
function stbar(x:Integer):Boolean;
function str_Out(str:string;x:Integer):string;
function ResultMsg(Code:integer):string;
procedure DataAssay(pHandle:DWord; pHand:byte;pIPAddress,pUser,pPassWord,pCommandID,
pDestNo,pChargeNo,pSvcType,pContent,pSPNumber:string);
implementation
uses SM_SP_Server, ServerDB, DataBaseOperat, SP_DLLs;
//===========================装载用户返回代码=================================//
procedure LoadResultCode;
begin
try
ResultCode.LoadFromFile(ExtractFilePath(Application.ExeName)+'ResultCode.ini');
except
on Exception do
raise exception.Create('装载信息文件错误!');
end;
end;
//====================进度条===============================//
procedure ProgressBar;
var
staPanleWidth:integer;
begin
Progress:=TGauge.Create(frm_smServer);
staPanleWidth:=frm_smServer.str.Panels[1].Width;
with Progress do
begin
Top:=3;
Left:=60;
Width:=frm_smServer.str.Panels[1].Width-4;
Height:=19;
Visible:=True;
ForeColor:=$000080FF;
Parent:=frm_smServer.str;
MinValue:=0;
MaxValue:=100;
end;
end;
procedure WriteLog(FileName:string;Context:string);
var
Tf:TextFile;
i:integer;
Ls:TStringList;
begin
if Context=''
then Exit;
Ls:=TStringList.Create;
AssignFile(Tf,FileName);
try
Ls.CommaText:=Context;
try
if FileExists(FileName) then Append(Tf)
else ReWrite(Tf);
for i:=0 to Ls.Count-1 do
if CurLogChk then
begin
WriteLn(Tf,FormatDateTime('dddddd hh:mm:ss',Now)+' '+Ls.Strings[i]);
WriteLn(Tf);
end;
except
end;
finally
CloseFile(Tf);
Ls.Free;
end;
end;
//返回用户信息请求信息内容//
function ResultMsg(Code:Integer):string;
var
i:integer;
begin
Result:='';
case Code of
100,101,102,103,104,105,106,107,108,800:
begin
for i:=0 to ResultCode.Count-1 do
if Copy(ResultCode.Strings[i],1,3)=IntToStr(Code) then
Result:=Copy(ResultCode.Strings[i],5,Length(ResultCode.Strings[i]));
end;
end;
end;
procedure strChanging(str:PChar;RI:Integer);
begin
with frm_smServer.str.Canvas do
begin
FillRect(Rect(pRect.Left+2,pRect.Top,pRect.Right-10,pRect.Bottom));
frm_smServer.ImageList1.Draw(frm_smServer.str.Canvas,pRect.Left+2,pRect.Top+2,RI);
if RI=1 then TextOut(pRect.Left+24,6,str);
if RI=0 then TextOut(pRect.Left+24,6,str);
end;
end;
function str_Out(str:string;x:Integer):string;
begin
frm_smServer.str.Refresh;
Result:='';
case x of
0..3:frm_smServer.str.Panels[x].Text:=str;
else
Result:=frm_smServer.str.Panels[1].Text;
end;
end;
function stbar(x:Integer):Boolean;
begin
Result:=False;
case x of
0:begin
RI:=1;
str_Out('等待接收数据...',1);
BatchSend:=True;
SingleSend:=True;
Result:=True;
Exit;
end;
-1:begin
RI:=2;
str_Out('读xboxp.ini文件出错!',1);
Exit;
end;
-2:begin
RI:=2;
str_Out('函数参数不符!',1);
Exit;
end;
-3:begin
RI:=2;
str_Out('Socket版本不符!',1);
Exit;
end;
-4:begin
RI:=0;
str_Out('连接服务器失败!',1);
Exit;
end;
-5:begin
RI:=2;
str_Out('接受服务器数据出错!',1);
Exit;
end;
-100:begin
RI:=2;
str_Out('分配内存空间失败!',1);
Exit;
end;
else Result:=True;
end;
end;
procedure CurLogMsg(Falg:integer;Msg:string);
begin
Case Falg of
0: begin
if frm_smServer.m_Rec_Win.Lines.Count<=10000 then
frm_smServer.m_Rec_Win.Lines.Add(Msg) else
begin
frm_smServer.m_Rec_Win.Clear;
frm_smServer.m_Rec_Win.Lines.Add(Msg);
end;
frm_smServer.m_Rec_Win.Lines.Add('');
end;
1: begin
if frm_smServer.mTransmit.Lines.Count<=10000 then
frm_smServer.mTransmit.Lines.Add(Msg) else
begin
frm_smServer.mTransmit.Clear;
frm_smServer.mTransmit.Lines.Add(Msg);
end;
frm_smServer.mTransmit.Lines.Add('');
end;
2: begin
if frm_smServer.mRecData.Lines.Count<=10000 then
frm_smServer.mRecData.Lines.Add(Msg) else
begin
frm_smServer.mRecData.Clear;
frm_smServer.mRecData.Lines.Add(Msg);
end;
frm_smServer.mRecData.Lines.Add('');
end;
3: begin
if frm_smServer. mRecCommand.Lines.Count<=10000 then
frm_smServer.mRecCommand.Lines.Add(Msg) else
begin
frm_smServer.mRecCommand.Clear;
frm_smServer.mRecCommand.Lines.Add(Msg);
end;
frm_smServer.mRecCommand.Lines.Add('');
end;
end;
end;
procedure ErrorMsg(Falg:Integer;ErrMsg:PChar);
begin
Case Falg of
0: Raise Exception.Create(ErrMsg);
1:MessageBox(Application.handle,ErrMsg,PChar('注意'),MB_ICONINFORMATION);
2:MessageBox(Application.handle,ErrMsg,PChar('错误'),MB_ICONSTOP);
3:MessageBox(Application.handle,ErrMsg,PChar('错误'),MB_OK);
end;
end;
procedure DataAssay(pHandle:DWord; pHand:byte;pIPAddress,pUser,pPassWord,
pCommandID,pDestNo,pChargeNo,pSvcType,pContent,pSPNumber:string);
var
aSvcType, s:string;
i:Integer;
begin
ResultValue:=0;
aSvcType:=pSvcType;
MsgResult:='';
s:=Trim(pCommandID);
if not IdentityAttest(pHand,pUser,pPassWord)
then begin
CommandID:=s;
ResultValue:=h49;
end;
if s=h01
then begin
CommandID:=h01;
if not IdentityAttest(pHand,pUser,pPassWord) then
ResultValue:=h49 else
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -