我是靠谱客的博主 虚幻老师,这篇文章主要介绍64位短信猫 RXtx串行 windows平台发送短信,现在分享给大家,希望可以做个参考。

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

需要在项目里面导入smslib-3.5.4.jar(目前最新的)(注:3.0的jar包只支持1.6以下的jdk)

导入RXTXcomm.jar包

最后找到jdk和jre的bin目录下放入rxtxSerial.dll(这次用的串行,如果需要并行,则放入rxtxParallel.dll)

你也可以都放入,并不影响什么。。。。。。。

设备:

购买的设备有华为,Wavecom多种厂商的,一般厂商会在包装上写好当前设备使用的波特率(这个波特率需要写入代码内,然后我使用的是Wavecom的设备)

设备买回来,驱动肯定是要的,在Wavecom自带的检测软件内可以清楚的看到串口如:COM3

如果没有检测软件,到设备管理器里面找端口就可以看见144707_fKDo_2647908.png

代码部分:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package org.iiomchina.jwt.util.util; import java.util.ArrayList; import java.util.List; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.smslib.AGateway; import org.smslib.ICallNotification; import org.smslib.IGatewayStatusNotification; import org.smslib.IInboundMessageNotification; import org.smslib.IOrphanedMessageNotification; import org.smslib.InboundMessage; import org.smslib.Library; import org.smslib.OutboundMessage; import org.smslib.Service; import org.smslib.StatusReportMessage; import org.smslib.AGateway.GatewayStatuses; import org.smslib.AGateway.Protocols; import org.smslib.Message.MessageEncodings; import org.smslib.Message.MessageTypes; import org.smslib.crypto.AESKey; import org.smslib.modem.SerialModemGateway; public class SendLibUtil { private static Log log = LogFactory.getLog("SendLibUtil"); Service srv; SerialModemGateway gateway ; public boolean isStart=false; public static SendLibUtil slu=null; private SendLibUtil(){ } public static SendLibUtil instance(){ if(slu==null){ //CommTest.test(); slu=new SendLibUtil(); } return slu; } public void doIt(){ // Create the notification callback method for inbound & status report // messages. InboundNotification inboundNotification = new InboundNotification(); // Create the notification callback method for inbound voice calls. CallNotification callNotification = new CallNotification(); //Create the notification callback method for gateway statuses. GatewayStatusNotification statusNotification = new GatewayStatusNotification(); OrphanedMessageNotification orphanedMessageNotification = new OrphanedMessageNotification(); try { log.info("Example: Read messages from a serial gsm modem."); log.info(Library.getLibraryDescription()); log.info("Version: " + Library.getLibraryVersion()); // Create new Service object - the parent of all and the main interface // to you. this.srv = Service.getInstance(); // Create the Gateway representing the serial GSM modem. //第一个为网关,如果只有一台设备则按代码原先的写,如有多个设备需要配置不同的网关,来区别设备。 //第二个参数就是串口 //第三个参数是生产商,因为发送的命令每个厂家不一样,所以生产商一定不能写错 //第四个参数设备名(可选) this.gateway = new SerialModemGateway("modem.com1", "COM3", 115200, "Wavecom", "WMOD2"); //linux //this.gateway = new SerialModemGateway("modem.ttyUSB0", "/dev/ttyUSB0", 9600, "WAVECOM MODEM", "WMOD2"); // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway... gateway.setProtocol(Protocols.PDU); // Do we want the Gateway to be used for Inbound messages? gateway.setInbound(true); // Do we want the Gateway to be used for Outbound messages? gateway.setOutbound(true); // Let SMSLib know which is the SIM PIN. gateway.setSimPin("0000"); // Set up the notification methods. this.srv.setInboundMessageNotification(inboundNotification); this.srv.setCallNotification(callNotification); this.srv.setGatewayStatusNotification(statusNotification); this.srv.setOrphanedMessageNotification(orphanedMessageNotification); // Add the Gateway to the Service object. this.srv.addGateway(gateway); // Similarly, you may define as many Gateway objects, representing // various GSM modems, add them in the Service object and control all of them. // Start! (i.e. connect to all defined Gateways) this.srv.startService(); // Printout some general information about the modem. log.info("Modem Information:"); log.info(" Manufacturer: " + gateway.getManufacturer()); log.info(" Model: " + gateway.getModel()); log.info(" Serial No: " + gateway.getSerialNo()); log.info(" SIM IMSI: " + gateway.getImsi()); log.info(" Signal Level: " + gateway.getSignalLevel() + "%"); log.info(" Battery Level: " + gateway.getBatteryLevel() + "%"); isStart=true; // In case you work with encrypted messages, its a good time to declare your keys. // Create a new AES Key with a known key value. // Register it in KeyManager in order to keep it active. SMSLib will then automatically // encrypt / decrypt all messages send to / received from this number. this.srv.getKeyManager().registerKey("+86111", new AESKey(new SecretKeySpec("0011223344556677".getBytes(), "AES"))); } catch (Exception e) { e.printStackTrace(); } } public void getRpt() throws Exception{ // Define a list which will hold the read messages. List<InboundMessage> msgList; // Read Messages. The reading is done via the Service object and // affects all Gateway objects defined. This can also be more directed to a specific // Gateway - look the JavaDocs for information on the Service method calls. msgList = new ArrayList<InboundMessage>(); this.srv.readMessages(msgList, InboundMessage.MessageClasses.ALL); for (InboundMessage msg : msgList) { if(msg.getType()==MessageTypes.STATUSREPORT){ StatusReportMessage report=(StatusReportMessage)msg; } else{ log.info(msg.getText()); log.info(msg.getSmscNumber()); log.info(msg.getOriginator()); } gateway.deleteMessage(msg); } } public long sendMessage(String phone, String content) throws Exception { OutboundMessage msg = new OutboundMessage(phone, content); msg.setEncoding(MessageEncodings.ENCUCS2); msg.setStatusReport(true); srv.sendMessage(msg); log.info(msg.getRefNo()); log.info(msg.getMessageStatus()); return 0L; } public void close(){ try { if(srv!=null) this.srv.stopService(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ isStart=false; } } public class InboundNotification implements IInboundMessageNotification { public void process(String gatewayId, MessageTypes msgType, InboundMessage msg) { if (msgType == MessageTypes.INBOUND) { System.out.println(">>> New Inbound message detected from Gateway: " + gatewayId); } else if (msgType == MessageTypes.STATUSREPORT) { System.out.println(">>> New Inbound Status Report message detected from Gateway: " + gatewayId); } System.out.println(msg); } public void process(AGateway arg0, MessageTypes arg1, InboundMessage arg2) { // TODO Auto-generated method stub } } public class CallNotification implements ICallNotification { public void process(String gatewayId, String callerId) { System.out.println(">>> New call detected from Gateway: " + gatewayId + " : " + callerId); } public void process(AGateway arg0, String arg1) { // TODO Auto-generated method stub } } public class GatewayStatusNotification implements IGatewayStatusNotification { public void process(String gatewayId, GatewayStatuses oldStatus, GatewayStatuses newStatus) { System.out.println(">>> Gateway Status change for " + gatewayId + ", OLD: " + oldStatus + " -> NEW: " + newStatus); } public void process(AGateway arg0, GatewayStatuses arg1, GatewayStatuses arg2) { // TODO Auto-generated method stub } } public class OrphanedMessageNotification implements IOrphanedMessageNotification { public boolean process(String gatewayId, InboundMessage msg) { System.out.println(">>> Orphaned message part detected from " + gatewayId); System.out.println(msg); // Since we are just testing, return FALSE and keep the orphaned message part. return false; } public boolean process(AGateway arg0, InboundMessage arg1) { // TODO Auto-generated method stub return false; } } public static void main(String args[]) { SendLibUtil app = new SendLibUtil(); try { app.doIt(); app.sendMessage("18666666666", "小伙子,短信猫弄好了!");//电话和短信 app.getRpt(); } catch (Exception e) { e.printStackTrace(); }finally{ app.close(); } } public boolean isStart() { return isStart; } public void setStart(boolean isStart) { this.isStart = isStart; } }

这样就可以实现短信猫发送短信了。

 

问题:

在短信猫第一次发送成功后,第二次发送短信回出现空指针问题。

解决方案:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//在关闭服务的代码里面,取消关闭操作 public void close(){ System.out.println("服务端口不关闭,连发模式!"); try { // if(srv!=null) // this.srv.stopService(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ isStart=false; } } public static void main(String args[]) { SendLibUtil app = new SendLibUtil(); try { app.doIt(); app.sendMessage("你的电话", "456,短信猫弄好了!"); app.getRpt(); } catch (Exception e) { e.printStackTrace(); } //finally{ // app.close(); //} } //或者注释掉这个关闭操作

 

转载于:https://my.oschina.net/maxdeath/blog/809615

最后

以上就是虚幻老师最近收集整理的关于64位短信猫 RXtx串行 windows平台发送短信的全部内容,更多相关64位短信猫内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部