จากกระทู้นี้-http://www.thaiseoboard.com/index.php/topic,84528 เลยหาทางเอามาทำเองบาง และเคยเห็นกระทู้นี้
http://forums.sem.or.th/index.php?topic=20315.0 ( ความรู้เป็นของมนุษยชาติ ) เลยแจกมั่งดีกว่า
<?php
// http://forums.digitalpoint.com/showthread.php?t=1485116
// http://help.cj.com/en/web_services/product_catalog_search_service_rest.htm
$CJ_ID = "your developer key here";
$website_id = "your web id here";
$kw = "halloween costume"; // your keyword here
$amount_link_page = 10;
$page = !empty($_GET['page']) ? $_GET['page'] : 1;
if (isset($_GET['manu']))
{
$manufacturer = $_GET['manu'];
$url = "https://product-search.api.cj.com/v2/product-search?website-id=$website_id&serviceable-area=US&advertiser-ids=joined&page-number=$page&records-per-page=$amount_link_page&manufacturer-name=". urlencode($manufacturer);
}
else
{
$url = "https://product-search.api.cj.com/v2/product-search?website-id=$website_id&serviceable-area=US&advertiser-ids=joined&page-number=$page&records-per-page=$amount_link_page&keywords=". urlencode($kw);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$CJ_ID));
$curl_results = curl_exec($ch);
curl_close($ch);
if ( $curl_results === False)
{
$pxml = null;
}
else
{
$pxml = simplexml_load_string($curl_results);
}
if (( !isset($pxml) ) or ( $pxml === False ))
{
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CJ API REST example</title>
</head>
<body>
<?php
echo "total matched " .$pxml->products['total-matched'] .
", page number " .$pxml->products['page-number'] .", ".$pxml->products['records-returned']." items per page";
echo "<br/>";
echo "<hr/>";
foreach ( $pxml->products->product as $prdlist )
{
if ( isset ($prdlist->{'image-url'}) and ($prdlist->{'image-url'} != "" ))
{
echo "<a style=\"margin: 10px;border: none;\" rel=\"nofollow\" href=\"#\" onclick=\"javascript:window.open('". $prdlist->{'buy-url'} ."')\">" . "<img style=\"border: none;\" src=\"".$prdlist->{'image-url'}."\" >" . "</a><br />";
}
echo "<a rel=\"nofollow\" href=\"#\" onclick=\"javascript:window.open('". $prdlist->{'buy-url'} ."')\">" . $prdlist->name . "</a><br />";
echo $prdlist->description . "<br />";
$advertiser_name = (($prdlist->{'advertiser-name'})=="")? "N/A" :$prdlist->{'advertiser-name'} ;
$manufacturer_name = (($prdlist->{'manufacturer-name'})=="")? "N/A" : "<a href=\"?manu=". urlencode($prdlist->{'manufacturer-name'})."\">".$prdlist->{'manufacturer-name'}."</a>" ;
echo "sole by " . $advertiser_name .", manufactured by " . $manufacturer_name ."<br />" ;
echo "price ". $prdlist->currency . $prdlist->price ."<br />";
echo "<hr /><br />";
}
//Page Navigator Likes Google
//By EThaiZone http://www.thaiseoboard.com/index.php?topic=23894.0
//Current Page
//$page = //moved to top of code
//Total Pages
$all = (int)ceil ( $pxml->products['total-matched'] / $amount_link_page );
if ( $all > 1000 ) $all = 1000; // is 1000 maximum?
//Amount of link's page
//$amount_link_page = // moved top of code
#########################
if($page > 1) {
if($page == 2)
$nav = " <a href=\"".$_SERVER['PHP_SELF']."\">[Previous]</a> ";
else
$nav = " <a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">[Previous]</a> ";
}
$show = empty($amount_link_page) ? $all : $amount_link_page;
$start = ($page <= $show) ? 1 : $page-$show;
$end = (($all-$page)<$show ? $all+1 : $page+$show);
for($i=$start; $i<$end; $i++) {
if($i == 1 && $i!=$page)
$nav .= " <a href=\"".$_SERVER['PHP_SELF']."\">1</a> ";
else if($i!=$page)
$nav .= " <a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
else
$nav .="<b>[".$i."]</b>";
}
if(($all-$page) > 0) {
$nav .= " <a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">[Next]</a> ";
}
#########################
//Show links
echo $nav;
?>
</body>
</html>