Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server
正在显示
2 个修改的文件
包含
69 行增加
和
5 行删除
| @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Bside\BCom; | @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Bside\BCom; | ||
| 12 | use App\Enums\Common\Code; | 12 | use App\Enums\Common\Code; |
| 13 | use App\Helper\Arr; | 13 | use App\Helper\Arr; |
| 14 | use App\Http\Controllers\Bside\BaseController; | 14 | use App\Http\Controllers\Bside\BaseController; |
| 15 | +use App\Jobs\UpdatePageJob; | ||
| 15 | use App\Models\Com\Notify; | 16 | use App\Models\Com\Notify; |
| 16 | use App\Models\Com\UpdateLog; | 17 | use App\Models\Com\UpdateLog; |
| 17 | use App\Models\Com\UpdateNotify; | 18 | use App\Models\Com\UpdateNotify; |
| @@ -107,7 +108,7 @@ class CNoticeController extends BaseController | @@ -107,7 +108,7 @@ class CNoticeController extends BaseController | ||
| 107 | }else{ | 108 | }else{ |
| 108 | //其他服务器:请求对应C端接口 | 109 | //其他服务器:请求对应C端接口 |
| 109 | $c_url = $this->user['domain'].'api/update_page/'; | 110 | $c_url = $this->user['domain'].'api/update_page/'; |
| 110 | - $param = [ | 111 | + $c_param = [ |
| 111 | 'project_id' => $this->user['project_id'], | 112 | 'project_id' => $this->user['project_id'], |
| 112 | 'type' => $type, | 113 | 'type' => $type, |
| 113 | 'route' => $route, | 114 | 'route' => $route, |
| @@ -115,10 +116,10 @@ class CNoticeController extends BaseController | @@ -115,10 +116,10 @@ class CNoticeController extends BaseController | ||
| 115 | 'language'=> $language, | 116 | 'language'=> $language, |
| 116 | 'is_sitemap' => $is_sitemap | 117 | 'is_sitemap' => $is_sitemap |
| 117 | ]; | 118 | ]; |
| 118 | - http_post($c_url, json_encode($param)); | ||
| 119 | -// $shell = 'curl -X POST ' . escapeshellarg($c_url) . ' -H "Content-Type: application/json"' . | ||
| 120 | -// ' -d ' . escapeshellarg(json_encode($param)) . ' > /dev/null 2>&1 &'; | ||
| 121 | -// shell_exec($shell); | 119 | +// http_post($c_url, json_encode($c_param)); |
| 120 | + | ||
| 121 | + //2024-10-11:改为异步请求 | ||
| 122 | + UpdatePageJob::dispatch(['c_url'=>$c_url,'c_params'=>json_encode($c_param)]); | ||
| 122 | } | 123 | } |
| 123 | $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); | 124 | $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); |
| 124 | } | 125 | } |
app/Jobs/UpdatePageJob.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Jobs; | ||
| 4 | + | ||
| 5 | +use Illuminate\Bus\Queueable; | ||
| 6 | +use Illuminate\Contracts\Queue\ShouldQueue; | ||
| 7 | +use Illuminate\Foundation\Bus\Dispatchable; | ||
| 8 | +use Illuminate\Queue\InteractsWithQueue; | ||
| 9 | +use Illuminate\Queue\SerializesModels; | ||
| 10 | + | ||
| 11 | +class UpdatePageJob implements ShouldQueue | ||
| 12 | +{ | ||
| 13 | + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
| 14 | + | ||
| 15 | + public $tries = 3; // 可配置任务重试次数 | ||
| 16 | + | ||
| 17 | + protected $param; | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Create a new job instance. | ||
| 21 | + * | ||
| 22 | + * @param $data | ||
| 23 | + * @return void | ||
| 24 | + */ | ||
| 25 | + public function __construct($data) | ||
| 26 | + { | ||
| 27 | + $this->param = $data; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * Execute the job. | ||
| 32 | + * B端更新页面异步请求 | ||
| 33 | + * @return bool | ||
| 34 | + */ | ||
| 35 | + public function handle() | ||
| 36 | + { | ||
| 37 | + $c_url = $this->param['c_url']; | ||
| 38 | + $c_params = $this->param['c_params']; | ||
| 39 | + | ||
| 40 | + try { | ||
| 41 | + $re = http_post($c_url, $c_params, [], true); | ||
| 42 | + if (isset($re['status']) && $re['status'] == 200) { | ||
| 43 | + $this->output($c_url . ' | 请求成功'); | ||
| 44 | + } else { | ||
| 45 | + $this->output($c_url . ' | ' . ($re['message'] ?? '未返回失败原因')); | ||
| 46 | + } | ||
| 47 | + } catch (\Exception $e) { | ||
| 48 | + $this->output($c_url . ' | 请求异常:' . $e->getMessage()); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + | ||
| 52 | + return true; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 输出处理日志 | ||
| 57 | + * @param $message | ||
| 58 | + */ | ||
| 59 | + public function output($message) | ||
| 60 | + { | ||
| 61 | + echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL; | ||
| 62 | + } | ||
| 63 | +} |
-
请 注册 或 登录 后发表评论