unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TFrmDemo = class(TForm) GroupBox1: TGroupBox; ChkSingle: TCheckBox; ChkBoth: TCheckBox; ChkKfBoth: TCheckBox; GroupBox2: TGroupBox; Label5: TLabel; EdServer: TEdit; BtConn: TButton; Label6: TLabel; Edaccount: TEdit; Label7: TLabel; EdPort: TEdit; Label8: TLabel; Edpwd: TEdit; BtDisConn: TButton; BtTest: TButton; GroupBox3: TGroupBox; Label9: TLabel; Label10: TLabel; Label11: TLabel; Label12: TLabel; Edspno: TEdit; Edlinkid: TEdit; Edfee: TEdit; Edcount: TEdit; Edphone: TEdit; Label1: TLabel; Label2: TLabel; BtSend: TButton; Mmsg: TMemo; BtRecv: TButton; BtReport: TButton; GroupBox4: TGroupBox; Label3: TLabel; Ednewpwd: TEdit; BtPwd: TButton; BtLeft: TButton; BtUsed: TButton; GroupBox5: TGroupBox; MInfo: TMemo; procedure BtConnClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure BtSendClick(Sender: TObject); procedure BtDisConnClick(Sender: TObject); procedure BtRecvClick(Sender: TObject); procedure BtReportClick(Sender: TObject); procedure ChkSingleClick(Sender: TObject); procedure EdPortKeyPress(Sender: TObject; var Key: Char); procedure BtTestClick(Sender: TObject); procedure EdcountKeyPress(Sender: TObject; var Key: Char); procedure BtUsedClick(Sender: TObject); procedure BtLeftClick(Sender: TObject); procedure BtPwdClick(Sender: TObject); private { Private declarations } public function Noconn():boolean; { Public declarations } end; var FrmDemo: TFrmDemo; mysock:integer; implementation {$R *.dfm} function MongateConnect(serverip:string;port:integer;account,password:string ):integer; stdcall;external 'MWGateway.dll'; function MongateConnectHttp(serverip:string;port:integer;account,password:string ):integer; stdcall;external 'MWGateway.dll'; function MongateSendSms(socket:integer;mobi,msg:string):integer; stdcall; external 'MWGateway.DLL'; function MongateTestConn(socket:integer):integer; stdcall; external 'MWGateway.DLL'; function MongateQueryBalance(socket:integer):integer; stdcall; external 'MWGateway.DLL'; function MongateQueryUsed(socket:integer):integer; stdcall; external 'MWGateway.DLL'; function MongateRecharge(socket:integer;cardno,cardpwd:string):integer; stdcall; external 'MWGateway.DLL'; function MongateChangePwd(socket:integer;account,oldpwd,newpwd:string):integer; stdcall; external 'MWGateway.DLL'; procedure MongateDisconnect(socket:integer); stdcall; external 'MWGateway.DLL'; function MongateVasGetSms(socket:integer;recvmsg:pchar):integer; stdcall; external 'MWGateway.DLL'; function MongateVasSendSms(socket:integer; feecode,spno,opercode,linkid,mobis,msg:string; icount:integer):integer; stdcall; external 'MWGateway.DLL'; function MongateCsGetSms(socket:integer;statereport:pchar):integer; stdcall; external 'MWGateway.DLL'; function MongateCsSendSms(socket:integer; mobi,note:string;icount:integer; msgno:pchar):integer; stdcall; external 'MWGateway.DLL'; function MongateCsSendSmsHttp(socket:integer; mobi,note:string;icount:integer; msgno:pchar):integer; stdcall; external 'MWGateway.DLL'; function MongateCsGetStatusReport(socket:integer;recvmsg:pchar):integer; stdcall; external 'MWGateway.DLL'; function TFrmDemo.Noconn():boolean; begin result:=false; if mysock<=0 then begin MInfo.Lines.Insert(0,'没有连接到任何服务器!!!'); result:=true; end; end; procedure TFrmDemo.BtConnClick(Sender: TObject); var tmpport:integer; begin if trim(EdPort.Text)='' then tmpport:=8018 else tmpport:=strtoint(EdPort.Text); if(mysock<=0) then begin mysock :=MongateConnect(trim(EdServer.Text),tmpport, // mysock :=MongateConnectHttp(trim(EdServer.Text),tmpport, trim(Edaccount.Text),trim(Edpwd.Text)); if(mysock>0) then MInfo.Lines.Insert(0,'连接成功!连接句柄:'+inttostr(mysock)) else MInfo.Lines.Insert(0,'连接失败!错误代码为:'+inttostr(mysock)); end; if mysock>0 then begin BtConn.Enabled:=false; BtDisConn.Enabled:=true; end end; procedure TFrmDemo.FormCreate(Sender: TObject); begin mysock :=0; end; procedure TFrmDemo.BtRecvClick(Sender: TObject); var n,i:integer; s:array[0..499,0..254] of char; p:pchar; tempstr,tmpport:string; begin if(mysock>0) then begin p :=@s[0][0]; if ChkKfBoth.Checked then begin n := MongateCsGetSms(mysock, p); tmpport:='客服' end else begin n := MongateVasGetSms(mysock, p); tmpport:='增值' end; if(n>0)then begin for i :=0 to n-1 do begin p := @s[i][0]; tempstr := StrPas(p); MInfo.Lines.Insert(0,tmpport+'收到信息:'+tempstr); end end else begin if(n=0) then MInfo.Lines.Insert(0,'接收'+tmpport+'接收无信息!') else MInfo.Lines.Insert(0,'接收'+tmpport+'信息出错!返回:' +inttostr(n)+')'); end; end; end; procedure TFrmDemo.BtSendClick(Sender: TObject); var re,icount:integer; msgno:pchar; begin if Noconn then exit; if trim(Edcount.Text)='' then icount:=1 else icount:=strtoint(edcount.Text); if ChkBoth.Checked then begin //增值信息 re :=MongateVasSendSms(mysock,trim(Edfee.Text), trim(Edspno.Text),'00********',trim(Edlinkid.Text), trim(Edphone.Text), trim(Mmsg.Text),icount); if(re=1) then MInfo.Lines.Insert(0,'发送增值信息成功!') else MInfo.Lines.Insert(0,'发送增值信息失败!返回:'+inttostr(re)); end else if ChkKfBoth.Checked then begin //客服信息 GetMem(msgno,30); re :=MongateCsSendSms(mysock,trim(Edphone.Text),trim(Mmsg.Text),icount,msgno); //re :=MongateCsSendSmsHttp(mysock,trim(Edphone.Text),trim(Mmsg.Text),icount,msgno); if(re=1) then MInfo.Lines.Insert(0,'发送客服信息成功!信息编号:'+msgno) else MInfo.Lines.Insert(0,'发送客服信息失败!返回:'+inttostr(re)); end else begin //单向信息 re :=MongateSendSms(mysock,trim(Edphone.Text), trim(Mmsg.Text)); if(re=1) then MInfo.Lines.Insert(0,'发送单向信息成功') else MInfo.Lines.Insert(0,'发送单向信息失败!返回:'+inttostr(re)); end; end; procedure TFrmDemo.BtDisConnClick(Sender: TObject); begin if(mysock>0) then begin MongateDisConnect(mysock); MInfo.Lines.Insert(0,'断开连接!'+inttostr(mysock)); BtConn.Enabled:=true; BtDisConn.Enabled:=false; mysock :=0; end; //BtDisConn end; procedure TFrmDemo.BtReportClick(Sender: TObject); var n,i:integer; s:array[0..499,0..254] of char; p:pchar; tempstr:string; begin if(mysock>0) then begin //BtReport p :=@s[0][0]; n := MongateCsGetStatusReport(mysock, p); if(n>0)then begin for i :=0 to n-1 do begin p := @s[i][0]; tempstr := StrPas(p); MInfo.Lines.Insert(0,'收到状态报告:'+tempstr); end; end else begin if(n=0) then MInfo.Lines.Insert(0,'无状态报告!') else MInfo.Lines.Insert(0,'读取状态报告出错!返回:' +inttostr(n)); end; end; end; procedure TFrmDemo.ChkSingleClick(Sender: TObject); procedure showme(edtmp:tedit;flag:boolean); begin edtmp.Enabled:=flag; if flag then edtmp.Color:=clWhite else edtmp.Color:=clScrollBar; end; begin if sender =ChkSingle then begin if ChkSingle.Checked then begin ChkBoth.Checked:=false; ChkKfBoth.Checked:=false; end; end; if sender =ChkBoth then begin if ChkBoth.Checked then begin ChkSingle.Checked:=false; ChkKfBoth.Checked:=false; end; end; if sender =ChkKfBoth then begin if ChkKfBoth.Checked then begin ChkBoth.Checked:=false; ChkSingle.Checked:=false; end; end; showme(Edspno,ChkBoth.Checked); showme(Edfee,ChkBoth.Checked); showme(Edlinkid,ChkBoth.Checked); showme(Edcount,(ChkBoth.Checked or ChkKfBoth.Checked)); if ChkBoth.Checked then BtSend.Caption:='增值信息' else if ChkKfBoth.Checked then BtSend.Caption:='客服信息' else BtSend.Caption:='单向信息'; BtRecv.Enabled:=ChkBoth.Checked or ChkKfBoth.Checked; BtReport.Enabled:=ChkKfBoth.Checked; end; procedure TFrmDemo.EdPortKeyPress(Sender: TObject; var Key: Char); begin if ((key<'0') or (key>'9')) and (key<>#8) then key:=#0; end; procedure TFrmDemo.BtTestClick(Sender: TObject); var irec:integer; begin if Noconn then exit; irec:=MongateTestConn(mysock); if irec=1 then MInfo.Lines.Insert(0,'测试连接成功!') else begin MInfo.Lines.Insert(0,'测试连接失败!返回:'+inttostr(irec)); BtDisConnClick(nil);//断开连接 end; end; procedure TFrmDemo.EdcountKeyPress(Sender: TObject; var Key: Char); begin if ((key<'0') or (key>'9')) and (key<>#8) then key:=#0; end; procedure TFrmDemo.BtUsedClick(Sender: TObject); var irec:integer; begin if Noconn then exit; irec:=MongateQueryUsed(mysock); if irec>0 then MInfo.Lines.Insert(0,'查询使用成功!已用:'+inttostr(irec)) else MInfo.Lines.Insert(0,'查询使用失败!返回:'+inttostr(irec)); end; procedure TFrmDemo.BtLeftClick(Sender: TObject); var irec:integer; begin if Noconn then exit; irec:=MongateQueryBalance(mysock); if irec>0 then MInfo.Lines.Insert(0,'查询余额成功!剩余:'+inttostr(irec)) else MInfo.Lines.Insert(0,'查询余额失败!返回:'+inttostr(irec)); end; procedure TFrmDemo.BtPwdClick(Sender: TObject); var irec:integer; begin if Noconn then exit; irec:=MongateChangePwd(mysock,trim(Edaccount.Text), trim(Edpwd.Text),trim(Ednewpwd.Text)); if irec=1 then MInfo.Lines.Insert(0,'修改密码成功,请记住新密码!') else MInfo.Lines.Insert(0,'修改密码失败!返回:'+inttostr(irec)); end; end.