Odeslat soubor prostřednictvím chatu s jazykem Java
Odeslat soubor chatem s jazykem Java
Java : DOKUMENTACE API
- Vytvořit skupinu pomocí Java
- Seznam skupinových polí s Java
- Přidejte pole do skupiny s Java
- Odstranění pole ze skupiny s Java
- Odstranění kontaktu ze skupiny
- Přiřazení země do skupiny s Java
- Seznam skupinových kontaktů s Java
- Přidejte kontakt do skupiny s Java
- Upravit kontakt skupiny pomocí Java
- Smazat kontakt skupiny s Java
- Získejte seznam aktivních chatovacích kanálů s jazykem Java
- Odeslat zprávu prostřednictvím chatu s jazykem Java
- Odeslat soubor prostřednictvím chatu s jazykem Java
- Získejte seznam konverzací v chatu s jazykem Java
- Získejte seznam zpráv z chatu s jazykem Java
- Získejte seznam nepřečtených zpráv z chatu s jazykem Java
Odeslat soubor prostřednictvím chatu s jazykem Java
String afilnet_class="chat";
String afilnet_method="sendfile";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_platform="whatsapp";
String afilnet_platformid="100";
String afilnet_destination="3460000000";
String afilnet_type="image";
String afilnet_fileurl="https://www.example.com/image.jpg";
String afilnet_thumburl="https://www.example.com/thumb.jpg";
String afilnet_message="test+message";
// Create an URL request
String sUrl = "https://www.afilnet.com/api/http/?class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&platform="+afilnet_platform+"&platformid="+afilnet_platformid+"&destination="+afilnet_destination+"&type="+afilnet_type+"&fileurl="+afilnet_fileurl+"&thumburl="+afilnet_thumburl+"&message="+afilnet_message;
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="chat";
String afilnet_method="sendfile";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_platform="whatsapp";
String afilnet_platformid="100";
String afilnet_destination="3460000000";
String afilnet_type="image";
String afilnet_fileurl="https://www.example.com/image.jpg";
String afilnet_thumburl="https://www.example.com/thumb.jpg";
String afilnet_message="test+message";
// Create the POST request
String post = "class="+afilnet_class+"&method="+afilnet_method+"&user="+afilnet_user+"&password="+afilnet_password+"&platform="+afilnet_platform+"&platformid="+afilnet_platformid+"&destination="+afilnet_destination+"&type="+afilnet_type+"&fileurl="+afilnet_fileurl+"&thumburl="+afilnet_thumburl+"&message="+afilnet_message;
// 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="chat";
String afilnet_method="sendfile";
String afilnet_user="user";
String afilnet_password="password";
String afilnet_platform="whatsapp";
String afilnet_platformid="100";
String afilnet_destination="3460000000";
String afilnet_type="image";
String afilnet_fileurl="https://www.example.com/image.jpg";
String afilnet_thumburl="https://www.example.com/thumb.jpg";
String afilnet_message="test+message";
// Create the POST request
String post = "class="+afilnet_class+"&method="+afilnet_method+"&platform="+afilnet_platform+"&platformid="+afilnet_platformid+"&destination="+afilnet_destination+"&type="+afilnet_type+"&fileurl="+afilnet_fileurl+"&thumburl="+afilnet_thumburl+"&message="+afilnet_message;
// 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());
}
Parametr | Popis | Povinné / Nepovinné |
---|---|---|
class=chat | Požadovaná třída: Třída, na kterou je žádost podána | Povinný |
method=sendfile | Požadovaná metoda třídy: Metoda třídy, které je žádost podána | Povinný |
user | Uživatel a e-mail vašeho účtu Afilnet | Povinný |
password | Heslo vašeho účtu Afilnet | Povinný |
platform | Platforma, na kterou je zpráva odeslána. Možné hodnoty: 'webchat', 'whatsapp', 'telegram', 'operátor' | Povinný |
platformid | Identifikátor platformy | Povinný |
destination | Příjemce, kam je soubor odeslán | Povinný |
type | Typ odesílaného souboru. Možné hodnoty: „obrázek“, „video“, „zvuk“, „hlas“, „dokument“, „kontakt“ | Povinný |
fileurl | Adresa URL, kde se nachází soubor odeslaný chatem | Povinný |
thumburl | Adresa URL miniatury, která je přiložena k souboru | Volitelný |
message | Zpráva doprovázející soubor | Volitelný |
Při zadávání žádostí obdržíte následující pole:
- status
-
výsledek (pokud status = úspěch), zde obdržíte následující hodnoty:
- Nebudou vám zasílány žádné další hodnoty
- chyba (pokud status = chyba), zde obdržíte kód chyby
Možné chybové kódy jsou uvedeny níže
Kód | Popis |
---|---|
MISSING_USER | Uživatel nebo e-mail nejsou zahrnuty |
MISSING_PASSWORD | Heslo není zahrnuto |
MISSING_CLASS | Třída není zahrnuta |
MISSING_METHOD | Metoda není zahrnuta |
MISSING_COMPULSORY_PARAM | Povinný parametr není zahrnut |
INCORRECT_USER_PASSWORD | Nesprávný uživatel nebo heslo |
INCORRECT_CLASS | Nesprávná třída |
INCORRECT_METHOD | Nesprávná metoda |
CHANNEL_NOT_FOUND | Uvedený kanál neexistuje |
CHAT_NOT_FOUND | Uvedený chat neexistuje |
INCORRECT_FILETYPE | Typ souboru je nesprávný, zkontrolujte možné hodnoty |
INCORRECT_FILEURL | Adresa URL souboru není platná |
INCORRECT_THUMBURL | Adresa URL miniatury je neplatná |
Parametry:
- class : chat
- method : sendfile
- user : user
- password : password
- platform : whatsapp
- platformid : 100
- destination : 3460000000
- type : image
- fileurl : https://www.example.com/image.jpg
- thumburl : https://www.example.com/thumb.jpg
- message : test+message
Žádost:
https://www.afilnet.com/api/http/?class=chat&method=sendfile&user=user&password=password&platform=whatsapp&platformid=100&destination=3460000000&type=image&fileurl=https://www.example.com/image.jpg&thumburl=https://www.example.com/thumb.jpg&message=test+message