OTP med Java
Generera ett OTP-token (ett engångslösenord) med Java
Java : API-DOKUMENTATION
- Skapa grupp med Java
- Hämta gruppfältlista med Java
- Lägg till ett fält i en grupp med Java
- Radera ett fält från en grupp med Java
- Radera en kontakt från en grupp
- Assistera land till e-grupp med Java
- Hämta gruppkontaktlista med Java
- Lägg till kontakt i en grupp med Java
- Ändra kontakt med en grupp med Java
- Radera kontakt med en grupp med Java
OTP med 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());
}
Parameter | Beskrivning | Obligatorisk / valfri |
---|---|---|
class=otp | Klass begärt: Klass som begäran görs till | Obligatorisk |
method=generateotp | Klassmetod begärd: Metod för den klass som begäran görs till | Obligatorisk |
user | Användare och e-post till ditt Afilnet-konto | Obligatorisk |
password | Lösenord för ditt Afilnet-konto | Obligatorisk |
type | Typ av grupp (e-post eller mobil) | Obligatorisk |
destination | Mobilnummer eller e-postadress | Obligatorisk |
time | Antal dagar, veckor, månader eller år | Valfri |
timetype | Tidtyp (Posible värde: dagar, veckor, månader o år) | Valfri |
length | Lösenordet för lösenordet att generera | Valfri |
otpformat | Lösenordets format att generera, om det innehåller alla tecken, endast siffror eller bara bokstäver (alla, siffror, bokstäver) | Valfri |
output | Outputformat för resultatet | Valfri |
När du gör förfrågningar får du följande fält:
- status
-
resultat (om status = framgång), här får du följande värden:
- Inga ytterligare värden kommer att skickas till dig
- fel (om status = fel), här får du felkoden
De möjliga felkoderna listas nedan
Koda | Beskrivning |
---|---|
MISSING_USER | Användare eller e-post ingår inte |
MISSING_PASSWORD | Lösenord ingår inte |
MISSING_CLASS | Klass ingår inte |
MISSING_METHOD | Metod ingår inte |
MISSING_COMPULSORY_PARAM | Obligatorisk parameter ingår inte |
INCORRECT_USER_PASSWORD | Felaktig användare eller lösenord |
INCORRECT_CLASS | Fel klass |
INCORRECT_METHOD | Fel metod |
INCORRECT_TIME_TYPE | Fel typ av tid (möjliga värden: dagar, veckor, månader eller år) |
INCORRECT_TYPE | Fel typ. Typen måste vara mobil eller e-post |
INCORRECT_FORMAT | ERROR_INCORRECT_FORMAT |
INCORRECT_OTP_FORMAT | ERROR_INCORRECT_OTP_FORMAT |
parametrar:
- class : otp
- method : generateotp
- user : user
- password : password
- type : number
- destination : 34600000000
- time : 1
- timetype : days
- length : 6
- otpformat : all
- output :
Begäran:
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=