APIv2

Library SMS for communication HTTPS API v2.

Лицензия

Лицензия

Группа

Группа

pl.serwersms
Идентификатор

Идентификатор

apiv2
Последняя версия

Последняя версия

1.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

APIv2
Library SMS for communication HTTPS API v2.
Ссылка на сайт

Ссылка на сайт

https://github.com/SerwerSMSpl/serwersms-java-api
Система контроля версий

Система контроля версий

https://github.com/SerwerSMSpl/serwersms-java-api

Скачать apiv2

Имя Файла Размер
apiv2-1.1.pom
apiv2-1.1.jar 18 KB
apiv2-1.1-sources.jar 13 KB
apiv2-1.1-javadoc.jar 84 KB
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/pl.serwersms/apiv2/ -->
<dependency>
    <groupId>pl.serwersms</groupId>
    <artifactId>apiv2</artifactId>
    <version>1.1</version>
</dependency>
// https://jarcasting.com/artifacts/pl.serwersms/apiv2/
implementation 'pl.serwersms:apiv2:1.1'
// https://jarcasting.com/artifacts/pl.serwersms/apiv2/
implementation ("pl.serwersms:apiv2:1.1")
'pl.serwersms:apiv2:jar:1.1'
<dependency org="pl.serwersms" name="apiv2" rev="1.1">
  <artifact name="apiv2" type="jar" />
</dependency>
@Grapes(
@Grab(group='pl.serwersms', module='apiv2', version='1.1')
)
libraryDependencies += "pl.serwersms" % "apiv2" % "1.1"
[pl.serwersms/apiv2 "1.1"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.json : json jar 20090211

Модули Проекта

Данный проект не имеет модулей.

SerwerSMS.pl JAVA Client API

Klient JAVA do komunikacji zdalnej z API v2 SerwerSMS.pl

Zalecane jest, aby komunikacja przez HTTPS API odbywała się z loginów utworzonych specjalnie do połączenia przez API. Konto użytkownika API można utworzyć w Panelu Klienta → Ustawienia interfejsów → HTTPS XML API → Użytkownicy.

Przykładowe wywołanie

import java.io.*;
import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.json.*;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import SerwerSMS.*;

public class NewMain {

    public static void main(String[] args) {

        try {
        
            SerwerSMS SerwerSMSApi = new SerwerSMS("demo", "demo");
        
            HashMap<String, String> options = new HashMap<String, String>();
            options.put("test", "true");
            options.put("details", "true");

            String type = "json";
            SerwerSMSApi.setFormat(type);
            String result = SerwerSMSApi.message.sendSms("500600700", "Test message", "", options);

            if (type == "xml") {

                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document document = builder.parse(new InputSource(new StringReader(result)));
                NodeList list = document.getElementsByTagName("item");

                for (int temp = 0; temp < list.getLength(); temp++) {

                    Node item = list.item(temp);
                    if (item.getNodeType() == Node.ELEMENT_NODE) {

                        Element element = (Element) item;
                        String id = element.getElementsByTagName("id").item(0).getTextContent();
                        String phone = element.getElementsByTagName("phone").item(0).getTextContent();
                        String status = element.getElementsByTagName("status").item(0).getTextContent();

                        System.out.println(id + " - " + phone + " - " + status);
                    }
                }

            } else if (type == "json") {

                JSONObject json = new JSONObject(result);
                JSONArray jsonArray = new JSONArray(json.get("items").toString());

                for (int i = 0; i < jsonArray.length(); i++) {

                    JSONObject tmp = new JSONObject(jsonArray.get(i).toString());
                    String id = tmp.get("id").toString();
                    String phone = tmp.get("phone").toString();
                    String status = tmp.get("status").toString();

                    System.out.println(id + " - " + phone + " - " + status);
                }
            }

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
}

Wysyłka SMS

try {

    SerwerSMS SerwerSMSApi = new SerwerSMS("demo", "demo");
    String type = "json";
    SerwerSMSApi.setFormat(type);
    
    // SMS FULL
    HashMap<String, String> options = new HashMap<String, String>();
    options.put("test", "true");
    options.put("details", "true");
    String result = SerwerSMSApi.message.sendSms("500600700,600700800", "Test message", "INFORMACJA", options);
    System.out.println(result);
 
    // SMS ECO
    HashMap<String, String> options = new HashMap<String, String>();
    options.put("test", "true");
    options.put("details", "true");
    String result = SerwerSMSApi.message.sendSms("500600700,600700800", "Test message", "", options);
    System.out.println(result);
  
    // VOICE from text
    HashMap<String, String> options = new HashMap<String, String>();
    options.put("test", "true");
    options.put("text", "Test message");
    options.put("details", "true");
    String result = SerwerSMSApi.message.sendVoice("500600700", options);
    System.out.println(result);
    
    // MMS
    HashMap<String, String> options = new HashMap<String, String>();
    options.put("test", "true");
    options.put("file_id", "82aa9f108c");
    String result = SerwerSMSApi.message.sendMms("500600700", "Title message", options);
    System.out.println(result);
  
} catch (Exception e) {
    System.out.println(e.getMessage());
}

Wysyłka spersonalizowanych SMS

try {

    ArrayList<HashMap<String, String>> listMessages = new ArrayList<HashMap<String, String>>();

    // Message nr. 1
    HashMap<String, String> message = new HashMap<String, String>();
    message.put("phone", "500600700");
    message.put("text", "Test message 1");
    listMessages.add(message);

    // Message nr. 2
    message = new HashMap<String, String>();
    message.put("phone", "600700800");
    message.put("text", "Test message 2");
    listMessages.add(message);

    HashMap<String, String> options = new HashMap<String, String>();
    options.put("test", "true");
    options.put("details", "true");

    String result = SerwerSMSApi.message.sendPersonalized(listMessages, "", options);
    System.out.println(result);
    
} catch (Exception e) {
    System.out.println(e.getMessage());
}

Pobieranie raportów doręczeń

try {

    HashMap<String, String> options = new HashMap<String, String>();
    options.put("id", "b7ac0db51a,0a83b5d5eb");
    String result = SerwerSMSApi.message.reports(options);
    System.out.println(result);

} catch (Exception e) {
    System.out.println(e.getMessage());
}

Pobieranie wiadomości przychodzących

try {

    HashMap<String, String> options = new HashMap<String, String>();
    options.put("phone", "500600700");
    String result = SerwerSMSApi.message.recived("ndi",options);

} catch (Exception e) {
    System.out.println(e.getMessage());
}

Wymagania

Java SE 8

Biblioteka do obsługi formatu JSON lub XML

Dokumentacja

http://dev.serwersms.pl

Konsola API

http://apiconsole.serwersms.pl

Версии библиотеки

Версия
1.1
1.0
0.0.1