Пример #1
0
function getAmazonPrice($region, $asin)
{
    $xml = aws_signed_request($region, array("Operation" => "ItemLookup", "ItemId" => $asin, "IncludeReviewsSummary" => False, "ResponseGroup" => "Medium,OfferSummary"));
    $item = $xml->Items->Item;
    $title = htmlentities((string) $item->ItemAttributes->Title);
    $url = htmlentities((string) $item->DetailPageURL);
    $image = htmlentities((string) $item->MediumImage->URL);
    $price = htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
    $code = htmlentities((string) $item->OfferSummary->LowestNewPrice->CurrencyCode);
    $qty = htmlentities((string) $item->OfferSummary->TotalNew);
    if ($qty !== "0") {
        $response = array("code" => $code, "price" => number_format((double) ($price / 100), 2, '.', ''), "image" => $image, "url" => $url, "title" => $title);
    }
    return $response;
}
Пример #2
0
function getAmazonData($SearchPhrase, $RequestType)
{
    include_once "aws_signed_request.php";
    $public_key = "AKIAIRPU52XIPOIZS5OA";
    $private_key = "MQUKYscxHYenmyPApVY9NmCi/9+KDC2FxiBeZmgn";
    if ($RequestType == "ItemLookup") {
        $pxml = aws_signed_request("com", array("Operation" => "ItemLookup", "SearchIndex" => "Books", "ItemId" => "{$SearchPhrase}", "IdType" => "ISBN", "ResponseGroup" => "Large"), $public_key, $private_key);
        if ($pxml === False) {
            return false;
            // Problem in accessing AMAZON API
        } else {
            if ($pxml->Items->Item->ASIN == "") {
                return false;
            } else {
                $Amazon['AmazonListPrice'] = $pxml->Items->Item->ItemAttributes->ListPrice->FormattedPrice;
                $Amazon['NonAmazonNewPrice'] = $pxml->Items->Item->OfferSummary->LowestNewPrice->FormattedPrice;
                $Amazon['NonAmazonUsedPrice'] = $pxml->Items->Item->OfferSummary->LowestUsedPrice->FormattedPrice;
                $Amazon['AmazonDiscountPrice'] = $pxml->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice;
                $Amazon['AmazonDetailPageURL'] = $pxml->Items->Item->DetailPageURL;
                return $Amazon;
            }
            // Else
        }
        // Else
    } else {
        if ($RequestType == "ItemSearch") {
            $pxml = aws_signed_request("com", array("Operation" => "ItemSearch", "SearchIndex" => "Books", "Keywords" => "{$SearchPhrase}", "ResponseGroup" => "Large"), $public_key, $private_key);
            if ($pxml === False) {
                return false;
                // Problem in accessing AMAZON API
            } else {
                if ($pxml->Items->Item->ItemAttributes->ListPrice->FormattedPrice == "") {
                    return false;
                } else {
                    $Amazon['AmazonListPrice'] = $pxml->Items->Item->ItemAttributes->ListPrice->FormattedPrice;
                    $Amazon['NonAmazonNewPrice'] = $pxml->Items->Item->OfferSummary->LowestNewPrice->FormattedPrice;
                    $Amazon['NonAmazonUsedPrice'] = $pxml->Items->Item->OfferSummary->LowestUsedPrice->FormattedPrice;
                    $Amazon['AmazonDiscountPrice'] = $pxml->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice;
                    $Amazon['AmazonDetailPageURL'] = $pxml->Items->Item->DetailPageURL;
                    return $Amazon;
                }
                // Else
            }
            // Else
        }
    }
}
Пример #3
0
function query($asin)
{
    global $public_key, $private_key;
    /* $requestparams	=	array("Operation"=>"ItemLookup", "Condition"=>"All", "ItemId"=>$asin, "IdType"=>"ASIN", "Availability"=>"Available", 
       "ResponseGroup"=>"Offers,OfferSummary,ItemAttributes"); */
    $requestparams = array("Operation" => "ItemLookup", "Condition" => "All", "ItemId" => $asin, "IdType" => "ASIN", "Availability" => "Available", "ResponseGroup" => "Large", "MerchantId" => "Amazon");
    $pxml = aws_signed_request("com", $requestparams, $public_key, $private_key);
    //print_r($pxml);
    //die();
    if ($pxml === False) {
        echo "No response.\n";
    } else {
        if ($pxml) {
            store_results($pxml);
            //unset($pxml);
        } else {
            echo "Query returned no results.\n";
        }
    }
}
Пример #4
0
function searchAWSItemDetail($asin, $type)
{
    $public_key = "AKIAJDNZSMGIHLN7E2IQ";
    $private_key = "xXiE5eQr+ugOOh5QCFJYSXlZykdZh1PVapwTzdEY";
    $retval = array();
    $data = array();
    $string_to_sign = array("Operation" => "ItemLookup", "ItemId" => $asin, "ResponseGroup" => "Small, Offers, Images, EditorialReview,Reviews");
    $xml = aws_signed_request("com", $string_to_sign, $public_key, $private_key);
    //print_r($xml);
    $i = 0;
    $items = $xml->Items->Item;
    foreach ($items as $item) {
        $reviews = array();
        $j = 0;
        if ($item->CustomerReviews) {
            foreach ($item->CustomerReviews->Review as $review) {
                $reviews[$j] = array('rating' => (string) $review->Rating, 'reviewer' => (string) $review->Reviewer->Nickname == '' ? 'You-Know-Who' : (string) $review->Reviewer->Nickname, 'location' => (string) $review->Reviewer->Location == '' ? 'Nowhere' : (string) $review->Reviewer->Location, 'date' => (string) $review->Date, 'summary' => (string) $review->Summary, 'content' => (string) $review->Content);
                $j++;
            }
        }
        if ((int) $item->Offers->TotalOffers == 0) {
            $price = 'N/A';
        } else {
            $price = (string) $item->Offers->Offer->OfferListing->Price->FormattedPrice;
        }
        if ($item->EditorialReviews) {
            $description = $type == 'books' ? (string) $item->EditorialReviews->EditorialReview->Content : '';
        } else {
            $description = 'N/A';
        }
        $data[$i] = array('itemId' => $asin, 'title' => (string) $item->ItemAttributes->Title, 'author' => $type == 'books' ? (string) $item->ItemAttributes->Author : (string) $item->ItemAttributes->Artist, 'price' => $price, 'image' => (string) $item->LargeImage->URL, 'averating' => (string) $item->CustomerReviews->AverageRating, 'totalreviews' => (string) $item->CustomerReviews->TotalReviews, 'totalreviewpages' => (string) $item->CustomerReviews->TotalReviewPages, 'review' => $reviews, 'description' => $description);
        $i++;
    }
    $retval['status'] = 'OK';
    $retval['statusmsg'] = 'OK';
    $retval['data'] = $data;
    return $retval;
}
 /**
  * Query Amazon with the issued parameters
  * 
  * @param array $parameters parameters to query around
  * @return simpleXmlObject xml query response
  */
 private function queryAmazon($parameters)
 {
     return aws_signed_request("com", $parameters, $this->public_key, $this->private_key, $this->associate_tag);
 }
