OTP с Java
Создайте OTP-токен (одноразовый пароль) с Java
Java : ДОКУМЕНТАЦИЯ API
- Создать группу с Java
- Получить список полей группы с помощью Java
- Добавить поле в группу с Java
- Удалить поле из группы с Java
- Удалить контакт из группы
- Предоставление страны электронной группе с Java
- Получить список контактов группы с помощью Java
- Добавить контакт в группу с Java
- Изменить контакт группы с помощью Java
- Удалить контакт группы с Java
OTP с Java
String afilnet_class="otp";
String afilnet_method="generateotp";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_type="number";
String afilnet_destination="34600000000";
String afilnet_time="1";
String afilnet_timetype="days";
String afilnet_length="6";
String afilnet_otpformat="all";
String afilnet_output="";
// Create an URL request
String sUrl = "https://www.afilnet.com/api/http/?class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&type="+afilnet_type+"&destination="+afilnet_destination+"&time="+afilnet_time+"&timetype="+afilnet_timetype+"&length="+afilnet_length+"&otpformat="+afilnet_otpformat+"&output="+afilnet_output;
URL url = new URL(sUrl);
StringBuilder builder = new StringBuilder();
BufferedReader theJSONline = new BufferedReader(new InputStreamReader(url.openStream()));
builder.append(theJSONline.readLine());
String content = builder.toString();
String afilnet_class="otp";
String afilnet_method="generateotp";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_type="number";
String afilnet_destination="34600000000";
String afilnet_time="1";
String afilnet_timetype="days";
String afilnet_length="6";
String afilnet_otpformat="all";
String afilnet_output="";
// Create the POST request
String post = "class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&type="+afilnet_type+"&destination="+afilnet_destination+"&time="+afilnet_time+"&timetype="+afilnet_timetype+"&length="+afilnet_length+"&otpformat="+afilnet_otpformat+"&output="+afilnet_output;
// We generate the URL
URL myurl = new URL("https://www.afilnet.com/api/http/");
// We create the connection
HttpURLConnection con = (HttpURLConnection) myurl.openConnection();
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-Length", String.valueOf(post.length()));
con.setRequestMethod("POST");
// We build the
OutputStream os = con.getOutputStream();
os.write(post.getBytes());
os.close();
StringBuilder sb = new StringBuilder();
int HttpResult = con.getResponseCode();
if(HttpResult == HttpURLConnection.HTTP_OK)
{
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
System.out.println(""+sb.toString());
} else {
System.out.println(con.getResponseCode());
System.out.println(con.getResponseMessage());
}
String afilnet_class="otp";
String afilnet_method="generateotp";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_type="number";
String afilnet_destination="34600000000";
String afilnet_time="1";
String afilnet_timetype="days";
String afilnet_length="6";
String afilnet_otpformat="all";
String afilnet_output="";
// Create the POST request
String post = "class="+afilnet_class+"&method="+afilnet_method+"&type="+afilnet_type+"&destination="+afilnet_destination+"&time="+afilnet_time+"&timetype="+afilnet_timetype+"&length="+afilnet_length+"&otpformat="+afilnet_otpformat+"&output="+afilnet_output;
// We generate the URL
URL myurl = new URL("https://www.afilnet.com/api/basic/");
// We create the connection
HttpURLConnection con = (HttpURLConnection) myurl.openConnection();
String encoded = Base64.getEncoder().encodeToString((afilnet_user+":"+afilnet_password).getBytes(StandardCharsets.UTF_8));
con.setRequestProperty("Authorization", "Basic "+encoded);
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-Length", String.valueOf(post.length()));
con.setRequestMethod("POST");
// We build the
OutputStream os = con.getOutputStream();
os.write(post.getBytes());
os.close();
StringBuilder sb = new StringBuilder();
int HttpResult = con.getResponseCode();
if(HttpResult == HttpURLConnection.HTTP_OK)
{
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(),"utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
System.out.println(""+sb.toString());
} else {
System.out.println(con.getResponseCode());
System.out.println(con.getResponseMessage());
}
параметр | Описание | Обязательный / Необязательный |
---|---|---|
class=otp | Запрошенный класс: класс, к которому сделан запрос | обязательное |
method=generateotp | Запрошенный метод класса: метод класса, к которому сделан запрос | обязательное |
user | Пользователь и адрес электронной почты вашей учетной записи Afilnet | обязательное |
password | Пароль вашей учетной записи Afilnet | обязательное |
type | Тип группы (электронная почта или мобильный) | обязательное |
destination | Номер мобильного телефона или адрес электронной почты | обязательное |
time | Количество дней, недель, месяцев или лет | Необязательный |
timetype | Тип времени (Возможное значение: дни, недели, месяцы или годы) | Необязательный |
length | Длина пароля для генерации | Необязательный |
otpformat | Формат создаваемого пароля, если он включает все символы, только цифры или только буквы (все, цифры, буквы) | Необязательный |
output | Выходной формат результата | Необязательный |
При отправке запросов вы получите следующие поля:
- status
-
результат (если статус = успех), здесь вы получите следующие значения:
- Никакие дополнительные значения не будут отправлены вам
- ошибка (если статус = ошибка), здесь вы получите код ошибки
Возможные коды ошибок перечислены ниже
Код | Описание |
---|---|
MISSING_USER | Пользователь или адрес электронной почты не включены |
MISSING_PASSWORD | Пароль не включен |
MISSING_CLASS | Класс не включен |
MISSING_METHOD | Метод не включен |
MISSING_COMPULSORY_PARAM | Обязательный параметр не включен |
INCORRECT_USER_PASSWORD | Неверный пользователь или пароль |
INCORRECT_CLASS | Неправильный класс |
INCORRECT_METHOD | Неправильный метод |
INCORRECT_TIME_TYPE | Неправильный тип времени (возможные значения: дни, недели, месяцы или годы) |
INCORRECT_TYPE | Неверный тип. Тип должен быть мобильным или электронным |
INCORRECT_FORMAT | ERROR_INCORRECT_FORMAT |
INCORRECT_OTP_FORMAT | ERROR_INCORRECT_OTP_FORMAT |
Параметры:
- class : otp
- method : generateotp
- user : user
- password : password
- type : number
- destination : 34600000000
- time : 1
- timetype : days
- length : 6
- otpformat : all
- output :
Запрос:
https://www.afilnet.com/api/http/?class=otp&method=generateotp&user=user&password=password&type=number&destination=34600000000&time=1&timetype=days&length=6&otpformat=all&output=