diff --git a/beike/Admin/Http/Controllers/MarketingController.php b/beike/Admin/Http/Controllers/MarketingController.php index ea76eb77..a171cc52 100644 --- a/beike/Admin/Http/Controllers/MarketingController.php +++ b/beike/Admin/Http/Controllers/MarketingController.php @@ -29,7 +29,7 @@ class MarketingController 'type' => $request->get('type'), 'keyword' => $request->get('keyword'), ]; - $plugins = MarketingService::getList($filters); + $plugins = MarketingService::getInstance()->getList($filters); $data = [ 'plugins' => $plugins, 'types' => PluginRepo::getTypes(), @@ -49,8 +49,8 @@ class MarketingController public function show(Request $request) { try { - $code = $request->code; - $plugin = MarketingService::getPlugin($code); + $pluginCode = $request->code; + $plugin = MarketingService::getInstance()->getPlugin($pluginCode); $data = [ 'plugin' => $plugin, ]; @@ -68,16 +68,7 @@ class MarketingController { try { $pluginCode = $request->code; - $datetime = date('Y-m-d'); - $url = config('beike.api_url') . "/api/plugins/{$pluginCode}/download"; - $content = file_get_contents($url); - - $pluginPath = "plugins/{$pluginCode}-{$datetime}.zip"; - Storage::disk('local')->put($pluginPath, $content); - - $pluginZip = storage_path('app/' . $pluginPath); - $zipFile = Zip::open($pluginZip); - $zipFile->extract(base_path('plugins')); + MarketingService::getInstance()->download($pluginCode); return json_success('下载解压成功, 请去插件列表安装'); } catch (\Exception $e) { return json_fail($e->getMessage()); diff --git a/beike/Admin/Services/MarketingService.php b/beike/Admin/Services/MarketingService.php index ab936939..35cca426 100644 --- a/beike/Admin/Services/MarketingService.php +++ b/beike/Admin/Services/MarketingService.php @@ -11,27 +11,62 @@ namespace Beike\Admin\Services; +use ZanySoft\Zip\Zip; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Storage; +use Illuminate\Http\Client\PendingRequest; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class MarketingService { - public static function getList($filters = []) + private PendingRequest $httpClient; + + public function __construct() + { + $this->httpClient = Http::withOptions([ + 'verify' => false, + ])->withHeaders([ + 'developer-token' => system_setting('base.developer_token'), + ]); + } + + public static function getInstance() + { + return new self; + } + + public function getList($filters = []) { $url = config('beike.api_url') . '/api/plugins'; if (!empty($filters)) { $url .= '?' . http_build_query($filters); } - return Http::withOptions(['verify' => false])->get($url)->json(); + return $this->httpClient->get($url)->json(); } - public static function getPlugin($code) + public function getPlugin($pluginCode) { - $url = config('beike.api_url') . '/api/plugins/' . $code; - $plugin = Http::withOptions(['verify' => false])->get($url)->json(); + $url = config('beike.api_url') . '/api/plugins/' . $pluginCode; + $plugin = $this->httpClient->get($url)->json(); if (empty($plugin)) { throw new NotFoundHttpException('该插件不存在或已下架'); } return $plugin; } + + public function download($pluginCode) + { + $datetime = date('Y-m-d'); + $url = config('beike.api_url') . "/api/plugins/{$pluginCode}/download"; + + $content = $this->httpClient->get($url)->body(); + + $pluginPath = "plugins/{$pluginCode}-{$datetime}.zip"; + Storage::disk('local')->put($pluginPath, $content); + + $pluginZip = storage_path('app/' . $pluginPath); + $zipFile = Zip::open($pluginZip); + $zipFile->extract(base_path('plugins')); + } + } diff --git a/plugins/Paypal/Static/image/logo.png b/plugins/Paypal/Static/image/logo.png index a8ab186f..e078b425 100644 Binary files a/plugins/Paypal/Static/image/logo.png and b/plugins/Paypal/Static/image/logo.png differ diff --git a/plugins/Paypal/config.json b/plugins/Paypal/config.json index 42b76e45..79742db2 100644 --- a/plugins/Paypal/config.json +++ b/plugins/Paypal/config.json @@ -4,7 +4,7 @@ "description": "PayPal 支付 PayPal Developer", "type": "payment", "version": "v1.0.0", - "icon": "/image/logo.png", + "icon": "plugin/paypal/image/logo.png", "author": { "name": "成都光大网络科技有限公司", "email": "yangjin@beikeshop.com"