⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sgip_api.dpr

📁 SPIG1.1.rar SPIG接口协议
💻 DPR
📖 第 1 页 / 共 2 页
字号:
library SGIP_API;

////////////////////////////////////////////////////////////////////////////
//                      说明:中国联通SGIP1.2接口库程序                    //
//                      作者:李定华                                       //
//                      Email:best@hb165.com                              //
//                      版本:1.0 2003/11/05                               //
////////////////////////////////////////////////////////////////////////////

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  ShareMem,
  Classes,
  Registry,
  Math,
  Windows,
  Winsock,
  SysUtils,
  ActiveX,
  ShellApi;

function FmtChar(const Source:LongWord;Len:byte):string;stdcall;external 'Sys32DLL.dll';


//SGIP1.1 消息体
type
  THead = record
     MessageLength : array[0..3] of byte;   //消息的总长度(字节)
     CommandID     : array[0..3] of byte;   //命令ID
     Sequence_No   : array[0..11] of byte;  //序列号
  end;

//SGIP1.1 Bind数据体
type
  TBind = record
     LoginType : array[0..3] of byte;        //登陆类型;1:SP向SMG建立的连接,用于发送命令
                                             //11:SP与SMG建立的测试连接用于跟踪测试
     LoginName : array[0..15] of Char;       //登陆名
     LoginPassword: array[0..15] of Char;    //登陆的密码
     Reserve      : array[0..7] of Char;     //保留
  end;

//SGIP1.1 Bind_Resp数据体
type
  Bind_Resp = record
     Result  : byte;
     Reserve : array[0..7] of Char;
  end;

//无消息体Unbind

//SGIP1.1 Submit数据体
type
  Submits = record
     SPNumber     : array[0..20] of Char;      //sp的接入号码
     ChargeNumber : array[0..20] of Char;      //付费号码
     UserCount    : byte;                      //接收短消息的手机数量
     UserNumber   : array[0..20] of Char;      //接收该短消息的手机号
     CorpID       : array[0..4] of Char;       //企业代码,0-99999
     ServiceType  : array[0..9] of Char;       //业务代码,由sp定义
     FeeType      : byte;                      //计费类型:
                                               //0:短消息类型为”发送“对”计费用户号码“不计费,此类话单仅用于核减SP对称的信道费。
                                               //1:对计费号码免费
                                               //2:对计费号码按条计信息费
                                               //3:对计费号码按包月收取信息费
                                               //4:对计费号码的收费是由SP实现
     FeeValue     : array[0..5] of Char;       //该条短消息的收费值,单位为分
     GivenValue   : array[0..5] of Char;       //赠送用户的话费,0-99999
     AgentFlag    : byte;                      //代收费标志,0:应收;1:实收
     MorelatetoMTFlag : byte;                  //引起MT消息的原因
     Priority     : byte;                      //优先级0-9,从低到高
     ExpireTime   : array[0..15] of Char;      //短消息寿命的终止时间,"yymmddhhmmsstnnp","tnnp"取固定值"032+"
     ScheduleTime : array[0..15] of Char;      //定时发送时间
     ReportFlag   : byte;                      //状态报告标志,0-出错返回状态报告;1-总返回状态报告;2-不要状态报告;3...
     TpPid        : byte;
     Udhi         : byte;
     MessageCoding: byte;                       //编码方式,0:Ascii;3:Write card;4:binary;8:ucs2;15:GBK
     MessageType  : byte;                       //0:短消息信息
     MsgLen       : Integer;                    //短消息长度
     MsgContent   : array of Char;              //短消息内容
     Reserved     : array[0..7] of Char;        //保留
  end;

//SGIP1.1 Submit_Resp数据体
type
  Submit_Resp = record
     Result  : byte;                  //Subimt命令是否成功接收;0:成功;
     Reserve : array[0..7] of Char;
  end;

//SGIP1.1 Deliver数据体
type
  Deliver = record
     UserNumber    : array[0..20] of Char;   //发送短消息的用户手机号,手机号码前加"86"国别标志
     SPNumber      : array[0..20] of Char;   //SP的接入号码
     TP_pid        : byte;
     TP_udhi       : byte;
     MessageCoding : byte;                   //短消息的编码格式
     MessageLength : Integer;                //短消息的长度
     MessageContent: array of Char;          //短消息的内容
     Reserve       : array[0..7] of Char;    //保留
   end;

//SGIP1.1 Deliver_Resp数据体
type
  Deliver_Resp = record
     Result : byte;
     Reserve: array[0..7] of Char;
  end;

//SGIP1.1 Report数据体
type
  Report = record
     SubmitSequenceNumber : array[0..11] of byte;  //该命令所涉及的Submit或Deliver命令的序列号
     ReportType : byte;                            //0:对先前一条Submit命令的状态报告
                                                   //1:对先前一条前转Deliver命令的状态报告
     UserNumber : array[0..20] of Char;            //接收短消息的手机号码
     State      : byte;
     ErrorCode  : byte;
     Reserve    : array[0..7] of Char;
  end;

//SGIP1.1 Report_Resp数据体
type
  Report_Resp = record
     Result : byte;
     Reserve: array[0..7] of Char;
  end;
//应答Result的值为0:接收成功;其它错误

