Delphi makes SMS sending control of GSM Modem

At present, most enterprises and schools have built intranets. And built an internal website to achieve resource sharing. In order to let users know the latest information on the Internet in time, many websites have adopted the method of mobile phone SMS reminder, but using the SP method of China Mobile or China Unicom will greatly increase the cost of enterprises. So this article discusses the use of GSM Modem and SMS sending control to realize the SMS reminder. First, let me introduce the environment I use.
  Server: Windows 2000 Advanced Server, IIS 5.0, ASP, SQL Server 2000
  Client: Windows XP or Windows 2000
  development tools delphi6.0, APRO4.06
  Install APRO controls in Delphi6 before building the project, this is the method used by the author , readers can also use comm32.
  After installing APRO as shown in Figure 1
  , create a new project.
  Select ActiveX Library
  and click OK. Save the project and name it jksms.dpr.
  Create a new automation object and

  name it: sms and click OK.
  Save the unit file and name it: main.pas.
  New method: sendmsg
  adds parameters to this method.
  Comnumber: The serial port number where the GSM Modem resides.
  Phone: The mobile phone number of the destination to be sent.
  Msg: Send message content.
  Click Refresh when done.
  Open main.pas to write a program for this method.
  The following is the program listing of main.pas:
  unit main;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
ComObj, ActiveX, jksms_TLB, StdVcl, SysUtils,windows,ADTrmEmu,
OoMisc,registry;
type
Tsms = class(TAutoObject, Isms)
protected
procedure sendmsg (comnumber: Integer; const phone, msg: WideString);
safecall;
{ Protected declarations }
end;
implementation
uses ComServ , adport;//The function needs to be manually added here
SEncodeMobNO(SmobNO: string): string;
//If you want to send Chinese SMS Modem's PDU mode must be used. This function is to PDU encoding the mobile phone number.
var
 TempPchar: Pchar;
 i: integer;
 Str: string;
begin
 if (copy(smobno, 1, 1) = '+') then //Determine whether the country code is included
  SmobNO := copy(smobno, 2, length(smobno) - 1); //Remove the '+' in the mobile phone number
 if ((length(SmobNO) mod 2) = 1) then
  SmobNO := SmobNO + 'F';
  TempPchar := Pchar(SmobNO); //Array the string Char
 i := 0;
 Str := '';
 while i < length(TempPchar) do begin
  Str := Str + TempPchar[i + 1] + TempPchar[i];
  i := i + 2;
 end;
 result := Str;
end;
function EncodeChinese(Input: WideString): string;//Encode the information content in PDU
var
 i: Integer;
begin
 Result := '';
 for i := 1 to Length(Input) do
  Result := Result + Format('%4.4X', [ord(Input [i])]);
end;
procedure Tsms.sendmsg(comnumber: Integer; const phone, msg: WideString);
//Method for sending SMS
var
 apdcomport:Tapdcomport;
 r,s,s2,s3,s4,s5:string;
 cmdlong,tmp:integer;
 msgs: WideString;
begin
 apdcomport:=TApdComPort.Create(nil);//Create serial communication object
 apdcomport.AutoOpen:=false;//Close the automatic open property
 apdcomport.Open:=false;
 apdcomport.ComNumber:=comnumber;//Set the string Line communication port
 apdcomport.Baud:=19200;//Set the serial port baud rate
 msgs:=msg;
 s:='0031000D9168';
 //PDU encoding attribute, this method does not need to set the SMS center number, because the existing The mobile phone SIM card has been written
 s2:=SEncodeMobNO(phone);// PDU encoding the mobile phone number
 s3:='0008A7';
 s4:='';
 s5:=EnCodeChinese(msgs);
 tmp:=length(s5 )div 2;
 s4:=format('%X',[tmp]);
 if length(s4)<2 then
  s4:='0'+s4;
 //Calculate PDU encoding length
 r:=s+s2+s3+s4+s5+ ^Z;
 cmdlong:=(length(r)-2) div 2;
 apdcomport.Open:=true;//Open the serial port
 apdcomport.Output:='AT+CMGF=0'#13;//Set Modem to PDU mode
 delayticks(7,true);//Delay
 apdcomport.Output:='AT+CMGS='+inttostr(cmdlong)+#13;//Set the message length, which should be 1/2 of the PDU encoding length.
 delayticks(7,true);
 apdcomport.Output:=r;//Send SMS.
 delayticks(9,true);
 apdcomport.Open:=false;
 apdcomport.Free;
end;
initialization
TAutoObjectFactory.Create(ComServer, Tsms, Class_sms,ciMultiInstance, tmApartment);
end.
  After the above program is compiled, the jksms.dll file is generated. Copy to d:/ on the web server. Run: regsvr32 d:/jksms.dll. This is used in ASP programs.
  Set sms=Server.CreateObject("jksms.sms")
Msg="Hello! Test if it works!"
Phone="Mobile phone number"
Port=Modem port number
Sms.sendmsg port,phone,msg So
  far, the control is made Finish. This control has been running in the author's unit so far, and everything is normal.
Transferred from bbs.sendsms.cn

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327045908&siteId=291194637