بدأ كل شيء بحقيقة أنني أردت إنشاء قناة على إنستغرام تنفق طوال اليوم في البحث عن خدمات النشر التلقائي واختبارها ، ثم قررت النظر في حزم جيثب الجاهزة ، فوجئت بحجم رمز هذه الحزم (بعض أطر عمل php أصغر من هذه الأغلفة على إنستجرام) ، بصقت وقررت كتابة غلاف بلادي مع الحد الأدنى من الميزات.تسجيل الدخول
سنقوم بتمرير الترخيص من خلال إصدار WEB. للقيام بذلك ، سنحتاج من البداية إلى الحصول على الرؤوس وملفات تعريف الارتباط.
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://www.instagram.com/',
CURLOPT_HEADER => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPHEADER => ['user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'],
]);
$response = curl_exec($curl);
$headers = curl_getinfo($curl);
$header_content = substr($response, 0, $headers['header_size']);
curl_close($curl);
$cookie = [];
preg_match_all("/Set-Cookie:\s*(?<cookie>[^=]+=[^;]+)/mi", $header_content, $matches);
foreach ($matches['cookie'] as $c) {
if ($c = str_replace(['sessionid=""', 'target=""'], '', $c)) {
$c = explode('=', $c);
$cookie = array_merge($cookie, [trim($c[0]) => trim($c[1])]);
}
}
if (isset($cookie['csrftoken']) {
}
علاوة على ذلك ، لن أعطي أمثلة على عمل CURL.تفويض:
POST
https:
HEADER
Content-Type: application/x-www-form-urlencoded
x-ig-app-id: 1217981644879628
x-csrftoken:
cookie:
user-agent:
BODY
username=&password=&queryParams={}&optIntoOneTap=false
{"authenticated": true, "user": true, "userId": "****", "loginNonce": "****", "reactivated": true, "status": "ok"}
{"authenticated": false, "user": true, "status": "ok"}
بحث المستخدم
للقيام بذلك ، سنحتاج إلى ملفات تعريف الارتباط التي تم استلامها مسبقًا ورأس x-csrftoken.
GET
https:
HEADER
x-csrftoken:
x-ig-app-id: 1217981644879628
cookie:
user-agent:
{
"users": [
{"position":0,
"user":{
"pk":" "
"username":" "
"full_name":" , "
.....
}
},{},{}
],
"places":[ ],
"hashtags":[ ],
"has_more": true,
"rank_token": "0.44093530619864296",
"clear_client_cache": false,
"status: "ok"
}
إرسال رسائل للتوجيه
لإرسال رسائل مباشرة ، نحتاج إلى معرف المستخدم لمن سنرسل ، وكيفية العثور على المستخدمين الذين وصفتهم أعلاه.
POST
https:
HEADER
user-agent: Instagram 10.2.2 Android (18/4.3; 320dpi; 720x1280; Huawei; HWEVA; EVA-L18; qcom; en_US)
x-csrftoken:
x-ig-app-id: 1217981644879628
cookie:
content-type: application/x-www-form-urlencoded
BODY
text={ }&_uuid=&_csrftoken={ csrftoken}&recipient_users="[[ ]]"&action=send_item&thread_ids=["0"]&client_context={UUID v4 }
{"status":"ok", "payload":{"item_id":" "} ...}
function uuid4()
{
if (function_exists('com_create_guid') === true) {
return trim(com_create_guid(), '{}');
}
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
return vsprintf('%s%s%s%s%s%s%s%s', str_split(bin2hex($data), 4));
}
تحميل الصور عبر إصدار WEB
قبل إرسال الصور ، تحتاج إلى حفظها بجودة ImageJPEG 100 وإلا فسيعرض الانستقرام خطأ:$photo = __DIR__ . '/source.jpg';
$file_temp = __DIR__ . '/send_images.jpg';
list($width, $height, $image_type) = getimagesize(realpath($photo));
$srcImage = ImageCreateFromJPEG($photo);
$resImage = ImageCreateTrueColor($width, $height);
ImageCopyResampled($resImage, $srcImage, 0, 0, 0, 0, $width, $height, $width, $height);
ImageJPEG($srcImage, $file_temp, 100);
ImageDestroy($srcImage);
حمل الصورة:
$microtime = round(microtime(true) * 1000);
POST
https:
HEADER
content-type: image/jpg
x-entity-name: 'fb_uploader_' . $microtime
offset: 0
user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X; ru-RU) AppleWebKit/537.36 (KHTML, like Gecko) Version/11.4.1 Mobile/15G77 Safari/537.36 Puffin/5.2.2IP
x-entity-length: filesize($file_temp)
x-instagram-rupload-params: {"media_type":1,"upload_id":"' . $microtime . '","upload_media_height":' . $height . ',"upload_media_width":' . $width . '}
x-csrftoken:
x-ig-app-id: 1217981644879628
cookie:
BODY
file_get_contents(realpath($file_temp))
{"upload_id":" $microtime", "status":"ok" ...}
POST
https:
HEADER
content-type: application/x-www-form-urlencoded
user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X; ru-RU) AppleWebKit/537.36 (KHTML, like Gecko) Version/11.4.1 Mobile/15G77 Safari/537.36 Puffin/5.2.2IP
x-csrftoken:
x-ig-app-id: 1217981644879628
cookie:
BODY
upload_id=$microtime&caption={, }&usertags=&custom_accessibility_caption=&retry_timeout=
{"status":"ok", "media":{"id":"***", ...}}
هذا كل شيء ، لقد قمت بتطبيق الحد الأدنى من الغلاف على instagram.لقد نشرت نسخة العمل الكاملة على جيثب .
سيكون من دواعي سروري أن أسمع عن التنفيذ ، ربما حدث خطأ ما.