0212-852-6465
0212-852-6465

JAVA SMS API ÖRNEK KODLAR

JAVASCRIPT üzerinde gerçekleştirilmiş XML-POST ve WEBSERVICE hizmetlerimizin örneklerini hazırladık

    Ücretsiz JAVA SMS Api Entegrasyonu

  1. Sisteminize kolayca entegre edebileceğiniz JAVA Sms Api servisimiz ile müşterilerinize şifre doğrulama, otomatik onay veya bilgi için anında tekli veya toplu mesajlar gönderin. Toplu sms gönderimi gibi birçok avantaj elde edeceğiniz Java SMS API örnek ve dokümanlarımızı inceleyin.

    Ücretsiz üyelik oluşturarak Api hizmetimizi deneme fırsatını şimdi değerlendirin.
    VatanSMS aboneliği ve Api hizmetimizi denemek tamamen ücretsizdir.
    Oluşturacağınız üyelik herhangi bir taahhüdü içermez.
    Risk yok! JAVA SMS API servisimizi size hediye edeceğimiz sms kredinizle deneyin. Satın almak veya herhangi bir ödeme yapma zorunluluğunuz yok!
    ÜCRETSİZ ÜYE OL ve JAVA ile TEST ET


  2. JAVA - XML POST - BİR MESAJI ÇOK KİŞİYE GÖNDERME


  3. /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package api1n;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLConnection;
    
    /**
     *
     * @author user
     */
    public class Api1N {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            try
                    {
                            URL u = new URL("http://panel.vatansms.com/panel/smsgonder1Npost.php");
                            URLConnection uc = u.openConnection();
                            HttpURLConnection connection = (HttpURLConnection) uc;
                            connection.setDoOutput(true);
                            connection.setDoInput(true);
                            connection.setRequestMethod("POST");
                            OutputStream out = connection.getOutputStream();
                            OutputStreamWriter wout = new OutputStreamWriter(out, "UTF-8");
                            wout.write("data=<sms>"+
                            "<kno>KullanıcıNumaranız</kno>"+
                            "<kulad>KullanıcıAdınız</kulad>"+
                            "<sifre>Şifreniz</sifre>"+
                            "<gonderen>GönderenAdınız</gonderen>"+
                            "<mesaj>Deneme Mesajıdır</mesaj>"+
                            "<numaralar>5554443322,5553334422</numaralar>"+
                            "<tur>Normal</tur>"+ // Normal yada Turkce olabilir
                            "</sms>");
                             //Xml'in içinde aşağıdaki alanları ekleyebilirsiniz.
                              // '<zaman>2013-11-05 15:00:00</zaman>'+  İleri tarihli mesaj için kullanabilirsiniz.
                            wout.flush();
                            out.close();
                            InputStream in = connection.getInputStream();
                            int c;
                            while ((c = in.read()) != -1) System.out.write(c);
                            System.out.println();
                            in.close();
                            out.close();
                            connection.disconnect();
                    }
                    catch (IOException e)
                    {
                    System.err.println(e);
                    }
        }
    
    }
    
  4. JAVA - XML POST - N MESAJI N KİŞİYE GÖNDERME

  5. /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package apinn;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLConnection;
    /**
     *
     * @author user
     */
    public class ApiNN {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
             try
                    {
                            URL u = new URL("http://panel.vatansms.com/panel/smsgonderNNpost.php");
                            URLConnection uc = u.openConnection();
                            HttpURLConnection connection = (HttpURLConnection) uc;
                            connection.setDoOutput(true);
                            connection.setDoInput(true);
                            connection.setRequestMethod("POST");
                            OutputStream out = connection.getOutputStream();
                            OutputStreamWriter wout = new OutputStreamWriter(out, "UTF-8");
                            wout.write("data=<sms>"+
                            "<kno>KullanıcıNumaranız</kno>"+
                            "<kulad>KullanıcıAdınız</kulad>"+
                            "<sifre>Şifreniz</sifre>"+
                            "<gonderen>GönderenAdınız</gonderen>"+
                            "<telmesajlar>"+
                            "<telmesaj><tel>5554443322</tel><mesaj>ilk kisiye giden mesaj</mesaj></telmesaj>"+
                            "<telmesaj><tel>5553334422</tel><mesaj>ikinci kisiye giden mesaj</mesaj></telmesaj>"+
                            "</telmesajlar>"+
                            "<tur>Normal</tur>"+ // Normal yada Turkce olabilir
                            "</sms>");
                             //Xml'in içinde aşağıdaki alanları ekleyebilirsiniz.
                              // '<zaman>2013-11-05 15:00:00</zaman>'+  İleri tarihli mesaj için kullanabilirsiniz.
                            wout.flush();
                            out.close();
                            InputStream in = connection.getInputStream();
                            int c;
                            while ((c = in.read()) != -1) System.out.write(c);
                            System.out.println();
                            in.close();
                            out.close();
                            connection.disconnect();
                    }
                    catch (IOException e)
                    {
                      System.err.println(e);
                    }
        }
    
    }
    
  6. JAVASCRIPT - XML POST - RAPORLAMA

  7. /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package apirapor;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLConnection;
    /**
     *
     * @author user
     */
    public class ApiRapor {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            try
                    {
                            URL u = new URL("http://panel.vatansms.com/panel/smstakippost.php");
                            URLConnection uc = u.openConnection();
                            HttpURLConnection connection = (HttpURLConnection) uc;
                            connection.setDoOutput(true);
                            connection.setDoInput(true);
                            connection.setRequestMethod("POST");
                            OutputStream out = connection.getOutputStream();
                            OutputStreamWriter wout = new OutputStreamWriter(out, "UTF-8");
                            wout.write("data=<smsrapor>"+
                            "<kulad>KullanıcıAdınız</kulad>"+
                            "<sifre>Şifreniz</sifre>"+
                            "<ozelkod>ÖzelKOD</ozelkod>"+
                            "</smsrapor>");
                            wout.flush();
                            out.close();
                            InputStream in = connection.getInputStream();
                            int c;
                            while ((c = in.read()) != -1) System.out.write(c);
                            System.out.println();
                            in.close();
                            out.close();
                            connection.disconnect();
                    }
                    catch (IOException e)
                    {
                    System.err.println(e);
                    }
        }
    
    }
    


  8. JAVA - WEBSERVIS - Bir Mesajı Çok Numaraya Gönderme

  9. package wsapi1n;
    
    import java.io.IOException;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    
    /**
     *
     * @author user
     */
    public class WSApi1N {
    
        /**
         * @param args the command line arguments
         * @throws java.lang.Exception
         */
        public static void main(String[] args) throws Exception {
            String KULNO="";
                    String KULAD="";
                    String KULSIFRE="";
                    String ORJINATOR="";
                    String ZAMAN="";                   //İleri tarih için kullanabilirsiniz. 2014-04-21 10:00:00
                    String ZAMANASIMI="";        //Sms ömrünü belirtir. 2014-04-21 15:00:00
                    String TIP="Normal";          //Normal yada Turkce
    
                    String Numaralar="5554443322,5553332211";
                    String Mesaj="Deneme|61|mesajidir";
    
                    String Adres= "http://panel.vatansms.com/webservis/service.php";
    
            String TekSmsiBirdenCokNumarayaGonder="<?xml version='1.0' encoding='utf-8'?>"+
                                            "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+
                                            "<soap:Body>"+
                                            "<TekSmsiBirdenCokNumarayaGonder xmlns='"+Adres+"'>"+
                                            "<kullanicino>"+KULNO+"</kullanicino>"+
                                            "<kullaniciadi>"+KULAD+"</kullaniciadi>"+
                                            "<sifre>"+KULSIFRE+"</sifre>"+
                                            "<orjinator>"+ORJINATOR+"</orjinator>"+
                                            "<numaralar>"+Numaralar+"</numaralar>"+
                                            "<mesaj>"+Mesaj+"</mesaj>"+
                                            "<zaman>"+ZAMAN+"</zaman>"+
                                            "<zamanasimi>"+ZAMANASIMI+"</zamanasimi>"+
                                            "<tip>"+TIP+"</tip>"+
                                            "</TekSmsiBirdenCokNumarayaGonder>"+
                                            "</soap:Body>"+
                                            "</soap:Envelope>";
           System.out.println(WSApi1N.POST(Adres, TekSmsiBirdenCokNumarayaGonder));
        }
         public static String POST( String _Adres, String _Xml) throws Exception
             {
                     HttpClient client = new DefaultHttpClient();
                     try
                     {
                             HttpPost post = new HttpPost(_Adres);
                             post.setHeader( "Content-type", "text/xml; charset=utf-8" );
                             post.setEntity( new StringEntity(_Xml));
                             HttpResponse response = client.execute( post );
                             HttpEntity entity = response.getEntity();
                             if ( entity != null ) {
                                    String cevap=  EntityUtils.toString( entity );
                                       cevap= cevap.split("<return xsi:type=\"xsd:string\">")[1];
                                       return cevap.split("</return>")[0];
                             }
                             return null;
                     }
                     catch ( IOException ex )
                     {
                             System.out.println(ex);
                             throw new RuntimeException( ex );
                     }
                     finally
                     {
                             client.getConnectionManager().shutdown();
                     }
            }
    }
    
  10. JAVA - WEBSERVIS - N MESAJI N KİŞİYE GÖNDER


  11. package wsapinn;
    import java.io.IOException;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    /**
     *
     * @author user
     */
    public class WSApiNN {
    
        /**
         * @param args the command line arguments
         * @throws java.lang.Exception
         */
        public static void main(String[] args) throws Exception {
         String KULNO="";
                    String KULAD="";
                    String KULSIFRE="";
                    String ORJINATOR="";
                    String ZAMAN="";                   //İleri tarih için kullanabilirsiniz. 2014-04-21 10:00:00
                    String ZAMANASIMI="";        //Sms ömrünü belirtir. 2014-04-21 15:00:00
                    String TIP="Normal";          //Normal yada Turkce
                    String NumaraMesaj="{[][Deneme|61|mesajidir1]}"; //{[numara][mesaj]} Mesajlarınızı PDF'deki gibi kodlu göndermenizi öneririz.
    
                    String Adres= "http://panel.vatansms.com/webservis/service.php";
    
            String HerBirNumarayaFarkliSmsGonder="<?xml version='1.0' encoding='utf-8'?>"+
                                            "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+
                                            "<soap:Body>"+
                                            "<HerBirNumarayaFarkliSmsGonder xmlns='"+Adres+"'>"+
                                            "<kullanicino>"+KULNO+"</kullanicino>"+
                                            "<kullaniciadi>"+KULAD+"</kullaniciadi>"+
                                            "<sifre>"+KULSIFRE+"</sifre>"+
                                            "<orjinator>"+ORJINATOR+"</orjinator>"+
                                            "<numaramesaj>"+NumaraMesaj+"</numaramesaj>"+
                                            "<zaman>"+ZAMAN+"</zaman>"+
                                            "<zamanasimi>"+ZAMANASIMI+"</zamanasimi>"+
                                            "<tip>"+TIP+"</tip>"+
                                            "</HerBirNumarayaFarkliSmsGonder>"+
                                            "</soap:Body>"+
                                            "</soap:Envelope>";
           System.out.println(WSApiNN.POST(Adres, HerBirNumarayaFarkliSmsGonder));
        }
         public static String POST( String _Adres, String _Xml) throws Exception
             {
                     HttpClient client = new DefaultHttpClient();
                     try
                     {
                             HttpPost post = new HttpPost(_Adres);
                             post.setHeader( "Content-type", "text/xml; charset=utf-8" );
                             post.setEntity( new StringEntity(_Xml));
                             HttpResponse response = client.execute( post );
                             HttpEntity entity = response.getEntity();
                             if ( entity != null ) {
                                      String cevap=  EntityUtils.toString( entity );
                                       cevap= cevap.split("<return xsi:type=\"xsd:string\">")[1];
                                       return cevap.split("</return>")[0];
                             }
                             return null;
                     }
                     catch ( IOException ex )
                     {
                             System.out.println(ex);
                             throw new RuntimeException( ex );
                     }
                     finally
                     {
                             client.getConnectionManager().shutdown();
                     }
            }
    }
    
  12. JAVA - WEBSERVIS - ÜYE BİLGİ VE RAPORLAMA İŞLEMLERİ


  13. package wsapiraporvedigerıslemler;
    import java.io.IOException;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    /**
     *
     * @author user
     */
    public class WSApiRaporveDigerIslemler {
    
        /**
         * @param args the command line arguments
         * @throws java.lang.Exception
         */
        public static void main(String[] args) throws Exception {
                    String KULNO="";
                    String KULAD="";
                    String KULSIFRE="";
    
                    String Adres= "http://panel.vatansms.com/webservis/service.php";
    
                    System.out.println("SMS ID'ye GORE RAPOR ALMA:");
                    String ozelkod="",numararapor=""; // numara boş bırakılırsa özelkod'a ait tüm raporlar çekilir
            String RaporSorgula="<?xml version='1.0' encoding='utf-8'?>"+
                                            "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+
                                            "<soap:Body>"+
                                            "<RaporSorgula xmlns='"+Adres+"'>"+
                                            "<kullanicino>"+KULNO+"</kullanicino>"+
                                            "<kullaniciadi>"+KULAD+"</kullaniciadi>"+
                                            "<sifre>"+KULSIFRE+"</sifre>"+
                                            "<ozelid>"+ozelkod+"</ozelid>"+
                                            "<numara>"+numararapor+"</numara>"+
                                            "</RaporSorgula>"+
                                            "</soap:Body>"+
                                            "</soap:Envelope>";
            System.out.println(WSApiRaporveDigerIslemler.POST(Adres, RaporSorgula));
    
                       System.out.println("TARIHE GORE RAPOR ALMA:");
                       String tarih="2014-04-22";
                       String GunlukRaporSorgula="<?xml version='1.0' encoding='utf-8'?>"+
                                    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+
                                    "<soap:Body>"+
                                    "<GunlukRaporSorgula xmlns='"+Adres+"'>"+
                                    "<kullanicino>"+KULNO+"</kullanicino>"+
                                    "<kullaniciadi>"+KULAD+"</kullaniciadi>"+
                                    "<sifre>"+KULSIFRE+"</sifre>"+
                                    "<tarih>"+tarih+"</tarih>"+
                                    "</GunlukRaporSorgula>"+
                                    "</soap:Body>"+
                                    "</soap:Envelope>";
                       System.out.println(WSApiRaporveDigerIslemler.POST(Adres, GunlukRaporSorgula));
    
                       System.out.println("ÜYE ve BAKİYE SORGULAMA:");
                       String UyeBilgisiSorgula="<?xml version='1.0' encoding='utf-8'?>"+
                                    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+
                                    "<soap:Body>"+
                                    "<UyeBilgisiSorgula xmlns='"+Adres+"'>"+
                                    "<kullanicino>"+KULNO+"</kullanicino>"+
                                    "<kullaniciadi>"+KULAD+"</kullaniciadi>"+
                                    "<sifre>"+KULSIFRE+"</sifre>"+
                                    "</UyeBilgisiSorgula>"+
                                    "</soap:Body>"+
                                    "</soap:Envelope>";
                       System.out.println(WSApiRaporveDigerIslemler.POST(Adres, UyeBilgisiSorgula));
    
                       System.out.println("ORJINATOR OLUSTURMA:");
                       String Orji="",Aciklama="";
                       String OrjinatorGonder="<?xml version='1.0' encoding='utf-8'?>"+
                                    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+
                                    "<soap:Body>"+
                                    "<OrjinatorGonder xmlns='"+Adres+"'>"+
                                    "<kullanicino>"+KULNO+"</kullanicino>"+
                                    "<kullaniciadi>"+KULAD+"</kullaniciadi>"+
                                    "<sifre>"+KULSIFRE+"</sifre>"+
                                    "<orjinator>"+Orji+"</orjinator>"+
                                    "<aciklama>"+Aciklama+"</aciklama>"+
                                    "</OrjinatorGonder>"+
                                    "</soap:Body>"+
                                    "</soap:Envelope>";
                       System.out.println(WSApiRaporveDigerIslemler.POST(Adres, OrjinatorGonder));
    
                       System.out.println("ORJINATORlERI CEKME ve SORGULAMA:");
                       String Orji1=""; //Boş bırakırsanız orjinatörlerin tümünü çeker
                       String OrjinatorSorgula="<?xml version='1.0' encoding='utf-8'?>"+
                                    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+
                                    "<soap:Body>"+
                                    "<OrjinatorSorgula xmlns='"+Adres+"'>"+
                                    "<kullanicino>"+KULNO+"</kullanicino>"+
                                    "<kullaniciadi>"+KULAD+"</kullaniciadi>"+
                                    "<sifre>"+KULSIFRE+"</sifre>"+
                                    "<orjinator>"+Orji1+"</orjinator>"+
                                    "</OrjinatorSorgula>"+
                                    "</soap:Body>"+
                                    "</soap:Envelope>";
                       System.out.println(WSApiRaporveDigerIslemler.POST(Adres, OrjinatorSorgula));
        }
        public static String POST( String _Adres, String _Xml) throws Exception
             {
                     HttpClient client = new DefaultHttpClient();
                     try
                     {
                             HttpPost post = new HttpPost(_Adres);
                             post.setHeader( "Content-type", "text/xml; charset=utf-8" );
                             post.setEntity( new StringEntity(_Xml));
                             HttpResponse response = client.execute( post );
                             HttpEntity entity = response.getEntity();
                             if ( entity != null ) {
                                     String cevap=  EntityUtils.toString( entity );
                                       cevap= cevap.split("<return xsi:type=\"xsd:string\">")[1];
                                       return cevap.split("</return>")[0];
                             }
                             return null;
                     }
                     catch ( IOException ex )
                     {
                             System.out.println(ex);
                             throw new RuntimeException( ex );
                     }
                     finally
                     {
                             client.getConnectionManager().shutdown();
                     }
            }
    }