ThaiSEOBoard.com

ความรู้ทั่วไป => Amazon => ข้อความที่เริ่มโดย: kkusd ที่ 31 สิงหาคม 2010, 21:02:29



หัวข้อ: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: kkusd ที่ 31 สิงหาคม 2010, 21:02:29
ขอหน่อยครับเอาแบบเป็น php เอาไปใช้ได้กับหน้า html ธรรมดากจะดีมากเลยครับ :wanwan017: :wanwan017:



ทำเสร็จแล้วจะเอามาแจก


หัวข้อ: Re: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: kkusd ที่ 31 สิงหาคม 2010, 21:12:16
ไม่เลยเหรอ สงสัยเก็บไว้ใช้คนเดียว


หัวข้อ: Re: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: medieval ที่ 31 สิงหาคม 2010, 21:15:12
ลองไปศึกษา ใน155cafe ในไฟล์ newfunc.php ดูครับ  ค้นหาคำว่า## Merchant  อยู่แถวนั่นละครับ ถ้าให้อธิบายคงยาวเป็นกอง คงช่วยได้แค่นี้ละครับ  :wanwan017:

http://www.thaiseoboard.com/index.php/topic,120721.0.html


หัวข้อ: Re: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: IzeSem ที่ 31 สิงหาคม 2010, 21:19:08
เดี๊ยวผมทำให้ง่ายๆแปร๊บนะ


หัวข้อ: Re: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: sugar ที่ 31 สิงหาคม 2010, 21:21:49
 :wanwan004: มารอแต็งให้ด้วยอีกคน  :wanwan013:


หัวข้อ: Re: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: kkusd ที่ 31 สิงหาคม 2010, 21:36:17
ลองไปศึกษา ใน155cafe ในไฟล์ newfunc.php ดูครับ  ค้นหาคำว่า## Merchant  อยู่แถวนั่นละครับ ถ้าให้อธิบายคงยาวเป็นกอง คงช่วยได้แค่นี้ละครับ  :wanwan017:

[url]http://www.thaiseoboard.com/index.php/topic,120721.0.html[/url]


ขอบคุณครับ เก็บไว้แกะโค้ต

เดี๊ยวผมทำให้ง่ายๆแปร๊บนะ


ขอบคุณล่วงหน้าครับ :wanwan020: :wanwan020:


หัวข้อ: Re: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: IzeSem ที่ 31 สิงหาคม 2010, 21:41:04
ไฟล์ test.php
โค๊ด:
<?php 
require_once(
"aws_signed_request.php");
$public_key  =""
$private_key =""
$tag ="";
$parsed_xml aws_signed_request("com", array("Operation"=>"ItemLookup","ItemId"=>"B002LITT56","ResponseGroup"=>"Large, OfferFull","MerchantId"=>"Featured","AssociateTag"=>"$tag"),$public_key$private_key);
$buyurl $parsed_xml->Items->Item->ItemLinks->ItemLink[6]->URL;
?>

<div align="center">
<table width="880" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="250" align="center" bgcolor="#eeeeee"><strong>Seller</strong></td>
            <td width="360" align="center" bgcolor="#eeeeee"><strong>Description</strong></td>
            <td width="250" align="center" bgcolor="#eeeeee"><strong>Price</strong></td>
          </tr>
          <?php 
foreach ($parsed_xml->Items->Item->Offers->Offer as $offer) {
$merchantname $offer->Merchant->Name;
$availability $offer->OfferListing->Availability;
$supersaving $offer->OfferListing->IsEligibleForSuperSaverShipping;
if  (
$supersaving==1){
                 
$supersaving "<br />This item ships for <strong>FREE with Super Saver Shipping</strong>.<br />";
}else{
                 
$supersaving ="<br />";
}
$price $offer->OfferListing->Price->FormattedPrice;
?>

   <tr>
            <td width="250" align="center" valign="middle"><?php echo "<strong>".$merchantname."</strong>"?><br /></td>
            <td width="360" align="left" valign="middle"><?php echo $availability.$supersaving?></td>
            <td width="250" align="center" valign="middle"><table width="250" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center"><?php echo $price;?></td>
              </tr>
              <tr>
                <td align="center">
                <a href="<?php echo $buyurl;?>" target="_blank">Go to Store</a>
                </td>
              </tr>
            </table>
  </td>
          </tr>
          <tr>
            <td colspan="3" valign="top"></td>
          </tr>
          <?php }?>
          <tr>
                </tr>
                </table>
                </div>
