600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > wavecom java_使用java操作wavecom短信猫来发短信的方法|实例源码介绍

wavecom java_使用java操作wavecom短信猫来发短信的方法|实例源码介绍

时间:2020-12-20 03:47:52

相关推荐

wavecom java_使用java操作wavecom短信猫来发短信的方法|实例源码介绍

使用java操作wavecom短信猫来发短信的方法|实例源码介绍。由于业务的需要,用java实现了用wavecom短信猫发短信的功能,本来这个应该用随猫购买的二次开发接口实现的,但由于这几台猫买的时候,经销商没有提供二次开发接口,所以我不得不在网上找了资料,自己写了个接口实现了发短信的功能。

实现这个功能,需要两个jar包,可以到/p/smslib下载smslib-v3.3.0-B2-bin.zip和javacomm20-win32.zip。

首先,把smslib-v3.3.0-B2-bin.zip解开,在smslib\dist\lib目录下找到smslib-3.3.0b2.jar,放入工程lib中,再把javacomm20-win32.zip解开,里面的comm.jar需要放到工程lib下,m.properties放到%JAVA_HOME%/jre/lib下,win32com.dll放到%JAVA_HOME%/jre/bin下。路径放错了,调用起来就会报错的。

环境配置好了以后,使用起来很简单,贴下我的代码:

// SendMessage.java – Sample application.

//

// This application shows you the basic procedure for sending messages.

// You will find how to send synchronous and asynchronous messages.

//

// For asynchronous dispatch, the example application sets a callback

// notification, to see what’s happened with messages.

package song.test;

import org.smslib.IOutboundMessageNotification;

import org.smslib.Library;

import org.smslib.OutboundMessage;

import org.smslib.Service;

import org.smslib.Message.MessageEncodings;

import org.smslib.modem.SerialModemGateway;

public class SendMessage

{

public void doIt() throws Exception

{

Service srv;

OutboundMessage msg;

OutboundNotification outboundNotification = new OutboundNotification();

System.out.println(“Example: Send message from a serial gsm modem.”);

System.out.println(Library.getLibraryDescription());

System.out.println(“Version: ” + Library.getLibraryVersion());

srv = new Service();

SerialModemGateway gateway = new SerialModemGateway(“1″, “COM1″, 115200, “wavecom”, “17254″);

gateway.setInbound(true);

gateway.setOutbound(true);

gateway.setSimPin(“0000″);

gateway.setOutboundNotification(outboundNotification);

srv.addGateway(gateway);

srv.startService();

System.out.println(“Modem Information:”);

System.out.println(” Manufacturer: ” + gateway.getManufacturer());

System.out.println(” Model: ” + gateway.getModel());

System.out.println(” Serial No: ” + gateway.getSerialNo());

System.out.println(” SIM IMSI: ” + gateway.getImsi());

System.out.println(” Signal Level: ” + gateway.getSignalLevel() + “%”);

System.out.println(” Battery Level: ” + gateway.getBatteryLevel() + “%”);

System.out.println();

// Send a message synchronously.

msg = new OutboundMessage(“13649251175″, “这个是用java发的中文短信!”);//手机号码,和短信内容

msg.setEncoding(MessageEncodings.ENCUCS2);//这句话是发中文短信必须的

srv.sendMessage(msg);

System.out.println(msg);

System.out.println(“Now Sleeping – Hit to terminate.”);

System.in.read();

srv.stopService();

}

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);

}

}

public static void main(String args[])

{

SendMessage app = new SendMessage();

try

{

app.doIt();

}

catch (Exception e)

{

e.printStackTrace();

}

}

}

/wex660@126/blog/static/24153065233728724/

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。