通过java调用短信猫发短信
2017-08-15 14:23
316 查看
原地址:https://www.oschina.net/code/snippet_225735_35383
具体的操作步骤如下:
1、把smslib-3.3.0b2.jar、comm.jar与log4j-1.2.11.jar,放入到工程的lib中;
2、把javax.comm.properties放到%JAVA_HOME%/jre/lib下;
3、把win32com.dll放到%JAVA_HOME%/jre/bin下;
4 把comm.jar放到%JAVA_HOME%/jre/ext下
注意:路径放错,调用起来就会报错;JDK的版本,用的版本是jdk-1_5_0_04。
如果本公司有自己的短信平台那就简单多了,有相应的接口直接提交xml报文就OK了。
具体的操作步骤如下:
1、把smslib-3.3.0b2.jar、comm.jar与log4j-1.2.11.jar,放入到工程的lib中;
2、把javax.comm.properties放到%JAVA_HOME%/jre/lib下;
3、把win32com.dll放到%JAVA_HOME%/jre/bin下;
4 把comm.jar放到%JAVA_HOME%/jre/ext下
注意:路径放错,调用起来就会报错;JDK的版本,用的版本是jdk-1_5_0_04。
package com.alonely.notecat; import org.smslib.IOutboundMessageNotification; import org.smslib.Outbou、ndMessage; import org.smslib.Service; import org.smslib.Message.MessageEncodings; import org.smslib.modem.SerialModemGateway; public class SendMessage { public class OutboundNotification implements IOutboundMessageNotification { public void process(String gatewayId, OutboundMessage msg) { System.out.println("Outbound handler called from Gateway: " + gatewayId); System.out.println(msg); } } @SuppressWarnings("deprecation") public void sendSMS(String mobilePhones, String content) { Service srv; OutboundMessage msg; OutboundNotification outboundNotification = new OutboundNotification(); srv = new Service(); SerialModemGateway gateway = new SerialModemGateway("modem.com3", "COM3", 9600, "wavecom", ""); //设置端口与波特率 gateway.setInbound(true); gateway.setOutbound(true); gateway.setSimPin("0000"); gateway.setOutboundNotification(outboundNotification); srv.addGateway(gateway); System.out.println("初始化成功,准备开启服务"); try { srv.startService(); System.out.println("服务启动成功"); String[] phones = mobilePhones.split(","); for (int i = 0; i < phones.length; i++) { msg = new OutboundMessage(phones[i], content); msg.setEncoding(MessageEncodings.ENCUCS2); // 中文 srv.sendMessage(msg); } srv.stopService(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { SendMessage sendMessage = new SendMessage(); sendMessage.sendSMS("您要发送的手机号", "您要发送的内容!"); } }
如果本公司有自己的短信平台那就简单多了,有相应的接口直接提交xml报文就OK了。
相关文章推荐
- java调用短信猫发短信示例
- java 通过存储过程名字 获取存储过程的参数列表,然后自动传参调用sp
- AndroidJNI 通过C++调用JAVA
- JAVA与.NET的相互调用——通过Web服务实现相互调用
- 通过java调用js方法的demo
- AndroidJNI 通过C++调用JAVA
- Cocos2d-x中通过JNI进行C++调用Java代码
- Cocos2d-x3.3RC0通过JNI调用Android的Java层代码,实现分享功能
- Java 可以通过 Runtime 调用Linux命令
- java调用C# webservice短信猫发送短信
- Java通过调用FFMPEG获取视频时长(已测试)
- Java通过JNI调用C++程序
- SAP通过JCO调用Java程序配置开发
- Java调用oracle存储过程通过游标返回临时表数据
- java与C/C++之间通过jni相互调用
- AndroidJNI 通过C++调用JAVA
- 通过java调用VBS,再用VBS执行Excel中的宏的例子
- Java中通过递归调用删除文件夹下所有文件
- JAVA通过JNI调用本地C语言方法
- 通过Java反射调用方法的实例,通过这个例子,能明白怎么用反射。