首页 > 代码库 > 搭建短信服务器

搭建短信服务器

    今天凭着积极主动的态度,把短信服务器的运行环境搭建成功,在此和大家分享下经验,希望能帮助到大家。

    1.安装Oracle客户端,原来一直使用精简版的Oracle客户端,但“创天炫彩”无法识别,只能安装Oracle官方提供的Oracle客户端,

    技术分享

     2.在Oracle客户端的tnsnames.ora配置文件添加连接串

ORCL172 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.22.51.172)(PORT = 1521))
    )
    (CONNECT_DATA =
      http://www.mamicode.com/(SERVER = DEDICATED)>

     3.安装GPRS Modem的驱动程序,插上GPRM Modem硬件;

     技术分享

     4.安装GPRM Modem的管理程序;

     技术分享

     5.创天炫彩的通道配置;

     技术分享

     6.在Oracle数据库创建程序所需的数据表,脚本如下:

create table MSG_FAILEDBOX
(
   ID                             NUMBER 			not null,
   OriginMsgID                    NUMBER 			not null, 
   ExpressLevel                   NUMBER 			default 2 not null , 
   Sender                         VARCHAR2(100),
   Receiver                       VARCHAR2(200)                  not null,
   MsgType                        NUMBER                         not null, 
   MsgTitle                       VARCHAR2(500),
   MMSContentLocation             VARCHAR2(500),
   SendTime                       DATE                           default SYSDATE not null,
   CommPort                       NUMBER                         not null, 
   ActualSendTime                 DATE                           not null,
   FailedReason                   VARCHAR2(500)
);
alter table MSG_FAILEDBOX
  add constraint MSG_FAILEDBOX_PK11075707620945 primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );



create table MSG_INBOX
(
   ID                             NUMBER not null,
   Sender                         VARCHAR2(100)                   not null,
   MsgType                        NUMBER                          not null, 
   MsgTitle                       VARCHAR2(500),   
   MMSUrl                         VARCHAR2(200),
   MMSContentLocation             VARCHAR2(4000),
   MsgArrivedTime	          DATE                      	  not null,
   MMSDownloadedTime              DATE,
   MMSDownloadedState             NUMBER                          default 0 not null ,
   CommPort                       NUMBER                    	  not null
);
alter table MSG_INBOX
  add constraint MSG_INBOX_PK21075710238559 primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );



create table MSG_OUTBOX
(
   MsgID                          NUMBER not null,
   ExpressLevel                   NUMBER                     	   default 2 not null , 
   Sender                         VARCHAR2(100),
   Receiver                       VARCHAR2(200)                    not null,
   MsgType                        NUMBER                          default 1  not null , 
   MsgTitle                       VARCHAR2(500),
   MMSContentLocation             VARCHAR2(500),
   SendTime                       DATE                           default SYSDATE not null,
   CommPort                       NUMBER                           default 0 not null 
);
alter table MSG_OUTBOX
  add constraint MSG_OUTBOX_PK21075710226041 primary key (MsgID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );


create table MSG_SENTBOX
(
   ID                             NUMBER                     not null,
   OriginMsgID                    NUMBER                     not null,
   ExpressLevel                   NUMBER                     not null,
   Sender                         VARCHAR2(100),
   Receiver                       VARCHAR2(200)              not null,
   MsgType                        NUMBER                     not null, 
   MsgTitle                       VARCHAR2(500),
   MMSContentLocation             VARCHAR2(500),
   SendTime                       DATE                       not null,
   CommPort                       NUMBER                     not null, 
   ActualSendTime                 DATE                       not null,
   ReceiveMMSTime                 DATE,
   MMSMessageID                  VARCHAR2(200)
);
alter table MSG_SENTBOX
  add constraint MSG_SENTBOX_PK21075710226041 primary key (ID)
  using index 
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );



create sequence MSG_FAILEDBOX_ID_SEQ
minvalue 1
maxvalue 999999999
start with 81
increment by 1
cache 20;


create sequence MSG_INBOX_ID_SEQ
minvalue 1
maxvalue 999999999
start with 81
increment by 1
cache 20;


create sequence MSG_OUTBOX_ID_SEQ
minvalue 1
maxvalue 999999999
start with 141
increment by 1
cache 20;


create sequence MSG_SENTBOX_ID_SEQ
minvalue 1
maxvalue 999999999
start with 81
increment by 1
cache 20;


CREATE OR REPLACE TRIGGER "SET_MSG_FAILEDBOX_ID" BEFORE INSERT
    ON "MSG_FAILEDBOX"
    FOR EACH ROW

DECLARE
  NEXT_MSG_FAILEDBOX_ID NUMBER;
BEGIN
  SELECT MSG_FAILEDBOX_ID_SEQ.NEXTVAL INTO NEXT_MSG_FAILEDBOX_ID FROM DUAL;
  :NEW.ID := NEXT_MSG_FAILEDBOX_ID;
END;
/


CREATE OR REPLACE TRIGGER "SET_MSG_INBOX_ID" BEFORE INSERT
    ON "MSG_INBOX"
    FOR EACH ROW

DECLARE
  NEXT_MSG_INBOX_ID NUMBER;
BEGIN
  SELECT MSG_OUTBOX_ID_SEQ.NEXTVAL INTO NEXT_MSG_INBOX_ID FROM DUAL;
  :NEW.ID := NEXT_MSG_INBOX_ID;
END;
/


CREATE OR REPLACE TRIGGER "SET_MSG_OUTBOX_ID" BEFORE
    INSERT  ON "MSG_OUTBOX"
FOR EACH ROW

DECLARE
  NEXT_MSG_OUTBOX_ID NUMBER;
BEGIN
  SELECT MSG_OUTBOX_ID_SEQ.NEXTVAL INTO NEXT_MSG_OUTBOX_ID FROM DUAL;
  :NEW.MsgID := NEXT_MSG_OUTBOX_ID;
END;
/


CREATE OR REPLACE TRIGGER "SET_MSG_SENTBOX_ID" BEFORE
    INSERT  ON "MSG_SENTBOX"
FOR EACH ROW

DECLARE
  NEXT_MSG_SENTBOX_ID NUMBER;
BEGIN
  SELECT MSG_SENTBOX_ID_SEQ.NEXTVAL INTO NEXT_MSG_SENTBOX_ID FROM DUAL;
  :NEW.ID := NEXT_MSG_SENTBOX_ID;
END;
/

commit;
    7.创天炫彩的数据库配置:

   技术分享
   数据库配置页面的数据库连接串名称和步骤2在tnsnames.ora中配置的连接串名称必须相同,测试连接。

   8.发送测试短信:

   技术分享

   使用方法为:向MSG_Outbox表(信息发送表)插入想要发送的短信内容,GRRS Modem硬件中的程序会把表中的数据发送到目标手机号,同时将这条记录从MSG_Outbox表删除。消息发送成功,将这条记录存储到MSG_Sentbox表(信息发送成功表);消息发送失败,将这条记录存储到MSG_Failedbox表(信息发送失败表)。MSG_Inbox表用于存储接收到的彩信/短信。

   到此,短信服务器的运行环境搭建成功,希望我的分享能够帮助大家进步。

搭建短信服务器