option('type'); $data = $this->option('data'); log_s('数据同步(老) => 开始发送:' . $type, 'sync-old', 'send'); log_s($data, 'sync-old', 'send'); try { $platform = Platform::first(); if (!$platform) { log_s('数据同步(老) => 发送结果:无平台数据', 'sync-old', 'send'); return Command::SUCCESS; } if ($platform->status != Platform::STATUS_PASS) { log_s('数据同步(老) => 发送结果:权限不足', 'sync-old', 'send'); return Command::SUCCESS; } [$uri, $form_params] = $this->$type($data); $response = $this->newRequest()->post(rtrim($platform->url, '/') . '/' . $uri, [ 'headers' => [ 'Authorization' => "Bearer $platform->token", ], 'form_params' => $form_params ]); $contents = $response->getBody()->getContents(); console_info($contents); $result = json_decode($contents, true); log_s('数据同步(老) => 发送结果:' . var_export($result, true), 'sync-old', 'send'); } catch (Exception $exception) { log_s('数据同步(老) => 错误信息:' . $exception->getMessage(), 'sync-old', 'send'); } return Command::SUCCESS; } public function newRequest(): Client { return new Client([ 'timeout' => 10, 'verify' => false, 'http_errors' => false, ]); } private function syncOrder($data): array { return ['platform/v1/sync/order', json_decode($data, true)]; } }