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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:40:39  来源:igfitidea点击:

How to send and receive sms using sms lib api

javasmslib

提问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.5or higher installed on your Computer
  • You are on Windows OS
  • Your java installtion directory JAVA_HOME= c:\java\jdk1.5
  • You have no separate jreinstalled on your pc ( you are using jrethat is loacated at JAVA_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 SMSLibsrc from here

步骤 1.SMSLib这里下载src

STEP 2.Download RXTXfrom here.

STEP 2.RXTX这里下载。

STEP 3.Download CommonsNetfrom here.

STEP 3.CommonsNet这里下载。

STEP 4.Download javacomm20-win32from here.

步骤 4.javacomm20-win32这里下载。

STEP 5.Download slf4j-1.5.6from here.

步骤 5.slf4j-1.5.6这里下载。

STEP 6.Download log4j-1.2.8.jarfrom 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

  1. commons-net-2.0.jarfrom CommonsNet\commons-net-2.0.jar
  2. comm.jarfrom javacomm20-win32\commapi\comm.jar
  3. javax.comm.propertiesfrom javacomm20-win32\commapi\javax.comm.properties
  4. RXTXcomm.jarfrom rxtx-2.1-7-bins-r2\RXTXcomm.jar
  5. All the jar from slf4j-1.5.6\*.jar
  6. smslib-3.4.1.jarfrom smslib-v3.4.1-bin\dist\lib\smslib-3.4.1.jar
  1. commons-net-2.0.jarCommonsNet\commons-net-2.0.jar
  2. comm.jarjavacomm20-win32\commapi\comm.jar
  3. javax.comm.propertiesjavacomm20-win32\commapi\javax.comm.properties
  4. RXTXcomm.jarrxtx-2.1-7-bins-r2\RXTXcomm.jar
  5. 所有的罐子来自 slf4j-1.5.6\*.jar
  6. smslib-3.4.1.jarsmslib-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

  1. win32com.dllfrom javacomm20-win32\commapi\win32com.dll
  2. rxtxSerial.dllfrom rxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxSerial.dll
  3. rxtxParallel.dllfrom rxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxParallel.dll
  1. win32com.dlljavacomm20-win32\commapi\win32com.dll
  2. rxtxSerial.dllrxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxSerial.dll
  3. rxtxParallel.dllrxtx-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

  1. win32com.dllfrom javacomm20-win32\commapi\win32com.dll
  2. rxtxSerial.dllfrom rxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxSerial.dll
  3. rxtxParallel.dllfrom rxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxParallel.dll
  1. win32com.dlljavacomm20-win32\commapi\win32com.dll
  2. rxtxSerial.dllrxtx-2.1-7-bins-r2\Windows\i368-mingw32\rxtxSerial.dll
  3. rxtxParallel.dllrxtx-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.CommTestas 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.CommTestand wait for program to complete. When program completes, Note-down for which values of baud rateand 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.javafile 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");
  1. First arg = here first argument of the SerialModemGateway()constructor can be any String
  2. 2nd Arg = com port (port attached to your modem in modem list (control panel /phone and modem))
  3. 3rd arg = baud rate for which commtest got info(refer to step 16)
  4. 4rth arg = manufacturer of your mobile phone i.e Nokia , SAMSUNG
  5. 5th arg = Model name of your mobile phone (refer to step 16)
  1. 第一个 arg = 这里SerialModemGateway()构造函数的第一个参数可以是任何字符串
  2. 2nd Arg = com 端口(连接到调制解调器列表中调制解调器的端口(控制面板/电话和调制解调器))
  3. 第 3 个参数 = commtest 获取信息的波特率(请参阅第 16 步)
  4. 4rth arg = 您的手机制造商,即诺基亚、三星
  5. 第 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

Source: http://sendsmsusingsmslib.blogspot.in/

来源:http: //sendsmsusingsmslib.blogspot.in/