Mise en place de la verification des credentials avec reconnexion automatique
This commit is contained in:
@@ -377,7 +377,7 @@ class APIController extends Controller
|
||||
$cursor = null;
|
||||
|
||||
// Nombre de tours
|
||||
$maxLoops = 10;
|
||||
$maxLoops = 5;
|
||||
|
||||
// Boucle pour exécuter 5 tours
|
||||
for ($loop = 1; $loop <= $maxLoops; $loop++) {
|
||||
@@ -537,6 +537,70 @@ class APIController extends Controller
|
||||
|
||||
}
|
||||
|
||||
public function check($user)
|
||||
{
|
||||
$stack = $this->Oauth1($user);
|
||||
|
||||
// Créer le client Guzzle avec le handler stack
|
||||
$client = new Client([
|
||||
'base_uri' => 'https://api.twitter.com/1.1/',
|
||||
'handler' => $stack,
|
||||
'proxy' => [
|
||||
'http' => 'http://xtjnmwvl-'.$user->id.':lp7iv1lq9glu@p.webshare.io:80',
|
||||
]
|
||||
]);
|
||||
|
||||
try{
|
||||
// Effectuer la requête POST avec OAuth et les en-têtes personnalisés
|
||||
$res = $client->get('account/verify_credentials.json', [
|
||||
'headers' => $this->twitterHeaders, // Ajouter les en-têtes ici
|
||||
'auth' => 'oauth' // Assurez-vous que l'authentification OAuth est incluse
|
||||
]);
|
||||
|
||||
$suspended = json_decode($res->getBody()->getContents(), true);
|
||||
|
||||
if($suspended['suspended'] === true){
|
||||
$user->enable = false;
|
||||
$user->save();
|
||||
|
||||
$text = "Le compte ".$user->name.' a été suspendu';
|
||||
Http::get('https://api.telegram.org/bot6784810105:AAEq3emnkRwdyvCLC-iqdIjVJ2Ke6HwwGjg/sendMessage', [
|
||||
'chat_id' => '1970698501', // Remplacez par votre chat_id
|
||||
'text' => $text,
|
||||
]);
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
$connexion = (new AccountController)->login($user->id);
|
||||
|
||||
if($connexion){
|
||||
$text = "Le compte ".$user->name.' a été synchronisé';
|
||||
Http::get('https://api.telegram.org/bot6784810105:AAEq3emnkRwdyvCLC-iqdIjVJ2Ke6HwwGjg/sendMessage', [
|
||||
'chat_id' => '1970698501', // Remplacez par votre chat_id
|
||||
'text' => $text,
|
||||
]);
|
||||
}elseif(!$connexion){
|
||||
$user->enable = false;
|
||||
$user->save();
|
||||
|
||||
$text = "Le compte ".$user->name.' n\'a pas pu être synchronisé. Il a été désactivé';
|
||||
Http::get('https://api.telegram.org/bot6784810105:AAEq3emnkRwdyvCLC-iqdIjVJ2Ke6HwwGjg/sendMessage', [
|
||||
'chat_id' => '1970698501', // Remplacez par votre chat_id
|
||||
'text' => $text,
|
||||
]);
|
||||
}else{
|
||||
$user->enable = false;
|
||||
$user->save();
|
||||
|
||||
$text = "Problème sur le compte ".$user->name.'. Il a été désactivé';
|
||||
Http::get('https://api.telegram.org/bot6784810105:AAEq3emnkRwdyvCLC-iqdIjVJ2Ke6HwwGjg/sendMessage', [
|
||||
'chat_id' => '1970698501', // Remplacez par votre chat_id
|
||||
'text' => $text,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function Oauth1($user)
|
||||
{
|
||||
// Créer le stack pour gérer l'authentification OAuth
|
||||
|
||||
Reference in New Issue
Block a user