

























<?php class AllegroModel extends YbModel { protected $access_token = null; protected $client_id = null; protected $client_secret = null; protected $host_url = null; /** * db config key * * @return string */ public function getDbKey() { return 'db'; } public function __construct($account){ $this->host_url = 'https://api.allegro.pl/'; $this->access_token = $account['access_token']; $this->client_id = $account['client_id']; $this->client_secret = $account['client_secret']; } public function get_customer_returns($data) { foreach ($data as $key=>$val){ $url.=$key.'='.$val.'&'; } $params = rtrim($url,"&"); $url = $this->host_url.'order/customer-returns'; if($params){ $url = $url.'?'.$params; } $headers[] = "Accept: application/vnd.allegro.beta.v1+json"; $headers[] = "Authorization: Bearer " . $this->access_token; $headers[] = "Content-Type: application/vnd.allegro.beta.v1+json"; $res = $this->cur_request($url, 'GET', '', $headers); return $res; } public function cur_request($URL, $type, $params, $headers) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $URL); if ($headers != "") { curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } else { curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded')); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); switch ($type) { case "GET" : curl_setopt($ch, CURLOPT_HTTPGET, true); break; case "POST": curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); break; case "PUT" : curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); break; case "PATCH": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); break; case "DELETE": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); break; } $file_contents = curl_exec($ch);//获得返回值 $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return [$responseCode, json_decode($file_contents, true)]; } }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。