Java 如何使用sms lib api发送和接收短信
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22587568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send and receive sms using sms lib api
提问by Sanaullah
i m new to sms lib api i never used api's before please would you give me some help how to use it from strart to end for sending and receiving sms using Gsm modem in eclipse. please it is an emergency my final year project is based upon it. please it will be a great favour..thanks in advance
我是 sms lib api 的新手,我以前从未使用过 api,请你给我一些帮助,如何从头到尾使用它在 eclipse 中使用 Gsm 调制解调器发送和接收短信。请这是紧急情况,我的最后一年的项目基于它。请这将是一个很大的帮助..提前谢谢
回答by Shishir Kumar
Assumption:
假设:
- You have
java1.5
or higher installed on your Computer - You are on
Windows OS
- Your java installtion directory
JAVA_HOME
=c:\java\jdk1.5
- You have no separate
jre
installed on your pc ( you are usingjre
that is loacated atJAVA_HOME\jre
) - You have any java supported mobile phone,
- 您
java1.5
的计算机上安装了或更高版本 - 你是在
Windows OS
- 你的java安装目录
JAVA_HOME
=c:\java\jdk1.5
- 您
jre
的电脑上没有单独安装(您使用的jre
是位于JAVA_HOME\jre
) - 你有任何支持java的手机,
Here we will connect PC with any java supported mobile via "Standard Serial Over blue tooth link".
在这里,我们将通过“标准串行蓝牙链接”将 PC 与任何支持 Java 的手机连接起来。
STEP 1.Download SMSLib
src from here
步骤 1.SMSLib
从这里下载src
STEP 2.Download RXTX
from here.
STEP 2.RXTX
从这里下载。
STEP 3.Download CommonsNet
from here.
STEP 3.CommonsNet
从这里下载。
STEP 4.Download javacomm20-win32
from here.
步骤 4.javacomm20-win32
从这里下载。
STEP 5.Download slf4j-1.5.6
from here.
步骤 5.slf4j-1.5.6
从这里下载。
STEP 6.Download log4j-1.2.8.jar
from here.
步骤 6.log4j-1.2.8.jar
从这里下载。
STEP 7.Unzip all the files in suitable location
STEP 7.将所有文件解压到合适的位置
STEP 8.Copy following files to JAVA_HOME\jre\lib\ext
STEP 8.将以下文件复制到JAVA_HOME\jre\lib\ext
commons-net-2.0.jar
fromCommonsNet\commons-net-2.0.jar
comm.jar
fromjavacomm20-win32\commapi\comm.jar
javax.comm.properties
fromjavacomm20-win32\commapi\javax.comm.properties
RXTXcomm.jar
fromrxtx-2.1-7-bins-r2\RXTXcomm.jar
- All the jar from
slf4j-1.5.6\*.jar
smslib-3.4.1.jar
fromsmslib-v3.4.1-bin\dist\lib\smslib-3.4.1.jar
commons-net-2.0.jar
从CommonsNet\commons-net-2.0.jar
comm.jar
从javacomm20-win32\commapi\comm.jar
javax.comm.properties
从javacomm20-win32\commapi\javax.comm.properties
RXTXcomm.jar
从rxtx-2.1-7-bins-r2\RXTXcomm.jar
- 所有的罐子来自
slf4j-1.5.6\*.jar
smslib-3.4.1.jar
从smslib-v3.4.1-bin\dist\lib\smslib-3.4.1.jar
STEP 9.Copy following files to JAVA_HOME\jre\bin
步骤 9.将以下文件复制到JAVA_HOME\jre\bin
win32com.dll
fromjavacomm20-win32\commapi\win32com.dll
rxtxSerial.dll
fromrxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxSerial.dll
rxtxParallel.dll
fromrxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxParallel.dll
win32com.dll
从javacomm20-win32\commapi\win32com.dll
rxtxSerial.dll
从rxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxSerial.dll
rxtxParallel.dll
从rxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxParallel.dll
STEP 10.Copy following files to C:\Program Files\WINDOWS\system32
步骤 10.将以下文件复制到C:\Program Files\WINDOWS\system32
win32com.dll
fromjavacomm20-win32\commapi\win32com.dll
rxtxSerial.dll
fromrxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxSerial.dll
rxtxParallel.dll
fromrxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxParallel.dll
win32com.dll
从javacomm20-win32\commapi\win32com.dll
rxtxSerial.dll
从rxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxSerial.dll
rxtxParallel.dll
从rxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxParallel.dll
STEP 11.If you are using any java IDE (i.e netbeans) then create new project, add source packages smslib-v3.4.1-src\src\java
. You need to have all the file of STEP 8in your class path.(to compile the project) and build project. Set misc.CommTest
as main class of the project.
步骤 11.如果您使用任何 Java IDE(即 netbeans),则创建新项目,添加源包smslib-v3.4.1-src\src\java
。您需要在类路径中包含STEP 8 的所有文件。(编译项目)并构建项目。设置misc.CommTest
为项目的主类。
STEP 12.Connect Bluetooth device to your computer's USB port. If PC prompts you for driver installation then install the driver. If your PC can not find any suitable driver the get the driver from some where for Standard Serial Link Over Bluetooth
步骤 12.将蓝牙设备连接到计算机的 USB 端口。如果 PC 提示您安装驱动程序,请安装驱动程序。如果您的 PC 找不到任何合适的驱动程序,请从蓝牙标准串行链接的某个地方获取驱动程序
STEP 13.Once the driver is installed start Bluetooth of mobile phone.
STEP 13.安装驱动程序后启动手机蓝牙。
STEP 14. Open control panel --> BueTooth Device
第 14 步。打开控制面板 --> BueTooth 设备
- click add
- check 'select passkey for me'
- click next
- system will display pass key
- accept connection from mobile phone using that pass key(allow connections without prompt)
- 点击添加
- 选中“为我选择密码”
- 点击下一步
- 系统会显示密码
- 使用该密码接受来自手机的连接(允许在没有提示的情况下连接)
STEP 15.Open control panel/Phone and modem You should see one modem attached to port like 'COM5
' in modem list.
步骤 15.打开控制面板/电话和调制解调器 您应该COM5
在调制解调器列表中看到一个连接到端口的调制解调器,如“ ”。
STEP 16. Run misc.CommTest
and wait for program to complete. When program completes, Note-down for which values of baud rate
and comm port
. The program will print text like below:
STEP 16. 运行misc.CommTest
并等待程序完成。程序完成后,记下baud rate
和 的值comm port
。该程序将打印如下文本:
Getting Info :
(some text)(model name of us phone) i.e (Some text)Nokia7210 Suppernova.
You have to note values for the com port attached to your modem in modem list ( comtrol panel /phone and modem)
STEP 17.Open examples.modem.SendMessage.java
file in your IDE and modefy following line according to your environment.
步骤 17.examples.modem.SendMessage.java
在您的 IDE 中打开文件并根据您的环境修改以下行。
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM1", 57600, "Nokia", "6310i");
- First arg = here first argument of the
SerialModemGateway()
constructor can be any String - 2nd Arg = com port (port attached to your modem in modem list (control panel /phone and modem))
- 3rd arg = baud rate for which commtest got info(refer to step 16)
- 4rth arg = manufacturer of your mobile phone i.e Nokia , SAMSUNG
- 5th arg = Model name of your mobile phone (refer to step 16)
- 第一个 arg = 这里
SerialModemGateway()
构造函数的第一个参数可以是任何字符串 - 2nd Arg = com 端口(连接到调制解调器列表中调制解调器的端口(控制面板/电话和调制解调器))
- 第 3 个参数 = commtest 获取信息的波特率(请参阅第 16 步)
- 4rth arg = 您的手机制造商,即诺基亚、三星
- 第 5 个参数 = 您手机的型号名称(请参阅第 16 步)
Modify following line
修改以下行
msg = new OutboundMessage("+00123456567889", "Hello from SMSLib!");
here replace +00123456567889 with +<your number with ISD code>
add following line some where after instantiation of SerialModemGateway
在实例化之后的一些地方添加以下行 SerialModemGateway
gateway.setSMSCNumber("+919825068000")
This smsc number can be found from you mobile's 'Message'/'Message Settings' depending on your mobile phone software
这个短信号码可以从你手机的“消息”/“消息设置”中找到,具体取决于你的手机软件
STEP 18.Run examples.modem.SendMessage
.
步骤 18.运行examples.modem.SendMessage
。