Actualiser api.php
This commit is contained in:
@@ -81,41 +81,67 @@ function fetchPosterByEAN($ean, $pdo) {
|
|||||||
$cached = getCache($pdo, $cacheKey);
|
$cached = getCache($pdo, $cacheKey);
|
||||||
if ($cached && !empty($cached['poster'])) return $cached['poster'];
|
if ($cached && !empty($cached['poster'])) return $cached['poster'];
|
||||||
|
|
||||||
// 1. UPCitemDB (Pas de clé nécessaire, version trial)
|
// 1. UPCitemDB (Toujours présent comme base gratuite, sans clé)
|
||||||
$upcData = fetchUPCitemdb($ean, $pdo);
|
$upcData = fetchUPCitemdb($ean, $pdo);
|
||||||
if ($upcData && !empty($upcData['poster'])) {
|
if ($upcData && !empty($upcData['poster'])) {
|
||||||
setCache($pdo, $cacheKey, ['poster' => $upcData['poster']], 'upc');
|
setCache($pdo, $cacheKey, ['poster' => $upcData['poster']], 'upc');
|
||||||
return $upcData['poster'];
|
return $upcData['poster'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. EAN-Search API
|
// 2. eBay Developers Program (Finding API)
|
||||||
$eanSearchKey = getConfigValue($pdo, 'ean_search_key');
|
$ebayKey = getConfigValue($pdo, 'ebay_api_key');
|
||||||
if ($eanSearchKey) {
|
if ($ebayKey) {
|
||||||
$url = "https://api.ean-search.org/api?token={$eanSearchKey}&op=barcode-lookup&ean={$ean}&format=json";
|
$url = "https://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME={$ebayKey}&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD&keywords={$ean}";
|
||||||
$res = httpGet($url, 5);
|
$res = httpGet($url, 5);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
$data = json_decode($res, true);
|
$data = json_decode($res, true);
|
||||||
if (!empty($data[0]['imageUrl'])) {
|
// On récupère l'image du premier résultat trouvé correspondant au code barre
|
||||||
setCache($pdo, $cacheKey, ['poster' => $data[0]['imageUrl']], 'ean_search');
|
if (!empty($data['findItemsByKeywordsResponse'][0]['searchResult'][0]['item'][0]['galleryURL'][0])) {
|
||||||
return $data[0]['imageUrl'];
|
$img = $data['findItemsByKeywordsResponse'][0]['searchResult'][0]['item'][0]['galleryURL'][0];
|
||||||
|
// eBay retourne parfois une image par défaut si non trouvée
|
||||||
|
if (strpos($img, 'default') === false) {
|
||||||
|
setCache($pdo, $cacheKey, ['poster' => $img], 'ebay');
|
||||||
|
return $img;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Barcode Lookup API
|
// 3. WorldCat APIs (xID / Search API)
|
||||||
$blKey = getConfigValue($pdo, 'barcode_lookup_key');
|
$worldcatKey = getConfigValue($pdo, 'worldcat_api_key');
|
||||||
if ($blKey) {
|
if ($worldcatKey) {
|
||||||
$url = "https://api.barcodelookup.com/v3/products?barcode={$ean}&key={$blKey}&formatted=y";
|
// WorldCat est principalement pour les livres (ISBN), utile pour les Digibooks ou éditions spéciales
|
||||||
|
$url = "https://worldcat.org/webservices/catalog/content/isbn/{$ean}?wskey={$worldcatKey}";
|
||||||
$res = httpGet($url, 5);
|
$res = httpGet($url, 5);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
$data = json_decode($res, true);
|
// Logique de parsing XML à implémenter selon la structure de réponse WorldCat
|
||||||
if (!empty($data['products'][0]['images'][0])) {
|
// Si une couverture est trouvée :
|
||||||
setCache($pdo, $cacheKey, ['poster' => $data['products'][0]['images'][0]], 'barcode_lookup');
|
// setCache($pdo, $cacheKey, ['poster' => $img], 'worldcat');
|
||||||
return $data['products'][0]['images'][0];
|
// return $img;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. Amazon Product Advertising API (PA-API 5.0)
|
||||||
|
$amazonKey = getConfigValue($pdo, 'amazon_api_key');
|
||||||
|
if ($amazonKey) {
|
||||||
|
// Note: L'API Amazon requiert une signature AWS V4 (clé d'accès + clé secrète).
|
||||||
|
// Voici la structure cible de l'appel pour rechercher par EAN (Keywords)
|
||||||
|
$url = "https://webservices.amazon.fr/paapi5/searchitems";
|
||||||
|
|
||||||
|
// Pseudo-requête de démonstration
|
||||||
|
// Il faudrait utiliser un SDK AWS ou une fonction de signature HMAC-SHA256 ici
|
||||||
|
$payload = json_encode([
|
||||||
|
"Keywords" => $ean,
|
||||||
|
"Resources" => ["Images.Primary.Large"],
|
||||||
|
"PartnerTag" => "moncinema-21",
|
||||||
|
"PartnerType" => "Associates",
|
||||||
|
"Marketplace" => "www.amazon.fr"
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Simulation d'une réponse valide
|
||||||
|
// if ($response && !empty($data['SearchResult']['Items'][0]['Images']['Primary']['Large']['URL'])) { ... }
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user