/** * @return mixed|\Psr\Http\Message\ResponseInterface */ public function execute() { $response = null; $properties = $this->getProperties(); $client = $this->getClient(); switch ($this->method) { case Api::METHOD_GET: try { $response = $client->get($this->sign->getFullPath(), ['query' => $properties]); } catch (ClientException $e) { var_dump($e->getResponse()->getBody()->getContents()); } break; case Api::METHOD_POST: try { $response = $client->post($this->sign->getFullPath(), ['form_params' => $properties]); } catch (ClientException $e) { var_dump($e->getResponse()->getBody()->getContents()); } break; default: throw new \RuntimeException("Required methods " . Api::METHOD_GET . " and " . Api::METHOD_POST); } return is_null($response) ? $response : (object) json_decode($response->getBody()->getContents(), true); }
public static function buildParameters(Event $event) { ScriptHandler::buildParameters($event); $extras = $event->getComposer()->getPackage()->getExtra(); if (!isset($extras['aliexpress-open'])) { throw new \InvalidArgumentException('The parameter handler needs to be configured through the extra.aliexpress-open setting.'); } $configs = $extras['aliexpress-open']; if (!is_array($configs)) { throw new \InvalidArgumentException('The extra.aliexpress-open setting must be an array or a configuration object.'); } if (!file_exists($configs['file']) && file_exists($extras['incenteev-parameters']['file'])) { $YamlParser = new Parser(); $YamlValues = $YamlParser->parse(file_get_contents($extras['incenteev-parameters']['file'])); $params = ['client_id' => $YamlValues[$extras['incenteev-parameters']['parameter-key']]['appKey'], 'redirect_uri' => 'urn:ietf:wg:oauth:2.0:oob', 'site' => 'aliexpress']; ksort($params); $paramsForSign = $params; array_walk($paramsForSign, function (&$value, $key) { $value = $key . $value; }); $params[Api::SIGN_PARAM] = Sign::getSignString(implode("", $paramsForSign), $YamlValues[$extras['incenteev-parameters']['parameter-key']]['appKeySecret']); $link = "http://gw.api.alibaba.com/auth/authorize.htm?" . http_build_query($params, null, '&', PHP_QUERY_RFC3986); $event->getIO()->write('<comment>Goto ' . $link . ' and get temporary auth code.</comment>'); $processor = new Processor($event->getIO()); $processor->processFile($configs); } }