<?php
namespace insta\Instagram\Service;
use Carbon\Carbon;
use insta\Instagram\{
Constant,
Device,
Request
};
use App\Models\Account as AccountTable;
use GuzzleHttp\Exception\ClientException;
class Account extends Request
{
private string $username;
private string $password;
public static $account;
/**
* @var Device $device
*/
private $device;
public function __construct()
{
parent::__construct();
$this->device = new Device();
}
public function login(string $username, string $password)
{
$account = AccountTable::where('username', $username)->first();
if ($account && $account->state == 'logged_in') {
self::$account = $account;
return true;
}
$this->username = $username;
$this->password = $password;
$init = $this->init();
$mid = $init->getHeader('Ig-Set-X-Mid')[0];
$this->addHeader('X-Mid', $mid);
$this->addHeader('X-Ig-Bandwidth-Speed-Kbps', '-1.000');
$this->addHeader('X-Ig-Bandwidth-Totalbytes-B', '0');
$this->addHeader('X-Ig-Bandwidth-Totaltime-Ms', '0');
$this->addHeader('X-Bloks-Version-Id', Constant::BLOCK_VERSION_ID);
$this->addHeader('Priority', 'u=3');
$this->addHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
$this->addHeader('Accept-Encoding', 'gzip, deflate');
$this->addHeader('X-Fb-Http-Engine', 'Liger');
$this->addHeader('X-Fb-Client-Ip', true);
$this->addHeader('X-Fb-Server-Cluster', true);
$signedBody = [
'jazoest' => '22538',
'country_codes' => '[{\"country_code\":\"90\",\"source\":[\"default\"]}]',
'phone_id' => $this->device->familyDeviceId,
'enc_password' => encrypt_password(password: $this->password, publicKeyId: Constant::PASSWORD_ENC_KEY_ID, publicKey: Constant::PASSWORD_ENC_PUB_KEY),
'username' => $this->username,
'adid' => create_guid(),
'guid' => $this->device->deviceId,
'device_id' => $this->device->androidId,
'google_tokens' => '[]',
'login_attempt_count' => '0'
];
$formData = [
'signed_body' => 'SIGNATURE.'.json_encode($signedBody)
];
try {
$response = $this->post(Constant::BASE_URL.'/api/v1/accounts/login/', $formData);
}
catch (ClientException $clientException) {
$error = json_decode($clientException->getResponse()->getBody());
AccountTable::updateOrCreate([
'username' => $username
], [
'password' => $password,
'last_activity' => Carbon::now(),
'state' => 'error',
'error_message' => $error->message,
'proxy_address' => (parent::$proxy == 0 ? null : parent::$proxy),
]);
return false;
}
$account = AccountTable::updateOrCreate([
'username' => $username
], [
'password' => $password,
'data' => [
'user_id' => $response->getHeader('ig-set-ig-u-ds-user-id')[0],
'token' => $response->getHeader('ig-set-authorization')[0],
'mid' => $mid,
'claim' => $response->getHeader('x-ig-set-www-claim')[0],
'pigeon_session_id' => $this->getDevice()->pigeonSessionId,
'device_id' => $this->getDevice()->deviceId,
'family_device_id' => $this->getDevice()->familyDeviceId,
'android_id' => $this->getDevice()->androidId,
'user_agent' => 'Instagram 265.0.0.19.301 Android (30/11; 480dpi; 1080x2208; TECNO MOBILE LIMITED/TECNO; TECNO KG8; TECNO-KG8; mt6769; tr_TR; 436384411)',
],
'last_activity' => Carbon::now(),
'state' => 'logged_in',
'error_message' => null,
'proxy_address' => (parent::$proxy == 0 ? null : parent::$proxy),
'search_account' => true,
]);
$claim = $this->getClaim($account);
$account->data = array_merge($account->data, ['claim' => $claim]);
$account->save();
self::$account = $account;
return true;
}
private function init()
{
$this->device->generate();
$this->setDevice($this->device);
$response = $this->get(Constant::INIT_BASE_URL.'/api/v1/trusted_friend/get_non_expired_requests_info/');
return $response;
}
public function getClaim(AccountTable $account)
{
$this->addHeader('Authorization', $account->data['token']);
$this->addHeader('X-Ig-Www-Claim', $account->data['claim']);
$this->addHeader('X-Mid', $account->data['mid']);
$this->addHeader('Ig-U-Ds-User-Id', $account->data['user_id']);
$this->addHeader('Ig-Intended-User-Id', $account->data['user_id']);
$this->addHeader('X-Ig-Bandwidth-Speed-Kbps', '-1.000');
$this->addHeader('X-Ig-Bandwidth-Totalbytes-B', '0');
$this->addHeader('X-Ig-Bandwidth-Totaltime-Ms', '0');
$this->addHeader('X-Bloks-Version-Id', Constant::BLOCK_VERSION_ID);
$this->addHeader('Priority', 'u=3');
$this->addHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
$this->addHeader('Accept-Encoding', 'gzip, deflate');
$this->addHeader('X-Fb-Http-Engine', 'Liger');
$this->addHeader('X-Fb-Client-Ip', true);
$this->addHeader('X-Fb-Server-Cluster', true);
$request = $this->get(Constant::INIT_BASE_URL.'/api/v1/multiple_accounts/get_account_family/');
return $request->getHeader('x-ig-set-www-claim')[0];
}
}burada bulunan login challenge durumunu kontrol etmiyor örnek bir hesap challenge de olsa bile login yaptığını varsayıyor aktif olarak gösteriyor username bilgisi user_id bilgisini vs çekiyor ve aktif kullanıcı sayısında aktif olarak gösteriyor bu durumu nasıl çözebilirim? direk tüm kodları yazdım yardımcı olabilecek biri?
challenge de olan bir hesap aktif gözükmemesi ve challenge düşürmesi için yardımcı olabilecek
0
●134
- 12-05-2023, 09:05:53Kimlik doğrulama veya yönetimden onay bekliyor.