The specific steps are as follows:
1. Put smslib-3.3.0b2.jar, comm.jar and log4j-1.2.11.jar into the project lib;
2. Put javax.comm.properties under %JAVA_HOME%/jre/lib;
3. Place win32com.dll under %JAVA_HOME%/jre/bin;
4 Put comm.jar under %JAVA_HOME%/jre/ext
Note: If the path is misplaced, an error will be reported when calling; the JDK version used is jdk-1_5_0_04.
Copy the code code as follows:
ackage 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", ""); //Set the port and baud rate
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
gateway.setOutboundNotification(outboundNotification);
srv.addGateway(gateway);
System.out.println("Initialization successful, ready to start service");
try {
srv.startService();
System.out.println("Service started successfully");
String[] phones = mobilePhones.split(",");
for (int i = 0; i < phones.length; i++) {
msg = new OutboundMessage(phones[i], content);
msg.setEncoding(MessageEncodings.ENCUCS2); // Chinese
srv.sendMessage(msg);
}
srv.stopService();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SendMessage sendMessage = new SendMessage();
sendMessage.sendSMS("The mobile phone number you want to send", "The content you want to send!");
}
}