🚧 Démarre le développement suite au passage à React

This commit is contained in:
Shikiryu 2018-06-29 00:04:32 +02:00
parent 7cada3dd07
commit 3a5008cc95
6 changed files with 127 additions and 29 deletions

5
.gitignore vendored
View File

@ -3,5 +3,6 @@
/composer.lock /composer.lock
/vendor/ /vendor/
/.idea/ /.idea/
/deals/lbcreposter.ini /data/config/lbcreposter.ini
/deals/*/ /data/deals/*/
data/logs/*.html

0
data/logs/.gitkeep Normal file
View File

View File

@ -2,7 +2,7 @@
namespace Shikiryu\LBCReposter; namespace Shikiryu\LBCReposter;
use Goutte\Client; use GuzzleHttp\Client;
class Account class Account
{ {
@ -20,22 +20,19 @@ class Account
*/ */
public function __construct(Config $config) public function __construct(Config $config)
{ {
$this->client = new \Goutte\Client(); $this->client = new Client([
$this->client->setClient(
new \GuzzleHttp\Client([
'timeout' => 90, 'timeout' => 90,
'verify' => false, 'verify' => false,
'curl' => [ 'curl' => [
CURLOPT_TIMEOUT => 60, CURLOPT_TIMEOUT => 60,
CURLOPT_TIMEOUT_MS => 60, CURLOPT_TIMEOUT_MS => 60,
CURLOPT_CONNECTTIMEOUT => 60, CURLOPT_CONNECTTIMEOUT => 60,
CURLOPT_COOKIEJAR => tmpfile(),
], ],
'headers' => [ 'headers' => [
'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0', 'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0',
], ],
]) ]);
);
$this->client->setMaxRedirects(10);
$this->config = $config; $this->config = $config;
} }
@ -64,8 +61,8 @@ class Account
public function isConnected() public function isConnected()
{ {
if (!$this->is_connected) { if (!$this->is_connected) {
$crawler = $this->client->request('GET', Actions::HOME_URL); // $crawler = $this->client->request('GET', Actions::HOME_URL);
$this->is_connected = $crawler->filter('#account_logout')->count() == 1; // $this->is_connected = $crawler->filter('#account_logout')->count() == 1;
} }
return $this->is_connected; return $this->is_connected;
} }

View File

