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
| package get.sms;
import java.io.IOException;
import org.smslib.AGateway;
import org.smslib.GatewayException;
import org.smslib.IOutboundMessageNotification;
import org.smslib.OutboundMessage;
import org.smslib.SMSLibException;
import org.smslib.Service;
import org.smslib.TimeoutException;
import org.smslib.modem.SerialModemGateway;
public class Envoit_Sms {
static String port="modem.com5";
static String port_number="COM5";
static int rate=115200;
static String modem_name="Motorola";
static String model="L71";
static SerialModemGateway gateway=null;
static String pin="0000";
static String number="+23793930372";
Service service;
OutboundMessage msg=null;
public Envoit_Sms() throws TimeoutException, SMSLibException, IOException, InterruptedException {
gateway = new SerialModemGateway(port,port_number,rate,modem_name,model);
System.out.println("initialisation...");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin(pin);
gateway.setSmscNumber(number);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
System.out.println("demarrage du service...");
service=Service.getInstance();
}
public void Envoit(String numero, String message) throws TimeoutException, GatewayException, SMSLibException, IOException, InterruptedException{
msg=new OutboundMessage("237"+numero,message);
//service=Service.getInstance();
//service.sendMessage(msg);
service.queueMessage(msg,gateway.getGatewayId());
System.out.println("envoit du sms");
service.stopService();
System.out.println("arret du service...");
}
public class OutboundNotification implements IOutboundMessageNotification
{
public void process(AGateway gateway, OutboundMessage msg)
{
System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
System.out.println(msg);
}
}
} |
Partager