Пример #6
0
/**
 * Given the ASIN (a unique amazon product identifier), looks up and displays detailed info for that
 * item.
 */
function ItemLookup($asin, $index = 0)
{
    global $LW_AMZN_THUMB_SIZE, $LW_AMZN_NUMCOLS, $wgMemc;
    $memKey = wfMemcKey('AMZN_ITEM_LOOKUP', $asin);
    $response = $wgMemc->get($memKey);
    if (empty($response)) {
        $params = array("Operation" => "ItemLookup", "ItemId" => $asin, "ResponseGroup" => "Medium,Offers");
        $request = aws_signed_request($params, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);
        $response = Http::get($request);
        $wgMemc->set($memKey, $response, SECONDS_IN_A_DAY);
    }
    $parsed_xml = simplexml_load_string($response);
    $DATA_COL_WIDTH = (LW_AD_WIDTH - $LW_AMZN_THUMB_SIZE * $LW_AMZN_NUMCOLS) / $LW_AMZN_NUMCOLS;
    if (isset($parsed_xml->Items) && $parsed_xml->Items->Request->IsValid) {
        $current = $parsed_xml->Items->Item;
        $detailPageUrl = urldecode($current->DetailPageURL);
        // Are we supposed to do this, or just leave "ws" (presumably "web service") as the tag?
        $detailPageUrl = str_replace("tag=ws", "tag=" . WIKIA_AMZN_AFFIL_ID, $detailPageUrl);
        //if(isset($current->Offers->Offer->OfferListing->OfferListingId)){ //only show items for which there is an offer
        switch ($LW_AMZN_THUMB_SIZE) {
            case 30:
                $imgSrc = $current->ImageSets->ImageSet->SwatchImage->URL;
                break;
            case 40:
            case 75:
            default:
                $imgSrc = $current->SmallImage->URL;
                break;
        }
        $alt = $current->ItemAttributes->Title;
        $alt = str_replace("'", '"', $alt);
        print "\t\t\t\t\t<td width='" . $LW_AMZN_THUMB_SIZE . "px'><a href='{$detailPageUrl}'><img src='" . $imgSrc . "' width='" . $LW_AMZN_THUMB_SIZE . "px' height='" . $LW_AMZN_THUMB_SIZE . "px' alt='{$alt}'/></a></td>\n";
        print "\t\t\t\t\t<td width='" . $DATA_COL_WIDTH . "px'><b><a href='{$detailPageUrl}'>" . $current->ItemAttributes->Title . "</a></b>";
        $artist = "";
        if (isset($current->ItemAttributes->Artist)) {
            $artist = $current->ItemAttributes->Artist;
        } elseif (isset($current->ItemAttributes->Creator)) {
            $artist = $current->ItemAttributes->Creator;
        }
        if ($artist != "") {
            $searchLink = str_replace(WIKIA_AMZN_SEARCH_TOKEN, $artist, WIKIA_AMZN_SEARCH_LINK);
            print "<br/>by <a href='{$searchLink}'>{$artist}</a>";
        }
        print "<br/>" . $current->OfferSummary->LowestNewPrice->FormattedPrice . "<br/>";
        print "</td>\n";
        //}
    }
}
Пример #7
0
<?php

