OTP με Java
Δημιουργήστε ένα OTP Token (κωδικός μιας ώρας) με Java
Java : ΕΓΓΡΑΦΗ API
- Δημιουργία ομάδας με Java
- Λήψη λίστας πεδίων ομάδας με Java
- Προσθέστε ένα πεδίο σε μια ομάδα με Java
- Διαγραφή πεδίου από ομάδα με Java
- Διαγράψτε μια επαφή από μια ομάδα
- Αναθέτοντας τη χώρα σε ομάδα e με Java
- Λήψη λίστας επαφών ομάδας με Java
- Προσθήκη επαφής σε μια ομάδα με 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 | Αριθμός κινητού τηλεφώνου ή email προορισμού | Υποχρεωτικός |
time | Αριθμός ημερών, εβδομάδων, μηνών ή ετών | Προαιρετικός |
timetype | Τύπος χρόνου (Posible value: ημέρες, εβδομάδες, μήνες o έτη) | Προαιρετικός |
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=