Linux安裝短信貓
一、需要的資源
1、短信貓硬件
2、串口驅動(comm - windows 或者 RxTx - linux)
Comm 串口驅動是windows系統使用;
RxTx 串口驅動是linux系統使用的;
3、smsLib開發包
短信二次開發工具包;
4、jetty(可選,以服務的方式部署需要);
這里使用jetty7.6.14下載地址:
修改smsLib源代碼方便編譯
二、安裝說明
短信貓驅動安裝(這里只說linux安裝方法,window和linux安裝類型):
1、解壓rxtx-2.1.7-bins-r2.zip ,這個是串口驅動類
2、將RXTXcomm.jar 放到 jdk1.6\jre\lib\ext目錄下
3、將lib中的linx/x86_64-unknown-linux-gnu/librxtxSerial.so 放到jdk1.6\jre\lib\amd64(64位)目錄下(驅動程序)
測試短信貓是否安裝成功
1、解壓smslib-v3.5.3壓縮包,運行smslib-v3.5.3\src\java\misc\CommTest.java類
如果顯示“Found: XXX”則表示短信貓硬件配置成功
三、部署SMSServer
1、創建文件夾“sms-server”,拷貝下列文件,目錄機構如下:
1. lib,庫文件
1. commons-net-3.0.1.jar,來自“smslib-v3.5.2/lib/”
2. jsmpp-2.1.0.jar,來自“smslib-v3.5.2/lib/”
3. servlet-api-2.5.jar,來自Jetty7
4. slf4j-log4j12-1.6.3.jar,來自“smslib-v3.5.2/lib/”
5. jetty-all-7.6.14.v20131031.jar,來自jetty7
6. log4j-1.2.16.jar,來自“smslib-v3.5.2/lib/”
7. slf4j-api-1.6.3.jar,來自“smslib-v3.5.2/lib/”
8. mysql-connector-java-5.1.26.jar,來自mysql數據庫鏈接,用不着數據庫可以不添加
2. smsserver-3.5.3.jar,來自“smslib-v3.5.3/dist/lib/”
默認的發布包中不包含HttpServer,需要自己編譯一下。將“smslib-v3.5.3/misc/SMSServer/Interfaces/Stable/HttpServer.java”拷貝到“smslib-v3.5.3/src/java/org/smslib/smsserver/interfaces/”目錄下。
(注意:發布包中的HttpServer,有個bug會導致中文短信顯示不正常。修正方法:在Read、Send等幾個內部類中,將“getResponse().setContentType("text/xml");”,修改為“getResponse().setContentType("text/xml;charset=UTF-8");”,並且移到“PrintWriter body = getResponse().getWriter();”的前面)。然后進入smslib目錄下,運行“ant build-smsserver”編譯一下。
3. SMSServer.conf
短消發送配置信息
# 可選配置設置一個balancer
smsserver.balancer=RoundRobinLoadBalancer
#處理完消息之后是否刪除,值yes/no
settings.delete_after_processing=yes
#發送消息模式,如果有多個短信貓則使用async(異步)方式,能提高發送效率,如果只有一個短信貓那么使用哪種方式都一樣
#Mode of operation for outbound processing. Allowed values: sync and async. If you have more than one GSM modems connected, you are advised to switch to async as all modems will be used simultaneously, thus increasing your throughput. If you have one GSM modem, it doesn"t make any difference what mode you will use.
settings.send_mode=async
#接收短信掃描間隔,單位 秒
#Inbound polling interval in seconds. SMSServer uses the inbound message notifications from the modem in order to wake up and read messages upon their arrival.
settings.inbound_interval=600
#發送短信掃描間隔,單位 秒
#Outbound polling interval in seconds. Every such interval, SMSServer will poll its interfaces for new to-be-sent messages and will attempt to send them.
settings.outbound_interval=10
#優先級發送時間區間
settings.timeframe.high=0800-1830
settings.timeframe.normal=1831-2200
settings.timeframe.low=2201-0759
#短信貓串口配置
gateway.0=myModem, SerialModem
#端口,windows 一般是COM,linux一般是/dev/ttyS0或/dev/ttyS1
#the comm port to use, for example COM1 or /dev/ttyS0.
myModem.port=/dev/ttyS1
#硬件波特率
myModem.baudrate=9600
#硬件廠家,例如:諾基亞-nokia ,短信貓 - Wavecom
myModem.manufacturer=Wavecom
#型號
myModem.model=M1206B
#中文編碼使用PDU
myModem.protocol=PDU
myModem.pin=0000
#允許接受
myModem.inbound=yes
#允許發送
myModem.outbound=yes
#Use this option to set/override the SMSC definition. Leave blank to use the default.
#信息中心號碼,設置會覆蓋卡中默認值
#myModem.smsc_number=
#服務接口設置
interface.0=httpServer, HttpServer
#監聽端口號
httpServer.port=8181
#讀信密碼
httpServer.password.read=123456
#發信密碼
httpServer.password.send=123456
#數據庫接口設置
interface.1=db1, Database
db1.url=jdbc:mysql://localhost/sms?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
db1.driver=com.mysql.jdbc.Driver
db1.username=root
db1.password=root
db1.type=mysql
db1.tables.sms_in=sms_in
db1.tables.sms_out=sms_out
db1.tables.calls=sms_calls
db1.batch_size=50
db1.retries=2
db1.update_outbound_on_statusreport=yes
4. Log4j.xml
日志記錄信息配置
5. MySQL.sql
MySql數據庫腳本,來自“smslib-v3.5.3\misc\SMSServer\Database Scripts”
6. Sms.sh(修改權限: chmod u+x sms.sh)
為方便啟動、停止短信服務自己寫的腳本
使用方式:./sms.sh start ./sms.sh stop 參數:start、stop、info、restart、status
四、這樣SmsServer就部署好了,啟動時只需執行“./sms.sh start”即可了。
五、測試
1、查看狀態:http://ip:port/status
2、發送短信:http://ip:port/send?password=123456&encoding=U&recipient=15866668888&text=測試一下
3、接收短信:http://ip:port/read?password=123456