$asin = $_POST['asin'];
$public_key = "public_key";
$private_key = "private_key";
$associate_tag = "associate_tage";
include "../../aws_signed_request.php";
$request = aws_signed_request('com', array('Operation' => 'ItemLookup', 'ItemId' => $asin, 'ResponseGroup' => 'Large'), $public_key, $private_key, $associate_tag);
$response = @file_get_contents($request);
if ($response === FALSE) {
    echo "Request failed.<br>";
} else {
    // parse XML
    //echo '<pre>';
    $pxml = simplexml_load_string($response);
    //var_dump($pxml);
    echo "Title: ";
    echo $pxml->Items->Item->ItemAttributes->Title;
    echo "</br></br>ASIN: ";
    echo $pxml->Items->Request->ItemLookupRequest->ItemId;
    echo "</br></br>Manufacturer: ";
    echo $pxml->Items->Item->ItemAttributes->Manufacturer;
    echo "</br></br>Part Number: ";
    echo $pxml->Items->Item->ItemAttributes->PartNumber;
    echo "</br></br>UPC: ";
    echo $pxml->Items->Item->ItemAttributes->UPC;
    echo "</br></br>Formatted Price: ";
    echo $pxml->Items->Item->ItemAttributes->ListPrice->FormattedPrice;
    echo "</br></br>Category: ";
    echo $pxml->Items->Item->ItemAttributes->ProductGroup;
    $weight = $pxml->Items->Item->ItemAttributes->PackageDimensions->Weight / 100;
Пример #8
0
<?php

/*
amacms接口
*/
//设置头部
header("Content-type:text/html;charset=UTF-8");
//包含数据库文件
include 'conn.php';
include 'config.php';
//获取Keywords
$keywords = $_GET['keywords'];
//开始调用API
$request = aws_signed_request($amacountry, array('Operation' => 'ItemSearch', 'Keywords' => $keywords, 'SearchIndex' => 'All', 'ResponseGroup' => 'Medium'), $public_key, $private_key, $associate_tag);
//访问Api地址
// $response = Curl_Get($request);
$response = Curl_Get('http://localhost/jiekou/xml.xml');
//解析xml
if ($response === FLASE) {
    echo "Request failed.\n";
} else {
    $pxml = simplexml_load_string($response);
    $Item_Arr = $pxml->Items;
    $Item_Arr = json_encode($Item_Arr);
    $Item_Arr = json_decode($Item_Arr, true);
    // $retrun_arr =array();
    $New_Arr = array();
    foreach ($Item_Arr['Item'] as $key => $value) {
        // array_push($return_arr['ASIN'],$value->ASIN);
        /*
        print 'ASIN: '.$value['ASIN']."<br>";//ASIN ASIN码
Пример #9
0
 /**
  * Query Amazon with the issued parameters
  * 
  * @param array $parameters parameters to query around
  * @return simpleXmlObject xml query response
  */
 private function queryAmazon($parameters)
 {
     // Since I querry amazon always with this method, I should put in the associate tag here, now that it is required.
     // I bet Amazon did this just to see who is paying attention while using their old product API...
     $parameters["AssociateTag"] = myInfo::MY_AMAZON_ASSOCIATE_ID;
     /*
     print("<pre>");
     print_r("About to querry Amazon with the following parameters: ");
     print_r($parameters);
     print("</pre>");
     */
     return aws_signed_request("com", $parameters, $this->public_key, $this->private_key);
 }
Пример #10
0
        }
    }
}
/*initiate aws request*/
$access_key = 'AKIAJA6JTHPOKRZ2GLZA';
$secret_key = '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';
if ($_GET['operation'] == 'ItemSearch') {
    $param2 = array('AssociateTag' => 'giftertipster-20', 'Operation' => $_GET['operation'], 'Version' => '2011-08-01', 'SearchIndex' => $_GET['cats'], 'Keywords' => $_GET['keywords'], 'ResponseGroup' => $_GET['responses']);
} else {
    if ($_GET['operation'] == 'ItemLookup') {
        $param2 = array('AssociateTag' => 'giftertipster-20', 'Operation' => $_GET['operation'], 'Version' => '2011-08-01', 'ItemId' => $_GET['keywords'], 'ResponseGroup' => $_GET['responses']);
    } else {
        echo 'Error';
    }
}
$amazon_object = aws_signed_request('com', $param2, $access_key, $secret_key);
/*display aws results
foreach ($amazon_object->Items->Item AS $items){
	
	echo $items->ItemAttributes->Title;
	echo '<br />';
	echo '<img src="';
	
	if (!empty($items->MediumImage->URL)){
		
		echo $items->MediumImage->URL;
	
	}else{
		
		echo $items->ImageSets->ImageSet[0]->MediumImage->URL;
	
Пример #11
0
 $parameters["Pochette"] = $parameters["_url"] . "/converter/picture/album/" . $results["Code_Album"];
 $parameters["ASIN"] = $results["ASIN"];
 //Récupération des informations amazon
 $details = file_get_contents(aws_signed_request("fr", array("Operation" => "ItemLookup", "ItemId" => $parameters["ASIN"], "ResponseGroup" => "Small"), $public, $secret, "musique04c-21"));
 $details = simplexml_load_string($details);
 $parameters["Amazon_Title"] = (string) $details->Items->Item->ItemAttributes->Title;
 $parameters["Amazon_Group"] = (string) $details->Items->Item->ItemAttributes->ProductGroup;
 $parameters["Amazon_Manu"] = (string) $details->Items->Item->ItemAttributes->Manufacturer;
 $parameters["Amazon_Creators"] = array();
 foreach ($details->Items->Item->ItemAttributes->Creator as $node) {
     $data = array();
     $data["role"] = $node->attributes()[0];
     $data["name"] = $node;
     array_push($parameters["Amazon_Creators"], $data);
 }
 $details = file_get_contents(aws_signed_request("fr", array("Operation" => "ItemLookup", "ItemId" => $parameters["ASIN"], "ResponseGroup" => "OfferSummary"), $public, $secret, "musique04c-21"));
 $details = simplexml_load_string($details);
 $parameters["Amazon_Price"] = (string) $details->Items->Item->OfferSummary->LowestUsedPrice->FormattedPrice;
 // Récupère toutes les enregistrement de l'album concerné
 $sql = "SELECT DISTINCT Album.Code_Album as Code_Album, Enregistrement.Code_Morceau as Code_Morceau, Enregistrement.Titre as Titre, Enregistrement.Durée as Duree, Enregistrement.Prix as Prix FROM Album ";
 $sql = $sql . "INNER JOIN Disque ON Disque.Code_Album = Album.Code_Album INNER JOIN Composition_Disque ON Composition_Disque.Code_Disque = Disque.Code_Disque INNER JOIN Enregistrement ON Enregistrement.Code_Morceau = Composition_Disque.Code_Morceau WHERE Album.Code_Album = '" . $parameters["code"] . "'";
 $results = $_system_registry->getModel()->query($sql)->fetchall();
 for ($i = 0; $i != count($results); $i++) {
     $results[$i]["pair"] = "";
     //Détermination de la parité pour le design
     if ($i % 2 == 0) {
         $results[$i]["pair"] = "pair";
     }
     $results[$i]["Extrait"] = $parameters["_url"] . "/converter/sound/record/" . $results[$i]["Code_Morceau"];
 }
 $parameters["records"] = $results;
Пример #12
0
$auth = $_POST['auth'];
$users_table = $wpdb->prefix . "users";
$songs_table = $wpdb->prefix . "songs";
$result = $wpdb->get_results("SELECT id FROM {$users_table} WHERE MD5(user_pass) = '{$auth}'");
if ($result) {
    $user_id = $result[0]->id;
    $title = $_POST['song']['title'];
    $artist = $_POST['song']['artist'];
    $album = $_POST['song']['album'];
    if ($title && $artist && $album) {
        require "aws_signed_request.php";
        $search = "{$artist}, {$album}";
        $public_key = get_option("now_playing_amzn_public");
        $private_key = get_option("now_playing_amzn_private");
        $tag = get_option("now_playing_amzn_tag") ? get_option("now_playing_amzn_tag") : "mybl06a-20";
        $pxml = aws_signed_request("com", array("Operation" => "ItemSearch", "SearchIndex" => "Music", "ResponseGroup" => "Small,Images", "Keywords" => $search, "AssociateTag" => $tag), $public_key, $private_key);
        if ($pxml === False) {
            die("problem inserting song");
        } else {
            if (isset($pxml->Items->Item->MediumImage->URL)) {
                $img = $pxml->Items->Item->MediumImage->URL;
                $url = $pxml->Items->Item->DetailPageURL;
            }
        }
        $insert = "INSERT INTO {$songs_table} (img, title, artist, album, url, user_id) VALUES ('{$img}','{$title}','{$artist}','{$album}','{$url}','{$user_id}')";
        $results = $wpdb->query($insert);
        echo "song inserted";
    } else {
        die("Missing required field");
    }
} else {
Пример #13
0
 protected function _fetchAlbumImage($artist, $album)
 {
     error_log('ARTIST:' . $artist);
     $xml = aws_signed_request($this->getAmazonCountryCode(), array('Operation' => 'ItemSearch', 'Artist' => $artist, 'Title' => $album, 'SearchIndex' => 'Music', 'ResponseGroup' => 'Images'), $this->getAmazonId(), $this->getAmazonAccessKey());
     if (!$xml) {
         throw new Exception('Error while performing API request');
     }
     $xml->registerXpathNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2009-03-31');
     $imageUrl = (string) array_shift($xml->xpath('//az:LargeImage/az:URL'));
     if (!$imageUrl) {
         error_log('ERROR');
         throw new Exception('Could not find cover');
     }
     if (extension_loaded('curl')) {
         $curl = curl_init($imageUrl);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         $image = curl_exec($curl);
     } else {
         $image = file_get_contents($imageUrl);
     }
     return $image;
 }
Пример #14
0
/**
 * Fetches the data for a given Amazon ID (equals ISBN)
 *
 * @author  Andreas Goetz <*****@*****.**>
 * @param   int   IMDB-ID
 * @return  array Result data
 */
function amazonawsData($id)
{
    global $amazonAWSUrl, $cache;
    global $CLIENTERROR;
    $url = aws_signed_request(array('Operation' => 'ItemLookup', 'ItemId' => $id, 'ResponseGroup' => 'Large'));
    $resp = httpClient($url, $cache);
    #   dump($resp);
    if ($resp['success']) {
        $xml = load_xml($resp['data']);
        #       dump($xml);
        $data = awsNodeData($xml->Items->Item[0]);
        #		dump($data);
    } else {
        $CLIENTERROR .= $resp['error'] . "\n";
    }
    // utf-8 according to HTTP response but simplexml complains?
    // utf-8 is already forced by load_xml
    $data['encoding'] = 'utf-8';
    return $data;
}