作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server

... ... @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Bside\BCom;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Jobs\UpdatePageJob;
use App\Models\Com\Notify;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateNotify;
... ... @@ -107,7 +108,7 @@ class CNoticeController extends BaseController
}else{
//其他服务器:请求对应C端接口
$c_url = $this->user['domain'].'api/update_page/';
$param = [
$c_param = [
'project_id' => $this->user['project_id'],
'type' => $type,
'route' => $route,
... ... @@ -115,10 +116,10 @@ class CNoticeController extends BaseController
'language'=> $language,
'is_sitemap' => $is_sitemap
];
http_post($c_url, json_encode($param));
// $shell = 'curl -X POST ' . escapeshellarg($c_url) . ' -H "Content-Type: application/json"' .
// ' -d ' . escapeshellarg(json_encode($param)) . ' > /dev/null 2>&1 &';
// shell_exec($shell);
// http_post($c_url, json_encode($c_param));
//2024-10-11:改为异步请求
UpdatePageJob::dispatch(['c_url'=>$c_url,'c_params'=>json_encode($c_param)]);
}
$this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
}
... ...
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class UpdatePageJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 3; // 可配置任务重试次数
protected $param;
/**
* Create a new job instance.
*
* @param $data
* @return void
*/
public function __construct($data)
{
$this->param = $data;
}
/**
* Execute the job.
* B端更新页面异步请求
* @return bool
*/
public function handle()
{
$c_url = $this->param['c_url'];
$c_params = $this->param['c_params'];
try {
$re = http_post($c_url, $c_params, [], true);
if (isset($re['status']) && $re['status'] == 200) {
$this->output($c_url . ' | 请求成功');
} else {
$this->output($c_url . ' | ' . ($re['message'] ?? '未返回失败原因'));
}
} catch (\Exception $e) {
$this->output($c_url . ' | 请求异常:' . $e->getMessage());
}
return true;
}
/**
* 输出处理日志
* @param $message
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
}
}
... ...