หัวข้อ: หาผู้ใจดีช่วยสอนเรื่องเขียน Script landing page กับ Amazon ครับ
เริ่มหัวข้อโดย: krite2010 ที่ 16 กุมภาพันธ์ 2011, 12:24:38
ผมไม่เก่งภาษาอังกฤษนะครับ
จะเขียน script นะครับ เป็น PHP หรือ .phtml นะครับ คือ จะทำ landing page นะครับ ผมมี Access Key , Identify Key และ Secrate Key แล้ว หรือถ้าใครมี script ที่เป็น PHP หรือ .phtml ได้ยิ่งดี ที่สนับสนุนเงื่่อนไขปัจจุบันครับ ปล. จากบทความนี้ครับ ตอนที่ 1 http://www.thaiseoboard.com/index.php/topic,45860.0.html ตอนที่ 2 http://www.thaiseoboard.com/index.php?topic=46149.0 ตอนที่ 3 http://www.thaiseoboard.com/index.php/topic,46393.0.html ตอนที่ 4 http://www.thaiseoboard.com/index.php/topic,47531.0.html ตอนที่ 5 http://www.thaiseoboard.com/index.php/topic,49524.0.html
เออ ผมไม่ได้ใช้ Wordpress ครับ แต่ใช้ตัวอื่น สนับสนุน .phtml ครับ แนะนำด้วยขอบคุณอย่างสูงครับ ขอบคุณๆๆๆ
hปปp://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService &Version=2010-11-01 &Operation=ItemLookup( ตรงนี้ต้องเป็นอะไรครับ ) &ItemId=[ASIN ของสินค้ารายการนั้น 1 Item เช่น B00332FFIE แต่ไม่ทราบว่าเหมือนกับ ASIN กับ SKU คือตัวเดียวกันไหม ] &ResponseGroup=ItemAttributes,Images ( ตรงนี้ต้องเป็นอะไรครับ แนะนำด้วย
ช่วยสอนการเขียน landing page ด้วย PHP ตามเงื่อนไข Amazon ปัจจุบันให้หน่อยครับ โปรดแนะนำด้วย ขอบคุณ ปล. Amazon Associates Web Service ตัวไหนเป็นตัวล่าสุดครับ แนะนำด้วย ขอบคุณ
หัวข้อ: Re: หาผู้ใจดีช่วยสอนเรื่องเขียน Script landing page กับ Amazon ครับ
เริ่มหัวข้อโดย: krite2010 ที่ 16 กุมภาพันธ์ 2011, 12:30:05
จะเขียน code หรือแก้ code ครับ ช่วยดูให้หน่อยครับ จาก Simple Example of PHP software changes to comply with Authenticated / Signed Request / Query to Amazon's AWS / Product Advertising API for affiliate websites - which may affect some homeschool websites. Amazon documents hint at how to do this, but there's no sample code for PHP programming - Here's how I got it to work... // example starts with a typical AWS operation - no keys or timestamp yet $request = 'Operation=ItemLookup&ResponseGroup=Tags&TagsPerPage=20&Marketplace=us&Version=2008-04-07&ItemId=1604591935'; if ($THE_OLD_UNSIGNED_WAY) { // Here's the simple unsigned method that works until August 15 2009 $request = 'http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=YOUR_ACCESS_ID&'.$request; $response = file_get_contents($request); if ($response) $simple_response = simplexml_load_string($response); } else { // START CHANGES FOR SIGNED REQUEST // see http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?rest-signature.html for more details //Substitute your real Access Id here... $request = 'Service=AWSECommerceService&'. 'AWSAccessKeyId=YOUR_ACCESS_ID&'. 'Timestamp='.gmdate("Y-m-d\TH:i:s\Z").'&'. $request; // encode url - replace commas w/ %2C, replace colon w/ %3A // Could use urlencode($request) here, but $request may already be partially encoded $request = str_replace(',','%2C', $request); $request = str_replace(':','%3A', $request); //break request string into key/value pairs, $reqarr = explode('&',$request); //sort on byte value sort($reqarr); // tie back together w/ &'s $string_to_sign = implode("&", $reqarr); $string_to_sign = "GET\nwebservices.amazon.com\n/onca/xml\n".$string_to_sign; //Substitute your real Secret Key here... $signature = urlencode(base64_encode(hash_hmac("sha256", $string_to_sign, 'YOUR_SECRET_KEY', True))); $request .= '&Signature='.$signature; $request = 'http://webservices.amazon.com/onca/xml?'.$request; echo 'NEW REQ '.$request; // For this example, the above echo should yield: // NEW REQ http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=YOUR_ACCESS_ID&Timestamp=2009-07-22T00%3A14%3A26Z&Operation=ItemLookup&ResponseGroup=Tags&TagsPerPage=20&Marketplace=us&Version=2008-04-07&ItemId=1604591935&Signature=VVWycI8PUINBthhpsipfwCtvUuX6ma%2FbUzGFJ4pBO78%3D // - obviously this is a bogus request as we used placeholders for AccessId and SecretKey $response = file_get_contents($request); if ($response) $simple_response = simplexml_load_string($response); // if your signed request is invalid - AWS will give error response such as: // The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. // more help at: 1. <?php 2. 3. function aws_signed_request($region, $params, $public_key, $private_key) 4. { 5. /* 6. Copyright (c) 2009 Ulrich Mierendorff 7. 8. Permission is hereby granted, free of charge, to any person obtaining a 9. copy of this software and associated documentation files (the "Software"), 10. to deal in the Software without restriction, including without limitation 11. the rights to use, copy, modify, merge, publish, distribute, sublicense, 12. and/or sell copies of the Software, and to permit persons to whom the 13. Software is furnished to do so, subject to the following conditions: 14. 15. The above copyright notice and this permission notice shall be included in 16. all copies or substantial portions of the Software. 17. 18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24. DEALINGS IN THE SOFTWARE. 25. */ 26. 27. /* 28. Parameters: 29. $region - the Amazon(r) region (ca,com,co.uk,de,fr,jp) 30. $params - an array of parameters, eg. array("Operation"=>"ItemLookup", 31. "ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small") 32. $public_key - your "Access Key ID" 33. $private_key - your "Secret Access Key" 34. */ 35. 36. // some paramters 37. $method = "GET"; 38. $host = "ecs.amazonaws.".$region; 39. $uri = "/onca/xml"; 40. 41. // additional parameters 42. $params["Service"] = "AWSECommerceService"; 43. $params["AWSAccessKeyId"] = $public_key; 44. // GMT timestamp 45. $params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z"); 46. // API version 47. $params["Version"] = "2009-03-31"; 48. 49. // sort the parameters 50. ksort($params); 51. 52. // create the canonicalized query 53. $canonicalized_query = array(); 54. foreach ($params as $param=>$value) 55. { 56. $param = str_replace("%7E", "~", rawurlencode($param)); 57. $value = str_replace("%7E", "~", rawurlencode($value)); 58. $canonicalized_query[] = $param."=".$value; 59. } 60. $canonicalized_query = implode("&", $canonicalized_query); 61. 62. // create the string to sign 63. $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query; 64. 65. // calculate HMAC with SHA256 and base64-encoding 66. $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True)); 67. 68. // encode the signature for the request 69. $signature = str_replace("%7E", "~", rawurlencode($signature)); 70. 71. // create request 72. $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature; 73. 74. // do request 75. $response = @file_get_contents($request); 76. 77. if ($response === False) 78. { 79. return False; 80. } 81. else 82. { 83. // parse XML 84. $pxml = simplexml_load_string($response); 85. if ($pxml === False) 86. { 87. return False; // no xml 88. } 89. else 90. { 91. return $pxml; 92. } 93. } 94. } 95. ?>
After downloading and extracting aws_signed_request.zip you can include aws_signed_request.php in your PHP scripts. The function contained in this file takes four parameters. $region is the Amazon region (for example "com" or "fr"). $params is an array of parameters with the parameter names as keys. $public_key and $private_key are your keys you have got from Amazon. Here is an example (you have to replace $public_key and $private_key with your own identifiers) 1. include("aws_signed_request.php"); 2. 3. $public_key = "xxxxxx"; 4. $private_key = "xxxxxx"; 5. $pxml = aws_signed_request("com", array("Operation"=>"ItemLookup","ItemId"=>"B000X9FLKM","ResponseGroup"=>"Small"), $public_key, $private_key); 6. if ($pxml === False) 7. { 8. echo "Did not work.\n"; 9. } 10. else 11. { 12. if (isset($pxml->Items->Item->ItemAttributes->Title)) 13. { 14. echo $pxml->Items->Item->ItemAttributes->Title, "\n"; 15. } 16. else 17. { 18. echo "Could not find item.\n"; 19. } 20. }
คือ ไม่รู้เข้ากับกฎของ amazon ณ ปัจจุบันหรือไม่ และต้องปรับแก้อย่างไรครับ และเมื่อเปรียบเทียบกับอีก code คือ
หัวข้อ: Re: หาผู้ใจดีช่วยสอนเรื่องเขียน Script landing page กับ Amazon ครับ
เริ่มหัวข้อโดย: krite2010 ที่ 16 กุมภาพันธ์ 2011, 12:31:45
code นี้ได้จากเมื่องนอกมานะครับ ชื่อ file นี้คือ function.php ครับ <?php /** * * AWS_Cart 0.0.1 - November 2008 * Copyright (C) awsfm.com * AWS_Cart is licensed under a Creative Commons License * */
include('config.php');
function priceCheck($id,$sku,$price,$type){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=ItemLookup&ItemId=$sku&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); $awsListPrice=$parsed_xml->Items->Item->ItemAttributes->ListPrice->FormattedPrice; $awsListPriceDB=substr_replace($parsed_xml->Items->Item->ItemAttributes->ListPrice->Amount, '.', -2, 0); $awsOfferListPrice=$parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice; $awsOfferListPriceDB=substr_replace($parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->Amount, '.', -2, 0); if($type=='regular'){ if($awsListPrice!=$price){ $con = mysql_connect(dbhost,dbuser,dbpass); mysql_select_db(dbname,$con); mysql_query("UPDATE catalog_product_entity_decimal SET value=$awsListPriceDB WHERE entity_id=$id AND attribute_id='59'"); mysql_close($con); print $awsListPrice; }else{ print $price; } } if($type=='final'){ if($awsOfferListPrice!=$price){ $con = mysql_connect(dbhost,dbuser,dbpass); mysql_select_db(dbname,$con); mysql_query("UPDATE catalog_product_entity_decimal SET value=$awsOfferListPriceDB WHERE entity_id=$id AND attribute_id='60'"); mysql_close($con); print $awsOfferListPrice; }else{ print $price; } } }
function priceCheckCheckout($id,$sku,$price){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=ItemLookup&ItemId=$sku&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); $awsListPrice=$parsed_xml->Items->Item->ItemAttributes->ListPrice->FormattedPrice; $awsListPriceDB=substr_replace($parsed_xml->Items->Item->ItemAttributes->ListPrice->Amount, '.', -2, 0); $awsOfferListPrice=$parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice; $awsOfferListPriceDB=substr_replace($parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->Amount, '.', -2, 0); if($awsOfferListPrice!=$price){ $con = mysql_connect(dbhost,dbuser,dbpass); mysql_select_db(dbname,$con); mysql_query("UPDATE catalog_product_entity_decimal SET value=$awsOfferListPriceDB WHERE entity_id=$id AND attribute_id='60'"); mysql_close($con); } }
function itemLookup($sku, $qty){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=ItemLookup&ItemId=$sku&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); $offerListingId = urlencode($parsed_xml->Items->Item->Offers->Offer->OfferListing->OfferListingId); cartCreate($offerListingId, $qty); }
function cartCreate($offerListingId, $qty){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=CartCreate&Item.1.OfferListingId=$offerListingId&Item.1.Quantity=$qty"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); showCartContents($parsed_xml); }
function itemLookupAdd($sku, $qty, $cart, $hmac){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=ItemLookup&ItemId=$sku&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); $offerListingId = urlencode($parsed_xml->Items->Item->Offers->Offer->OfferListing->OfferListingId); cartAdd($offerListingId, $qty, $cart, $hmac); }
function cartAdd($offerListingId, $qty, $cart, $hmac){ $request="http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=CartAdd&CartId=$cart&HMAC=$hmac&Item.1.OfferListingId=$offerListingId&Item.1.Quantity=$qty"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); $response = file_get_contents($request); $parsed_xml = simplexml_load_string($response); showCartContents($parsed_xml); }
function showCartContents($parsed_xml){ global $checkout; global $CartId; global $HMAC; $checkout = $parsed_xml->Cart->PurchaseURL; $CartId = $parsed_xml->Cart->CartId; $HMAC = $parsed_xml->Cart->URLEncodedHMAC; } ?>
และอีก code ชื่อ file คือ config.php ครับ คือ <?php /** * * AWS_Cart 0.0.1 - November 2008 * Copyright (C) awsfm.com * AWS_Cart is licensed under a Creative Commons License * */
define('KEYID','1N9P3CKRQDC5BWFFNT02'); define('AssocTag','422blacklther-20');
define('dbhost','host'); define('dbname','database'); define('dbuser','user'); define('dbpass','password'); ?>
code อันไหน น่าจะใช้ได้กับ เงื่อนไขปัจจุบันครับ แล้วผมต้องแก้ไขตรงไหนบ้างโปรดแนะนำด้วย ขอบคุณ คือ ผมจะต้องแปลงไฟล์ จาก .php เป็น file .phtml เห็นหลายคนบอกว่าให้ทำการ Rename เป็นนามสกุล .phtml ไม่ทราบว่าถูกต้องไหม แนะนำด้วย ขอบคุณ ขอความกรุณาด้วย ขอบคุณ
หัวข้อ: Re: หาผู้ใจดีช่วยสอนเรื่องเขียน Script landing page กับ Amazon ครับ
เริ่มหัวข้อโดย: ohmohm ที่ 18 กุมภาพันธ์ 2011, 15:26:22
ลองแบบง่ายๆ ก่อน ดีไหม ดันโค้ด <?php include("includes/request.php"); // get it from [url]http://mierendo.com/software/aws_signed_query/[/url] $public_key = 'xxxxxxxxxxxxxxx'; // your public key $private_key = 'xxxxxxxxxxxxxxxx'; // your private key
$bnodeid = '540734' ; // today's deal, other may be searched by [url]http://www.google.co.th/search?q=inurl%3Anode%3D+site%3Aamazon.com+b[/url] $tag = 'YOUR_TAG_HERE-20' ; // your affilliate tag $parsed_xml = aws_signed_request("com", array( "Operation"=>'BrowseNodeLookup', // [url]http://docs.amazonwebservices.com/AWSEcommerceService/4-0/[/url] "BrowseNodeId"=>"$bnodeid", "ResponseGroup"=>'BrowseNodeInfo', "AssociateTag"=>"$tag"), $public_key, $private_key);
header('Content-type: text/xml'); print ( $parsed_xml->saveXML() ); ?> ถ้าแบบใช้ได้ทันที ก็ที่นี่ http://forums.thaisem.com/index.php?topic=8265.0
หัวข้อ: Re: หาผู้ใจดีช่วยสอนเรื่องเขียน Script landing page กับ Amazon ครับ
เริ่มหัวข้อโดย: bot2o ที่ 18 กุมภาพันธ์ 2011, 15:47:14
ทำไม ไม่เอา script ที่เขาแจกมา ใช้ก่อนล่ะครับ อย่าง 155store เขาก้อ แจกกันเยอะแยะ
|