add token for marketing
This commit is contained in:
parent
dbc403550c
commit
8ca284f762
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
|
|
@ -4,7 +4,7 @@
|
|||
"description": "PayPal 支付 <a href='https://developer.paypal.com/' target='_blank'>PayPal Developer</a>",
|
||||
"type": "payment",
|
||||
"version": "v1.0.0",
|
||||
"icon": "/image/logo.png",
|
||||
"icon": "plugin/paypal/image/logo.png",
|
||||
"author": {
|
||||
"name": "成都光大网络科技有限公司",
|
||||
"email": "yangjin@beikeshop.com"
|
||||
|
|
|
|||
Loading…
Reference in New Issue