PHP
4
Вклад в тег
$clientId = '812'; //айди шопа
$apiKey = '04c1d-a754-4c7f-aa2c-8d14e256'; // ключ апи
$method = '/v1/product/list'; //метод запроса
#////тело запроса///#
$data = '{
"stocks": [
{
"product_id": 120000,
"offer_id": "PRD-1",
"stock": 20
},
{
"product_id": 124100,
"offer_id": "PRD-2",
"stock": 20
}
]
}';
#////////#
$result = post($clientId, $apiKey, $method, $data); //вывод результата
echo $result;
//фунция для с работы с API
function post($clientId, $apiKey, $method, $data){
$url = 'http://api-seller.ozon.ru'.$method;
$headers = array(
'Content-Type: application/json',
'Host: api-seller.ozon.ru',
'Client-Id: '.$clientId,
'Api-Key: '.$apiKey
) ;
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => $headers
);
curl_setopt_array($ch, $options);
$html = curl_exec($ch);
curl_close($ch);
return $html;
};
$url="http://billing.evpanet.com/user/";
$post = array(
'login' => 'aksenov',
'password' =>'123456789');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url) ;
curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) ");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie/$login.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie/$login.txt");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$html = curl_exec($ch);
echo $html;