إرسال ملف عبر الدردشة مع Android
إرسال ملف عن طريق الدردشة مع Android
Android : وثائق API
- إنشاء مجموعة باستخدام Android
- الحصول على قائمة حقول المجموعة باستخدام Android
- إضافة حقل إلى مجموعة بها Android
- حذف حقل من مجموعة بها Android
- حذف جهة اتصال من مجموعة
- عيّن البلد إلى مجموعة بها Android
- الحصول على قائمة جهات اتصال المجموعة باستخدام Android
- إضافة جهة اتصال إلى مجموعة بها Android
- تعديل جهة اتصال مجموعة بها Android
- حذف جهة اتصال لمجموعة بها Android
إرسال ملف عبر الدردشة مع Android
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());
}
معامل | وصف | إجباري / اختياري |
---|---|---|
class=chat | الفئة المطلوبة: الفئة التي تم تقديم الطلب إليها | إلزامي |
method=sendfile | طريقة الفصل المطلوبة: طريقة الفصل الذي تم تقديم الطلب إليه | إلزامي |
user | المستخدم والبريد الإلكتروني لحساب Afilnet الخاص بك | إلزامي |
password | كلمة المرور لحساب Afilnet الخاص بك | إلزامي |
platform | المنصة التي يتم إرسال الرسالة إليها. القيم الممكنة: "webchat" و "whatsapp" و "telegram" و "المشغل" | إلزامي |
platformid | معرّف النظام الأساسي | إلزامي |
destination | المستلم حيث تم إرسال الملف | إلزامي |
type | نوع الملف المرسل. القيم المحتملة: "صورة" ، "فيديو" ، "صوت" ، "صوت" ، "مستند" ، "جهة اتصال" | إلزامي |
fileurl | عنوان Url حيث يوجد الملف المراد إرساله عن طريق الدردشة | إلزامي |
thumburl | عنوان URL للصورة المصغرة المصاحبة للملف | اختياري |
message | الرسالة المصاحبة للملف | اختياري |
عند تقديم طلبات ، ستتلقى الحقول التالية:
- status
-
النتيجة (إذا كانت الحالة = النجاح) ، سوف تتلقى هنا القيم التالية:
- لن يتم إرسال قيم إضافية إليك
- خطأ (إذا كانت الحالة = خطأ) ، هنا ستتلقى رمز الخطأ
يتم سرد رموز الأخطاء المحتملة أدناه
الشفرة | وصف |
---|---|
MISSING_USER | المستخدم أو البريد الإلكتروني غير المدرجة |
MISSING_PASSWORD | كلمة المرور غير المدرجة |
MISSING_CLASS | الطبقة غير المدرجة |
MISSING_METHOD | طريقة غير المدرجة |
MISSING_COMPULSORY_PARAM | المعلمة الإجبارية غير المدرجة |
INCORRECT_USER_PASSWORD | مستخدم غير صحيح أو كلمة المرور |
INCORRECT_CLASS | فئة غير صحيحة |
INCORRECT_METHOD | طريقة غير صحيحة |
CHANNEL_NOT_FOUND | القناة المشار إليها غير موجودة |
CHAT_NOT_FOUND | الدردشة المشار إليها غير موجودة |
INCORRECT_FILETYPE | نوع الملف خاطئ ، تحقق من القيم الممكنة |
INCORRECT_FILEURL | عنوان url للملف غير صالح |
INCORRECT_THUMBURL | عنوان url للصورة المصغرة غير صالح |
المعلمات:
- 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
طلب:
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