ไฟล์ aws_signed_request.php กำหนด api เป็น API Version 2010-06-01
โค๊ด:
<?php

function aws_signed_request($region$params$public_key$private_key)
{
    
/*
    Copyright (c) 2009 Ulrich Mierendorff

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
    */
    
    /*
    Parameters:
        $region - the Amazon(r) region (ca,com,co.uk,de,fr,jp)
        $params - an array of parameters, eg. array("Operation"=>"ItemLookup",
                        "ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small")
        $public_key - your "Access Key ID"
        $private_key - your "Secret Access Key"
    */

    // some paramters
    
$method "GET";
    
$host "ecs.amazonaws.".$region;
    
$uri "/onca/xml";
    
    
// additional parameters
    
$params["Service"] = "AWSECommerceService";
    
$params["AWSAccessKeyId"] = $public_key;
    
// GMT timestamp
    
$params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
    
// API version
    
$params["Version"] = "2010-06-01";
    
    
// sort the parameters
    
ksort($params);
    
    
// create the canonicalized query
    
$canonicalized_query = array();
    foreach (
$params as $param=>$value)
    {
        
$param str_replace("%7E""~"rawurlencode($param));
        
$value str_replace("%7E""~"rawurlencode($value));
        
$canonicalized_query[] = $param."=".$value;
    }
    
$canonicalized_query implode("&"$canonicalized_query);
    
    
// create the string to sign
    
$string_to_sign $method."\n".$host."\n".$uri."\n".$canonicalized_query;
    
    
// calculate HMAC with SHA256 and base64-encoding
    
$signature base64_encode(hash_hmac("sha256"$string_to_sign$private_keyTrue));
    
    
// encode the signature for the request
    
$signature str_replace("%7E""~"rawurlencode($signature));
    
    
// create request
    
$request "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
    
    
// do request
$strload curl_init($request);
           curl_setopt($strloadCURLOPT_HEADERfalse);
           curl_setopt($strloadCURLOPT_RETURNTRANSFERtrue);
$responsecurl_exec($strload);
           curl_close($strload);
    if (
$response === False)
    {
        return 
False;
    }
    else
    {
        
// parse XML
        
$pxml simplexml_load_string($response);
        if (
$pxml === False)
        {
            return 
False// no xml
        
}
        else
        {
            return 
$pxml;
        }
    }
}
?>

แก้
   $public_key  ="";
   $private_key ="";
   $tag ="";


หัวข้อ: Re: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: olomixolo ที่ 31 สิงหาคม 2010, 21:43:14
ขอบคุณ ครับ แต่ยัง งงๆ อยู่ นะ
 :P


หัวข้อ: Re: ขอ Code Compare ของ amazon หน่อยครับ
เริ่มหัวข้อโดย: sugar ที่ 31 สิงหาคม 2010, 21:47:14
ไฟล์ test.php
โค๊ด:
<?php 
require_once(
"aws_signed_request.php");
$public_key  =""
$private_key =""
$tag ="";
$parsed_xml aws_signed_request("com", array("Operation"=>"ItemLookup","ItemId"=>"B002LITT56","ResponseGroup"=>"Large, OfferFull","MerchantId"=>"Featured","AssociateTag"=>"$tag"),$public_key$private_key);
$buyurl $parsed_xml->Items->Item->ItemLinks->ItemLink[6]->URL;
?>

