Unit1.pas 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. unit Unit1;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls;
  6. type
  7. TFrmDemo = class(TForm)
  8. GroupBox1: TGroupBox;
  9. ChkSingle: TCheckBox;
  10. ChkBoth: TCheckBox;
  11. ChkKfBoth: TCheckBox;
  12. GroupBox2: TGroupBox;
  13. Label5: TLabel;
  14. EdServer: TEdit;
  15. BtConn: TButton;
  16. Label6: TLabel;
  17. Edaccount: TEdit;
  18. Label7: TLabel;
  19. EdPort: TEdit;
  20. Label8: TLabel;
  21. Edpwd: TEdit;
  22. BtDisConn: TButton;
  23. BtTest: TButton;
  24. GroupBox3: TGroupBox;
  25. Label9: TLabel;
  26. Label10: TLabel;
  27. Label11: TLabel;
  28. Label12: TLabel;
  29. Edspno: TEdit;
  30. Edlinkid: TEdit;
  31. Edfee: TEdit;
  32. Edcount: TEdit;
  33. Edphone: TEdit;
  34. Label1: TLabel;
  35. Label2: TLabel;
  36. BtSend: TButton;
  37. Mmsg: TMemo;
  38. BtRecv: TButton;
  39. BtReport: TButton;
  40. GroupBox4: TGroupBox;
  41. Label3: TLabel;
  42. Ednewpwd: TEdit;
  43. BtPwd: TButton;
  44. BtLeft: TButton;
  45. BtUsed: TButton;
  46. GroupBox5: TGroupBox;
  47. MInfo: TMemo;
  48. procedure BtConnClick(Sender: TObject);
  49. procedure FormCreate(Sender: TObject);
  50. procedure BtSendClick(Sender: TObject);
  51. procedure BtDisConnClick(Sender: TObject);
  52. procedure BtRecvClick(Sender: TObject);
  53. procedure BtReportClick(Sender: TObject);
  54. procedure ChkSingleClick(Sender: TObject);
  55. procedure EdPortKeyPress(Sender: TObject; var Key: Char);
  56. procedure BtTestClick(Sender: TObject);
  57. procedure EdcountKeyPress(Sender: TObject; var Key: Char);
  58. procedure BtUsedClick(Sender: TObject);
  59. procedure BtLeftClick(Sender: TObject);
  60. procedure BtPwdClick(Sender: TObject);
  61. private
  62. { Private declarations }
  63. public
  64. function Noconn():boolean;
  65. { Public declarations }
  66. end;
  67. var
  68. FrmDemo: TFrmDemo;
  69. mysock:integer;
  70. implementation
  71. {$R *.dfm}
  72. function MongateConnect(serverip:string;port:integer;account,password:string ):integer;
  73. stdcall;external 'MWGateway.dll';
  74. function MongateConnectHttp(serverip:string;port:integer;account,password:string ):integer;
  75. stdcall;external 'MWGateway.dll';
  76. function MongateSendSms(socket:integer;mobi,msg:string):integer;
  77. stdcall; external 'MWGateway.DLL';
  78. function MongateTestConn(socket:integer):integer;
  79. stdcall; external 'MWGateway.DLL';
  80. function MongateQueryBalance(socket:integer):integer;
  81. stdcall; external 'MWGateway.DLL';
  82. function MongateQueryUsed(socket:integer):integer;
  83. stdcall; external 'MWGateway.DLL';
  84. function MongateRecharge(socket:integer;cardno,cardpwd:string):integer;
  85. stdcall; external 'MWGateway.DLL';
  86. function MongateChangePwd(socket:integer;account,oldpwd,newpwd:string):integer;
  87. stdcall; external 'MWGateway.DLL';
  88. procedure MongateDisconnect(socket:integer);
  89. stdcall; external 'MWGateway.DLL';
  90. function MongateVasGetSms(socket:integer;recvmsg:pchar):integer;
  91. stdcall; external 'MWGateway.DLL';
  92. function MongateVasSendSms(socket:integer; feecode,spno,opercode,linkid,mobis,msg:string;
  93. icount:integer):integer; stdcall; external 'MWGateway.DLL';
  94. function MongateCsGetSms(socket:integer;statereport:pchar):integer;
  95. stdcall; external 'MWGateway.DLL';
  96. function MongateCsSendSms(socket:integer; mobi,note:string;icount:integer;
  97. msgno:pchar):integer; stdcall; external 'MWGateway.DLL';
  98. function MongateCsSendSmsHttp(socket:integer; mobi,note:string;icount:integer;
  99. msgno:pchar):integer; stdcall; external 'MWGateway.DLL';
  100. function MongateCsGetStatusReport(socket:integer;recvmsg:pchar):integer;
  101. stdcall; external 'MWGateway.DLL';
  102. function TFrmDemo.Noconn():boolean;
  103. begin
  104. result:=false;
  105. if mysock<=0 then begin
  106. MInfo.Lines.Insert(0,'没有连接到任何服务器!!!');
  107. result:=true;
  108. end;
  109. end;
  110. procedure TFrmDemo.BtConnClick(Sender: TObject);
  111. var
  112. tmpport:integer;
  113. begin
  114. if trim(EdPort.Text)='' then tmpport:=8018
  115. else tmpport:=strtoint(EdPort.Text);
  116. if(mysock<=0) then begin
  117. mysock :=MongateConnect(trim(EdServer.Text),tmpport,
  118. // mysock :=MongateConnectHttp(trim(EdServer.Text),tmpport,
  119. trim(Edaccount.Text),trim(Edpwd.Text));
  120. if(mysock>0) then
  121. MInfo.Lines.Insert(0,'连接成功!连接句柄:'+inttostr(mysock))
  122. else
  123. MInfo.Lines.Insert(0,'连接失败!错误代码为:'+inttostr(mysock));
  124. end;
  125. if mysock>0 then begin
  126. BtConn.Enabled:=false;
  127. BtDisConn.Enabled:=true;
  128. end
  129. end;
  130. procedure TFrmDemo.FormCreate(Sender: TObject);
  131. begin
  132. mysock :=0;
  133. end;
  134. procedure TFrmDemo.BtRecvClick(Sender: TObject);
  135. var
  136. n,i:integer;
  137. s:array[0..499,0..254] of char;
  138. p:pchar;
  139. tempstr,tmpport:string;
  140. begin
  141. if(mysock>0) then begin
  142. p :=@s[0][0];
  143. if ChkKfBoth.Checked then begin
  144. n := MongateCsGetSms(mysock, p);
  145. tmpport:='客服'
  146. end
  147. else begin
  148. n := MongateVasGetSms(mysock, p);
  149. tmpport:='增值'
  150. end;
  151. if(n>0)then begin
  152. for i :=0 to n-1 do begin
  153. p := @s[i][0];
  154. tempstr := StrPas(p);
  155. MInfo.Lines.Insert(0,tmpport+'收到信息:'+tempstr);
  156. end
  157. end
  158. else begin
  159. if(n=0) then
  160. MInfo.Lines.Insert(0,'接收'+tmpport+'接收无信息!')
  161. else
  162. MInfo.Lines.Insert(0,'接收'+tmpport+'信息出错!返回:'
  163. +inttostr(n)+')');
  164. end;
  165. end;
  166. end;
  167. procedure TFrmDemo.BtSendClick(Sender: TObject);
  168. var
  169. re,icount:integer;
  170. msgno:pchar;
  171. begin
  172. if Noconn then exit;
  173. if trim(Edcount.Text)='' then icount:=1
  174. else icount:=strtoint(edcount.Text);
  175. if ChkBoth.Checked then begin //增值信息
  176. re :=MongateVasSendSms(mysock,trim(Edfee.Text),
  177. trim(Edspno.Text),'00********',trim(Edlinkid.Text),
  178. trim(Edphone.Text), trim(Mmsg.Text),icount);
  179. if(re=1) then
  180. MInfo.Lines.Insert(0,'发送增值信息成功!')
  181. else
  182. MInfo.Lines.Insert(0,'发送增值信息失败!返回:'+inttostr(re));
  183. end
  184. else if ChkKfBoth.Checked then begin //客服信息
  185. GetMem(msgno,30);
  186. re :=MongateCsSendSms(mysock,trim(Edphone.Text),trim(Mmsg.Text),icount,msgno);
  187. //re :=MongateCsSendSmsHttp(mysock,trim(Edphone.Text),trim(Mmsg.Text),icount,msgno);
  188. if(re=1) then
  189. MInfo.Lines.Insert(0,'发送客服信息成功!信息编号:'+msgno)
  190. else
  191. MInfo.Lines.Insert(0,'发送客服信息失败!返回:'+inttostr(re));
  192. end
  193. else begin //单向信息
  194. re :=MongateSendSms(mysock,trim(Edphone.Text),
  195. trim(Mmsg.Text));
  196. if(re=1) then
  197. MInfo.Lines.Insert(0,'发送单向信息成功')
  198. else
  199. MInfo.Lines.Insert(0,'发送单向信息失败!返回:'+inttostr(re));
  200. end;
  201. end;
  202. procedure TFrmDemo.BtDisConnClick(Sender: TObject);
  203. begin
  204. if(mysock>0) then begin
  205. MongateDisConnect(mysock);
  206. MInfo.Lines.Insert(0,'断开连接!'+inttostr(mysock));
  207. BtConn.Enabled:=true;
  208. BtDisConn.Enabled:=false;
  209. mysock :=0;
  210. end; //BtDisConn
  211. end;
  212. procedure TFrmDemo.BtReportClick(Sender: TObject);
  213. var
  214. n,i:integer;
  215. s:array[0..499,0..254] of char;
  216. p:pchar;
  217. tempstr:string;
  218. begin
  219. if(mysock>0) then
  220. begin //BtReport
  221. p :=@s[0][0];
  222. n := MongateCsGetStatusReport(mysock, p);
  223. if(n>0)then begin
  224. for i :=0 to n-1 do begin
  225. p := @s[i][0];
  226. tempstr := StrPas(p);
  227. MInfo.Lines.Insert(0,'收到状态报告:'+tempstr);
  228. end;
  229. end
  230. else
  231. begin
  232. if(n=0) then
  233. MInfo.Lines.Insert(0,'无状态报告!')
  234. else
  235. MInfo.Lines.Insert(0,'读取状态报告出错!返回:'
  236. +inttostr(n));
  237. end;
  238. end;
  239. end;
  240. procedure TFrmDemo.ChkSingleClick(Sender: TObject);
  241. procedure showme(edtmp:tedit;flag:boolean);
  242. begin
  243. edtmp.Enabled:=flag;
  244. if flag then edtmp.Color:=clWhite
  245. else edtmp.Color:=clScrollBar;
  246. end;
  247. begin
  248. if sender =ChkSingle then begin
  249. if ChkSingle.Checked then begin
  250. ChkBoth.Checked:=false;
  251. ChkKfBoth.Checked:=false;
  252. end;
  253. end;
  254. if sender =ChkBoth then begin
  255. if ChkBoth.Checked then begin
  256. ChkSingle.Checked:=false;
  257. ChkKfBoth.Checked:=false;
  258. end;
  259. end;
  260. if sender =ChkKfBoth then begin
  261. if ChkKfBoth.Checked then begin
  262. ChkBoth.Checked:=false;
  263. ChkSingle.Checked:=false;
  264. end;
  265. end;
  266. showme(Edspno,ChkBoth.Checked);
  267. showme(Edfee,ChkBoth.Checked);
  268. showme(Edlinkid,ChkBoth.Checked);
  269. showme(Edcount,(ChkBoth.Checked or ChkKfBoth.Checked));
  270. if ChkBoth.Checked then BtSend.Caption:='增值信息'
  271. else if ChkKfBoth.Checked then BtSend.Caption:='客服信息'
  272. else BtSend.Caption:='单向信息';
  273. BtRecv.Enabled:=ChkBoth.Checked or ChkKfBoth.Checked;
  274. BtReport.Enabled:=ChkKfBoth.Checked;
  275. end;
  276. procedure TFrmDemo.EdPortKeyPress(Sender: TObject; var Key: Char);
  277. begin
  278. if ((key<'0') or (key>'9')) and (key<>#8) then key:=#0;
  279. end;
  280. procedure TFrmDemo.BtTestClick(Sender: TObject);
  281. var
  282. irec:integer;
  283. begin
  284. if Noconn then exit;
  285. irec:=MongateTestConn(mysock);
  286. if irec=1 then MInfo.Lines.Insert(0,'测试连接成功!')
  287. else begin
  288. MInfo.Lines.Insert(0,'测试连接失败!返回:'+inttostr(irec));
  289. if (irec <0) and (irec >-300) then BtDisConnClick(nil);//断开连接
  290. end;
  291. end;
  292. procedure TFrmDemo.EdcountKeyPress(Sender: TObject; var Key: Char);
  293. begin
  294. if ((key<'0') or (key>'9')) and (key<>#8) then key:=#0;
  295. end;
  296. procedure TFrmDemo.BtUsedClick(Sender: TObject);
  297. var
  298. irec:integer;
  299. begin
  300. if Noconn then exit;
  301. irec:=MongateQueryUsed(mysock);
  302. if irec>0 then
  303. MInfo.Lines.Insert(0,'查询使用成功!已用:'+inttostr(irec))
  304. else
  305. MInfo.Lines.Insert(0,'查询使用失败!返回:'+inttostr(irec));
  306. end;
  307. procedure TFrmDemo.BtLeftClick(Sender: TObject);
  308. var
  309. irec:integer;
  310. begin
  311. if Noconn then exit;
  312. irec:=MongateQueryBalance(mysock);
  313. if irec>0 then
  314. MInfo.Lines.Insert(0,'查询余额成功!剩余:'+inttostr(irec))
  315. else
  316. MInfo.Lines.Insert(0,'查询余额失败!返回:'+inttostr(irec));
  317. end;
  318. procedure TFrmDemo.BtPwdClick(Sender: TObject);
  319. var
  320. irec:integer;
  321. begin
  322. if Noconn then exit;
  323. irec:=MongateChangePwd(mysock,trim(Edaccount.Text),
  324. trim(Edpwd.Text),trim(Ednewpwd.Text));
  325. if irec=1 then
  326. MInfo.Lines.Insert(0,'修改密码成功,请记住新密码!')
  327. else
  328. MInfo.Lines.Insert(0,'修改密码失败!返回:'+inttostr(irec));
  329. end;
  330. end.