| Current Path : /var/www/magento.test.indacotrentino.com/www/scripts/import/OLD/ |
| Current File : /var/www/magento.test.indacotrentino.com/www/scripts/import/OLD/connection.php |
<?php
function getToken() {
$username = 'admin';
$password = 'Inda_987';
$host = 'http://indaco2.38121.it';
$userData = ["username" => $username, "password" => $password];
$ch = curl_init($host . "/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));
$token = curl_exec($ch);
$token = str_ireplace('"', '', $token);
$config['host'] = $host;
$config['token'] = $token;
return $config;
}
function senddata($rest, $attribute) {
$config = getToken();
echo var_dump($config);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $config['host'].$rest,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $attribute,
CURLOPT_HTTPHEADER => array(
"authorization: Bearer " . $config['token'],
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
die("");
}
return $response;
}
function searchCondition($rest, $searchCondition) {
$config = getToken();
$ch = curl_init($config['host'] . $rest . "?" . $searchCondition);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // Request method
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"authorization: Bearer " . $config['token'],
"cache-control: no-cache",
"content-type: application/json"
));
$result = curl_exec($ch);
$result = json_decode($result, 1);
return $result;
}