@ -2,17 +2,22 @@
namespace Shikiryu\LBCReposter; namespace Shikiryu\LBCReposter;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Crawler;
class Actions class Actions
{ {
const HOME_URL = 'https://www.leboncoin.fr/'; const HOME_URL = 'https://www.leboncoin.fr/';
const LOGIN_URL = 'https://www.leboncoin.fr/beta/ajax/popins/connexion.html';
const ACCOUNT_URL = 'https://compteperso.leboncoin.fr/account/index.html'; const ACCOUNT_URL = 'https://compteperso.leboncoin.fr/account/index.html';
const ADD_URL = 'https://www.leboncoin.fr/ai/form/0'; const ADD_URL = 'https://www.leboncoin.fr/ai/form/0';
const DELETE_URL = 'https://compteperso.leboncoin.fr/store/main?cmd=adservices'; const DELETE_URL = 'https://compteperso.leboncoin.fr/store/main?cmd=adservices';
const UPLOAD_URL = 'https://www.leboncoin.fr/ai/photo_upload_ajax/0'; const UPLOAD_URL = 'https://www.leboncoin.fr/ai/photo_upload_ajax/0';
const API_LOGIN_URL = 'https://api.leboncoin.fr/api/oauth/v1/token';
const API_DEAL_RETRIEVE_URL = 'https://api.leboncoin.fr/api/dashboard/v1/search';
const API_PROFILE_URL = 'https://api.leboncoin.fr/api/accounts/v1/accounts/me/personaldata';
const API_STATUS_URL = 'https://api.leboncoin.fr/api/dashboard/v1/kyc_status/me';
const VERBOSE_INFO = 1; const VERBOSE_INFO = 1;
const VERBOSE_PAGE = 2; const VERBOSE_PAGE = 2;
const VERBOSE_REQUEST = 4; const VERBOSE_REQUEST = 4;
@ -21,6 +26,8 @@ class Actions
protected $debug = false; protected $debug = false;
protected $verbose = self::VERBOSE_INFO; protected $verbose = self::VERBOSE_INFO;
protected $access_token;
/** /**
* @var Account * @var Account
*/ */
@ -80,12 +87,34 @@ class Actions
{ {
if (!$this->account->isConnected()) { if (!$this->account->isConnected()) {
// Let's connect to your account (or not) // Let's connect to your account (or not)
$crawler = $this->account->getClient()->request('GET', self::LOGIN_URL); try {
$this->addPageDebug('connect', $crawler); $crawler = $this->account->getClient()->request('POST', self::API_LOGIN_URL, [
$form = $crawler->selectButton('Se connecter')->form(); 'form_params' => [
$crawler = $this->account->getClient()->submit($form, ['st_username' => $this->account->getConfig()->login, 'st_passwd' => $this->account->getConfig()->password]); 'client_id' => 'frontweb',
$this->addPageDebug('checkIsConnected', $crawler); 'grant_type' => 'password',
$this->account->setConnected($crawler->filter('.account_userinfo')->count() > 0); 'password' => $this->account->getConfig()->password,
'username' => $this->account->getConfig()->login
]
]);
$response = json_decode($crawler->getBody()->getContents());
$this->access_token = $response->access_token;
} catch (GuzzleException $e) {
$this->account->setConnected(false);
}
try {
$crawler = $this->account->getClient()->request('GET', self::API_STATUS_URL,
[
'headers' => [
'Accept' => 'application/json',
'Authorization' => sprintf('Bearer %s', $this->access_token)
]
]
);
$response = json_decode($crawler->getBody()->getContents());
$this->account->setConnected($response->status === 1);
} catch (GuzzleException $e) {
$this->account->setConnected(false);
}
} }
return $this->account->isConnected(); return $this->account->isConnected();
} }
@ -99,7 +128,40 @@ class Actions
{ {
if ($this->connect()) { if ($this->connect()) {
// Let's go to our dashboard // Let's go to our dashboard
$crawler = $this->account->getClient()->request('GET', self::ACCOUNT_URL); $search_params = [
'context' => 'default',
'filters' => [
'owner' => [
'store_id' => ''
]
],
'limit' => '5',
'offset' => '0',
'sort_by' => 'date',
'sort_order' => 'desc',
];
var_dump($search_params);
var_dump( $this->access_token );
try {
$crawler = $this->account->getClient()->request('POST', self::API_DEAL_RETRIEVE_URL,
[
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
// 'api_key' => self::API_KEY,
'Authorization' => sprintf('Bearer %s', $this->access_token),
],
'body' => json_encode($search_params),
'debug' => true,
]
);
$response = json_decode($crawler->getBody()->getContents());
var_dump($response); exit;
$this->account->setConnected($response->status === 1);
} catch (GuzzleException $e) {
echo $e->getMessage() . ' - '.$e->getTraceAsString(); exit;
$this->account->setConnected(false);
}
$this->addPageDebug('retrieve', $crawler); $this->addPageDebug('retrieve', $crawler);
// Let's list our existing deals // Let's list our existing deals
$deals = $crawler->filter('#dashboard .list .element')->each( $deals = $crawler->filter('#dashboard .list .element')->each(

38
library/User.php Normal file
View File

@ -0,0 +1,38 @@
<?php
namespace Shikiryu\LBCReposter;
class User
{
protected $storeId;
protected $userId;
/**
* User constructor.
* @param $storeId
* @param $userId
*/
public function __construct($storeId, $userId)
{
$this->storeId = $storeId;
$this->userId = $userId;
}
/**
* @return mixed
*/
public function getStoreId()
{
return $this->storeId;
}
/**
* @return mixed
*/
public function getUserId()
{
return $this->userId;
}
}