Envio de Sms At Comands

1 resposta
java-sejava
jorgereidinaldo

Estou tentando usar este codigo que encontrei na internet porem não sei pq nao funciona o envio
nao tenho experiencia com comanos at alguem poderia me ajudar

identar texto pre-formatado em 4 espaços

public class SMSsender {

static Enumeration portList;

static CommPortIdentifier portId;

static String messageString1 = AT;

static String messageString2 = AT+CPIN=7078"”;

static String messageString3 = AT+CMGF=1;

static String messageString4 = AT+CMGS=+[telefone removido]"”;
static String messageString5 = TESTY2;

static SerialPort serialPort;

static OutputStream outputStream;

static InputStream inputStream;

static char enter = 13;
static char CTRLZ = 26;

public static void main(String[] args) throws InterruptedException {

portList = CommPortIdentifier.getPortIdentifiers();

while (portList.hasMoreElements()) {

portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

     if (portId.getName().equals("COM5")) {

        try {
            serialPort = (SerialPort)
                portId.open("COM5", 2000);
        } catch (PortInUseException e) {
        	e.printStackTrace();}
        try {
            outputStream = serialPort.getOutputStream();
            inputStream = serialPort.getInputStream();
        } catch (IOException e) {e.printStackTrace();}
        try {
            serialPort.setSerialPortParams(9600,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE); 
        } catch (UnsupportedCommOperationException e) {e.printStackTrace();}
        try { 

            outputStream.write((messageString1 + enter).getBytes());


            Thread.sleep(100); 
            outputStream.flush();

            outputStream.write((messageString2 + enter).getBytes()); 

             Thread.sleep(100); 
             outputStream.flush();

            outputStream.write((messageString3 + enter).getBytes());

            Thread.sleep(100); 
            outputStream.flush(); 




            outputStream.write((messageString4 + enter).getBytes()); 

            Thread.sleep(100);  
            outputStream.flush();

           outputStream.write((messageString5 + CTRLZ).getBytes());  

            outputStream.flush(); 
            Thread.sleep(100); 


System.out.println("Wyslano wiadomosc");  
Thread.sleep(3000);


outputStream.close();
serialPort.close();
System.out.println("Port COM zamkniety"); 

        } catch (IOException e) {e.printStackTrace();}
    }
}
}

} }

identar texto pre-formatado em 4 espaços

1 Resposta

R

Geralmente quando envia SMS via celular(chip), vai e volta operadora bloqueia o envio. Existem algumas empresas que enviam direto operadora, conheço a www.smspeople.com.br que fazem integração de envio, resposta com número curto. Tem os manuais inclusive em java, php, etc…

Criado 11 de novembro de 2017
Ultima resposta 28 de ago. de 2020
Respostas 1
Participantes 2