job connect YD portal

This commit is contained in:
glovetleong
2021-12-16 21:46:33 +08:00
parent 4a158b8dac
commit 5e11b8ebdf
4 changed files with 157 additions and 0 deletions
@@ -0,0 +1,32 @@
<?php
namespace App\Classes\Modules\Orders\Services;
use Psr\Http\Message\ResponseInterface;
class FetchesDataFromYDPortal
{
/**
* @param string $url
* @param string $method
* @param $body
* @param bool $requiresAuthentication
* @return \Psr\Http\Message\ResponseInterface
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function clientRequest(string $url, string $method, $body){
$client = new \GuzzleHttp\Client();
$request = $client->requestAsync($method, $url, ['query' => $body]);
return $request->wait();
}
public function getResponseBody(ResponseInterface $request){
$content = $request->getBody()->getContents();
$content = str_replace("\r",'', $content);
return json_decode($content);
}
}
@@ -0,0 +1,40 @@
<?php
namespace App\Classes\Modules\PackingLists\Processors;
use App\Classes\Modules\Orders\Services\FetchesDataFromYDPortal;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class FetchOrderListsFromYdPortalProcessor
{
/**
/** @var FetchesDataFromVTPortal */
private $fetchesDataFRomYDPortal;
public function __construct(FetchesDataFromYDPortal $fetchesDataFRomYDPortal)
{
$this->fetchesDataFRomYDPortal = $fetchesDataFRomYDPortal;
}
/**
* @param Carbon|null $start
* @param Carbon|null $end
* @return array
* @throws GuzzleException
*/
public function execute(?Carbon $start = null, ?Carbon $end = null) {
$orderRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/GetOrderList.ashx', 'GET', [
'apicode' => '393b1cb4b8b37d09',
'begintime' => '1633968000',
'endtime' => '1639308222',
]);
$order = $this->fetchesDataFRomYDPortal->getResponseBody($orderRequest);
dd($order);
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands;
use App\Models\State;
use App\Http\Helpers\General;
use Illuminate\Console\Command;
use App\Jobs\CurlYdOrderListJob;
class CurlYdOrderListCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:curlYdOrderListCommand';
// php artisan queue:work
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
CurlYdOrderListJob::dispatch();
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Jobs;
use App\Classes\Modules\PackingLists\Processors\FetchOrderListsFromYdPortalProcessor;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class CurlYdOrderListJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
(App()->make(FetchOrderListsFromYdPortalProcessor::class))->execute();
}
}