Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xutl committed Feb 15, 2021
1 parent 620ab4c commit 4e8f457
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/Jobs/DeleteJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* This is NOT a freeware, use is subject to license terms
* @copyright Copyright (c) 2010-2099 Jinan Larva Information Technology Co., Ltd.
* @link http://www.larva.com.cn/
* @license http://www.larva.com.cn/license/
*/

namespace Larva\Baidu\Push\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Larva\Baidu\Push\Models\BaiduPush;

/**
* 删除推送
*
* @author Tongle Xu <xutongle@gmail.com>
*/
class DeleteJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* 任务可以尝试的最大次数。
*
* @var int
*/
public $tries = 2;

/**
* @var BaiduPush
*/
protected $baiduPush;

/**
* @var string
*/
protected $site;

/**
* @var string
*/
protected $token;

/**
* Create a new job instance.
*
* @param BaiduPush $baiduPush
*/
public function __construct(BaiduPush $baiduPush)
{
$this->baiduPush = $baiduPush;
if (function_exists('settings')) {
$this->site = config('app.url');
$this->token = settings('system.baidu_site_token');
} else {
$this->site = config('services.baidu.site');
$this->token = config('services.baidu.site_token');
}
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
Http::contentType('text/plain')->post("http://data.zz.baidu.com/del?site={$this->site}&token={$this->token}", [
'body' => $this->baiduPush->url
]);
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
}
97 changes: 97 additions & 0 deletions src/Jobs/PushJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* @copyright Copyright (c) 2018 Jinan Larva Information Technology Co., Ltd.
* @link http://www.larvacent.com/
* @license http://www.larvacent.com/license/
*/

namespace Larva\Baidu\Push\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
use Larva\Baidu\Push\Models\BaiduPush;

/**
* 推送 Url 给百度
*
* @author Tongle Xu <xutongle@gmail.com>
*/
class PushJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* 任务可以尝试的最大次数。
*
* @var int
*/
public $tries = 2;

/**
* @var BaiduPush
*/
protected $baiduPush;

/**
* @var string
*/
protected $site;

/**
* @var string
*/
protected $token;

/**
* Create a new job instance.
*
* @param BaiduPush $baiduPush
*/
public function __construct(BaiduPush $baiduPush)
{
$this->baiduPush = $baiduPush;
if (function_exists('settings')) {
$this->site = config('app.url');
$this->token = settings('system.baidu_site_token');
} else {
$this->site = config('services.baidu.site');
$this->token = config('services.baidu.site_token');
}
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
if ($this->baiduPush->type == BaiduPush::TYPE_SITE) {
$response = Http::contentType('text/plain')->post("http://data.zz.baidu.com/urls?site={$this->site}&token={$this->token}", [
'body' => $this->baiduPush->url
]);
if (isset($response['error'])) {
$this->baiduPush->setFailure($response['error'] . ':' . $response['message']);
} else {
$this->baiduPush->setSuccess();
}
} else if ($this->baiduPush->type == BaiduPush::TYPE_DAILY) {
$response = Http::contentType('text/plain')->post("http://data.zz.baidu.com/urls?site={$this->site}&token={$this->token}&type=daily", [
'body' => $this->baiduPush->url
]);
if (isset($response['error'])) {
$this->baiduPush->setFailure($response['error'] . ':' . $response['message']);
} else {
$this->baiduPush->setSuccess();
}
}
} catch (\Exception $e) {
$this->baiduPush->setFailure($e->getMessage());
}
}
}
87 changes: 87 additions & 0 deletions src/Jobs/UpdateJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* This is NOT a freeware, use is subject to license terms
* @copyright Copyright (c) 2010-2099 Jinan Larva Information Technology Co., Ltd.
* @link http://www.larva.com.cn/
* @license http://www.larva.com.cn/license/
*/

namespace Larva\Baidu\Push\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
use Larva\Baidu\Push\Models\BaiduPush;

/**
* Class UpdateJob
*
* @author Tongle Xu <xutongle@gmail.com>
*/
class UpdateJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* 任务可以尝试的最大次数。
*
* @var int
*/
public $tries = 2;

/**
* @var BaiduPush
*/
protected $baiduPush;

/**
* @var string
*/
protected $site;

/**
* @var string
*/
protected $token;

/**
* Create a new job instance.
*
* @param BaiduPush $baiduPush
*/
public function __construct(BaiduPush $baiduPush)
{
$this->baiduPush = $baiduPush;
if(function_exists('settings')){
$this->site = config('app.url');
$this->token = settings('system.baidu_site_token');
} else {
$this->site = config('services.baidu.site');
$this->token = config('services.baidu.site_token');
}
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$response = Http::contentType('text/plain')->post("http://data.zz.baidu.com/update?site={$this->site}&token={$this->token}", [
'body' => $this->baiduPush->url
]);
if (isset($response['error'])) {
$this->baiduPush->setFailure($response['error'] . ':' . $response['message']);
} else {
$this->baiduPush->setSuccess();
}
} catch (\Exception $e) {
$this->baiduPush->setFailure($e->getMessage());
}
}
}

0 comments on commit 4e8f457

Please sign in to comment.