---
title: "通用短信网关的简单收发程序探索"
author: "DataBird"
date: "2011-03-20T11:37:52Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-03-20T17:13:17Z"
id: 968129
url: "https://databird.iteye.com/blog/968129"
---

1.在淘宝花140元买了个通用的WAVECOM芯片短信网关，USB口的不要电源线，方便点。
2.淘宝店附送了USB转串口的安装程序PL-2303 Driver Installer.exe（通用的）和爱迪生短信通 5.4 版TxtSmsSetup.msi.msi（破解的）。
3.安装第2点的2个东东后，图形界面的爱迪生短信通就可以正常收发短信了，检测到用的com6端口。这个端口要记住，每次安装都可能不同，检测一下就知道了。速率就填9600。
4.我要的是java程序收发短信，不是用现成的 爱迪生短信通 去发广告短信，是所谓编程吧。AT命令去搞据说难于上青天，二次开发包 搜搜都是要钱的，好不容易看到了http://hi.baidu.com/%CB%CE%B9%E2%BB%D41/blog/item/e45d6b58d4ba4cdb9c8204a9.html
这篇文章。于是试用。
5.遇到N多问题。
（1）作者讲他的不支持USB口，让我绝望！
但是不死心，去http://smslib.org/doc/smslib/quickstart/看到了如下的话：
Serial modem gateway (class org.smslib.modem.SerialModemGateway): For modems which are connected via serial ports (or emulated serial ports, like USB etc). ，底层的二次开发包应该是支撑USB口的。实验结果是可以的。
（2）log4j包也要下载供smslib包调用。
http://logging.apache.org/log4j/1.2/download.html
（3）修改芯片名称和型号。端口号每个人的机器都可能不同，检测下。
SerialModemGateway gateway = new SerialModemGateway("modem.com6", "COM6", 9600, "wavecom", "17254");
（4）成功了。
run：
Example: Read messages from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem
or other supported gateways.
Web Site: http://smslib.org
This software is distributed under the terms of the Apache v2.0 License.
Version: 3.3.0-b2

Modem Information:
  Manufacturer:  WAVECOM MODEM
  Model:  MULTIBAND  900E  1800
  Serial No: 012345678901234
  SIM IMSI: ** MASKED **
  Signal Level: 74%
  Battery Level: 0%

Now Sleeping - Hit <enter> to terminate.
>>> New Inbound message detected from Gateway: modem.com6
===============================================================================
<< InboundMessage >>
-------------------------------------------------------------------------------
 Gateway Id: modem.com6
 Encoding: UCS2 (Unicode)
 Date: Sun Mar 20 10:47:16 CST 2011
 Text: 试用smslib成功了，非常高兴，希望我的文章能给摸索的人一点帮助！
 PDU data: 0032723872385988598872314F6076848001516C516C5B895385957F5F97898153BB4E0D597D610F601D768476847684
 Originator: 8613574110874
 Memory Index: 1
 Multi-part Memory Index: 
 Memory Location: SM
 Source / Destination Ports: -1 / -1
===============================================================================

run：
Example: Send message from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem
or other supported gateways.
Web Site: http://smslib.org
This software is distributed under the terms of the Apache v2.0 License.
Version: 3.3.0-b2
Modem Information:
  Manufacturer:  WAVECOM MODEM
  Model:  MULTIBAND  900E  1800
  Serial No: 012345678901234
  SIM IMSI: ** MASKED **
  Signal Level: 77%
  Battery Level: 0%

===============================================================================
<< OutboundMessage >>
-------------------------------------------------------------------------------
 Gateway Id: modem.com6
 Encoding: UCS2 (Unicode)
 Date: Sun Mar 20 11:26:34 CST 2011
 SMSC Ref No: 15
 Recipient: 13574110874
 Dispatch Date: Sun Mar 20 11:26:39 CST 2011
 Message Status: SENT
 Validity Period (Hours): -1
 Status Report: false
 Source / Destination Ports: -1 / -1
 Flash SMS: false
 Text: 这个是用java发的中文短信!祝山寨事业蒸蒸日上
 PDU data: 8FD94E2A662F7528006A00610076006153D176844E2D658777ED4FE10021795D5C715BE84E8B4E1A84B884B865E54E0A
===============================================================================

Now Sleeping - Hit <enter> to terminate.
（5）试用升级版的smslib-3.5.0.jar就报错，需要修改收发程序。以后再说了。
（6）最终目的是用java程序每隔1分钟扫描一次数据库的表，有新内容就发送短信，有接受的短信就写入库表。以后再说了。

6.附件说明：
1.把smslib-3.3.0b2.jar和comm.jar，放入工程lib中。
2.javax.comm.properties放到%JAVA_HOME%/jre/lib下，
3.win32com.dll放到%JAVA_HOME%/jre/bin下。
4.环境配置好了以后，把examples文件夹下的SendMessage.java和ReadMessages.java拷贝到你的开发工具下，就可以发短信了。

7.在前人的基础上改进比较省力，如果大家看后有改进的东西，希望告诉我也进步进步，谢谢！120251048@qq.com

8.端口和速率测试程序：CommTest
run：

Searching for devices...

Found port: COM6 
       Trying at   9600...  Getting Info... Found:  MULTIBAND  900E  1800
       Trying at  14400...  no device found (javax.comm.UnsupportedCommOperationException: Unsupported baud rate)
       Trying at  19200...  no device found
       Trying at  28800...  no device found (javax.comm.UnsupportedCommOperationException: Unsupported baud rate)
       Trying at  33600...  no device found (javax.comm.UnsupportedCommOperationException: Unsupported baud rate)
       Trying at  38400...  no device found
       Trying at  56000...  no device found (javax.comm.UnsupportedCommOperationException: Unsupported baud rate)
       Trying at  57600...  no device found
       Trying at 115200...  no device found

Test complete.
成功生成（总时间：44 秒）

9.log4j.properties 修改为控制台和log文件都输出：
log4j.properties需要放置在源程序的根目录下，折腾了很久啊。
log4j.logger.smslib=info, smsr, smsf

log4j.appender.smsr=org.apache.log4j.ConsoleAppender
log4j.appender.smsr.layout=org.apache.log4j.PatternLayout
log4j.appender.smsr.layout.ConversionPattern=%-6r %d  %-5p %C %x - %m%n

log4j.appender.smsf=org.apache.log4j.FileAppender
log4j.appender.smsf.File=D:/jdev/DEV/DataTransfer/log4j.log
log4j.appender.smsf.Append=false
log4j.appender.smsf.layout=org.apache.log4j.PatternLayout
log4j.appender.smsf.layout.ConversionPattern=%-6r %d  %-5p %C %x - %m%n

10.使用最新的smslib-3.5.0.jar，应该比smslib-3.3.0b2.jar强。
example里面有现成的，改改几个参数就行了。