const
 //客户端向服务端请求消息ID
 SGIP_BIND         = $00000001;     //客户端向服务器请求连接
 SGIP_UNBIND       = $00000002;     //客户端向服务器端通知短开当前的连接
 SGIP_SUBMIT	   = $00000003;     //客户端向服务器端发送一条MT短消息
 SGIP_DELIVER	   = $00000004;     //客户端向服务端发送一条MO短消息
 SGIP_REPORT	   = $00000005;     //客户端向服务器端发送一条MT或MO的发送结果
 //服务器返回请求消息ID
 SGIP_BIND_RESP    = $80000001;     //服务器端对接收到的Bind,命令的响应
 SGIP_UNBIND_RESP  = $80000002;     //服务器端对接收的Unbind命令的响应
 SGIP_SUBMIT_RESP  = $80000003;     //服务器端向从客户端接收到的Submit命令发送的应答消息
 SGIP_DELIVER_RESP = $80000004;     //服务器端向从客户端接收到的Deliver命令发送的应答消息
 SGIP_REPORT_RESP  = $80000005;     //服务器端向从客户端接收到的Report命令发送应答消息]
 {消息格式的定义}
 MSG_FMT_ASCII	   = $0;            //纯ASCII字符串
 MSG_FMT_WRITE_CARD= $3;	    //写卡操作
 MSG_FMT_BINARY	   = $4;            //二进制编码
 MSG_FMT_UCS2	   = $8;            //UCS2编码
 MSG_FMT_GB	   = $0F;           //GBK编码
 MSG_FMT_OTA	   = $F6;           //OTA操作时的编码方式

 Head_Len	   = SizeOf(THead);        //消息头的长度
 Bind_Len          = SizeOf(TBind);        //绑定消息体的长度
 Submits_Len       = SizeOf(Submits);       //MT消息体的长度
 Deliver_Len       = SizeOf(Deliver);      //MO消息体的长度
 Report_Len        = SizeOf(Report);        //Report消息体的长度

{$R *.res}

var
  BufferLine :TStringList;
  CommandLine:TStringList;
  Reg:TRegistry;
  SaveExit:Pointer;
  { 定义短信参数 }
  ReportFalg:string;
  MessageCoding:string;
  IPAddr: string;                 // 短消息中心IP地址
  Port: Integer;                  // 短消息中心Socket端口号
  UserName: string;               // 登陆名
  PassWord: string;               // 密码
  SPCode:string;                  //企业代码
  Sequence_No: LongWord;          // 消息编号(单调递增)

{
  Function ID=9000
  对收到短信进行解码
}
{ 十六进制字符串转换为ASCII字符串 }
function HexStrToStr(Source:string):string;stdcall;
var
  i:integer;
begin
  Result:='';
  for i:=0 to  (Length(Source) div 2)-1 do
    Result:=Result+Char(StrToInt('$'+Copy(Source,2*i+1,2)));
end;

{ 字符串到对应的十六进制串 }
function StrToHex(Source:string):string;stdcall;
var
  i:integer;
begin
  Result:='';
  for i:=1 to Length(Source) do
    Result:=Result+IntToHex(Ord(Source[i]),2);
end;

{ 长整数字符串转换为对应的二进制字符串 }
function IntToBin(Source:string):string;stdcall;
var
  i,j,k,l,m:integer;
  Temp,Rs,Ts,Res:string;
begin
  Result:='';
  if Source='' then Exit;
  Ts:=Source; Res:='';
  repeat
    Temp:=Source;
    Rs:=''; k:=0; m:=0;
    while Length(Source)>8 do
      begin
        // 拷贝8个字符
        Temp:=Copy(Source,1,8);
        Source:=Copy(Source,9,Length(Source)-8);
        // 转换为整数
        i:=StrToInt(Temp);
        j:=i div 2; k:=i mod 2;
        if (m=0) and (Length(IntToStr(j))<Length(Temp))
          then begin
            for l:=1 to Length(Temp)-Length(IntToStr(j)) do
              Rs:=Rs+'0';
          end;
        Rs:=Rs+IntToStr(j);
        // 向后传递余数
        if k=1
          then Source:='1'+Source;
        m:=k
      end;
    i:=StrToInt(Source);
    j:=i div 2; m:=i mod 2;
    if (k=0) and (Length(IntToStr(j))<Length(Source))
      then begin
        for l:=1 to Length(Source)-Length(IntToStr(j)) do
          Rs:=Rs+'0';
      end;
    Rs:=Rs+IntToStr(j);
    while Rs[1]='0' do
      Rs:=Copy(Rs,2,Length(Rs)-1);
    Res:=IntToStr(m)+Res;
    Ts:=Rs; Source:=Ts;
  until (Ts='1') or (Ts='0');
  Res:=Ts+Res;
  Result:=Res;
end;

{ 二进制字符串转换为十六进制字符串 }
function BinToHex(Source:string):string;stdcall;
var
  i,j:integer;
  s,t:string;
begin
  Result:='';
  if Source='' then Exit;
  t:='';
  i:=Length(Source) mod 4;
  if i>0
    then begin
      for j:=1 to 4-i do
        Source:='0'+Source;
    end;
  for i:=1 to (Length(Source) div 4) do
    begin
      s:=Copy(Source,(i-1)*4+1,4);
      if s='0000' then t:=t+'0';
      if s='0001' then t:=t+'1';
      if s='0010' then t:=t+'2';
      if s='0011' then t:=t+'3';
      if s='0100' then t:=t+'4';
      if s='0101' then t:=t+'5';
      if s='0110' then t:=t+'6';
      if s='0111' then t:=t+'7';
      if s='1000' then t:=t+'8';
      if s='1001' then t:=t+'9';
      if s='1010' then t:=t+'A';
      if s='1011' then t:=t+'B';
      if s='1100' then t:=t+'C';
      if s='1101' then t:=t+'D';
      if s='1110' then t:=t+'E';
      if s='1111' then t:=t+'F';
    end;
  if (Length(t) mod 2)=1 then t:='0'+t;
  Result:=t;
end;

{ 十六进制字符串转换为二进制字符串 }
function HexToBin(Source:string):string;stdcall;
var
  i:integer;
  t:string;
begin
  Result:='';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -