add token for marketing

This commit is contained in:
Edward Yang 2022-10-14 18:11:55 +08:00
parent dbc403550c
commit 8ca284f762
4 changed files with 45 additions and 19 deletions

View File

@ -29,7 +29,7 @@ class MarketingController
'type' => $request->get('type'), 'type' => $request->get('type'),
'keyword' => $request->get('keyword'), 'keyword' => $request->get('keyword'),
]; ];
$plugins = MarketingService::getList($filters); $plugins = MarketingService::getInstance()->getList($filters);
$data = [ $data = [
'plugins' => $plugins, 'plugins' => $plugins,
'types' => PluginRepo::getTypes(), 'types' => PluginRepo::getTypes(),
@ -49,8 +49,8 @@ class MarketingController
public function show(Request $request) public function show(Request $request)
{ {
try { try {
$code = $request->code; $pluginCode = $request->code;
$plugin = MarketingService::getPlugin($code); $plugin = MarketingService::getInstance()->getPlugin($pluginCode);
$data = [ $data = [
'plugin' => $plugin, 'plugin' => $plugin,
]; ];
@ -68,16 +68,7 @@ class MarketingController
{ {
try { try {
$pluginCode = $request->code; $pluginCode = $request->code;
$datetime = date('Y-m-d'); MarketingService::getInstance()->download($pluginCode);
$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'));
return json_success('下载解压成功, 请去插件列表安装'); return json_success('下载解压成功, 请去插件列表安装');
} catch (\Exception $e) { } catch (\Exception $e) {
return json_fail($e->getMessage()); return json_fail($e->getMessage());

View File

@ -11,27 +11,62 @@
namespace Beike\Admin\Services; namespace Beike\Admin\Services;
use ZanySoft\Zip\Zip;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Client\PendingRequest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class MarketingService 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'; $url = config('beike.api_url') . '/api/plugins';
if (!empty($filters)) { if (!empty($filters)) {
$url .= '?' . http_build_query($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; $url = config('beike.api_url') . '/api/plugins/' . $pluginCode;
$plugin = Http::withOptions(['verify' => false])->get($url)->json(); $plugin = $this->httpClient->get($url)->json();
if (empty($plugin)) { if (empty($plugin)) {
throw new NotFoundHttpException('该插件不存在或已下架'); throw new NotFoundHttpException('该插件不存在或已下架');
} }
return $plugin; 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'));
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -4,7 +4,7 @@
"description": "PayPal 支付 <a href='https://developer.paypal.com/' target='_blank'>PayPal Developer</a>", "description": "PayPal 支付 <a href='https://developer.paypal.com/' target='_blank'>PayPal Developer</a>",
"type": "payment", "type": "payment",
"version": "v1.0.0", "version": "v1.0.0",
"icon": "/image/logo.png", "icon": "plugin/paypal/image/logo.png",
"author": { "author": {
"name": "成都光大网络科技有限公司", "name": "成都光大网络科技有限公司",
"email": "yangjin@beikeshop.com" "email": "yangjin@beikeshop.com"