<div align="center">
<table width="880" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="250" align="center" bgcolor="#eeeeee"><strong>Seller</strong></td>
            <td width="360" align="center" bgcolor="#eeeeee"><strong>Description</strong></td>
            <td width="250" align="center" bgcolor="#eeeeee"><strong>Price</strong></td>
          </tr>
          <?php 
foreach ($parsed_xml->Items->Item->Offers->Offer as $offer) {
$merchantname $offer->Merchant->Name;
$availability $offer->OfferListing->Availability;
$supersaving $offer->OfferListing->IsEligibleForSuperSaverShipping;
if  (
$supersaving==1){
                 
$supersaving "<br />This item ships for <strong>FREE with Super Saver Shipping</strong>.<br />";
}else{
                 
$supersaving ="<br />";
}
$price $offer->OfferListing->Price->FormattedPrice;
?>

   <tr>
            <td width="250" align="center" valign="middle"><?php echo "<strong>".$merchantname."</strong>"?><br /></td>
            <td width="360" align="left" valign="middle"><?php echo $availability.$supersaving?></td>
            <td width="250" align="center" valign="middle"><table width="250" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td align="center"><?php echo $price;?></td>
              </tr>
              <tr>
                <td align="center">
                <a href="<?php echo $buyurl;?>" target="_blank">Go to Store</a>
                </td>
              </tr>
            </table>
  </td>
          </tr>
          <tr>
            <td colspan="3" valign="top"></td>
          </tr>
          <?php }?>
          <tr>
                </tr>
                </table>
                </div>
ไฟล์ aws_signed_request.php กำหนด api เป็น API Version 2010-06-01
โค๊ด:
<?php

function aws_signed_request($region$params$public_key$private_key)
{
    
/*
    Copyright (c) 2009 Ulrich Mierendorff

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
    */
    
    /*
    Parameters:
        $region - the Amazon(r) region (ca,com,co.uk,de,fr,jp)
        $params - an array of parameters, eg. array("Operation"=>"ItemLookup",
                        "ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small")
        $public_key - your "Access Key ID"
        $private_key - your "Secret Access Key"
    */

    // some paramters
    
$method "GET";
    
$host "ecs.amazonaws.".$region;
    
$uri "/onca/xml";
    
    
// additional parameters
    
$params["Service"] = "AWSECommerceService";
    
$params["AWSAccessKeyId"] = $public_key;
    
// GMT timestamp
    
$params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
    
// API version
    
$params["Version"] = "2010-06-01";
    
    
// sort the parameters
    
ksort($params);
    
    
// create the canonicalized query
    
$canonicalized_query = array();
    foreach (
$params as $param=>$value)
    {
        
$param str_replace("%7E""~"rawurlencode($param));
        
$value str_replace("%7E""~"rawurlencode($value));
        
$canonicalized_query[] = $param."=".$value;
    }
    
$canonicalized_query implode("&"$canonicalized_query);
    
    
// create the string to sign
    
$string_to_sign $method."\n".$host."\n".$uri."\n".$canonicalized_query;
    
    
// calculate HMAC with SHA256 and base64-encoding
    
$signature base64_encode(hash_hmac("sha256"$string_to_sign$private_keyTrue));
    
    
// encode the signature for the request
    
$signature str_replace("%7E""~"rawurlencode($signature));
    
    
// create request
    
$request "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature;
    
    
// do request
$strload curl_init($request);
           curl_setopt($strloadCURLOPT_HEADERfalse);
           curl_setopt($strloadCURLOPT_RETURNTRANSFERtrue);
$responsecurl_exec($strload);
           curl_close($strload);
    if (
$response === False)
    {
        return 
False;
    }
    else
    {
        
// parse XML
        
$pxml simplexml_load_string($response);
        if (
$pxml === False)
        {
            return 
False// no xml
        
}
        else
        {
            return 
$pxml;
        }
    }
}
?>

แก้
   $public_key  ="";
   $private_key ="";
   $tag ="";



กดแทงให้แล้ว ค่า เดี๋ยวลองไปมั่วต่อดู  :-[ ก็ งงนิสๆๆ  :P