Author Topic: แจกสคริป สำหรับคนทำ CJ ฮะ  (Read 2041 times)

0 Members and 1 Guest are viewing this topic.

Offline ohmohm

  • นิสิตรุ่นใหญ่
  • ****
  • Posts: 185
  • Thanks! : 9
  • Taj Mahal
    • ลงประกาศฟรี
จากกระทู้นี้-http://www.thaiseoboard.com/index.php/topic,84528 เลยหาทางเอามาทำเองบาง และเคยเห็นกระทู้นี้ http://forums.sem.or.th/index.php?topic=20315.0 ( ความรู้เป็นของมนุษยชาติ ) เลยแจกมั่งดีกว่า
Code: [Select]
<?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($chCURLOPT_URL$url);
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse); 
curl_setopt($chCURLOPT_POSTFALSE);
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
curl_setopt($chCURLOPT_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) ? $page-$show;
$end = (($all-$page)<$show $all+$page+$show);

for($i=$start$i<$end$i++) {
if($i == && $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>


Offline melodica

  • อาสาสมัครเสียว
  • ปรมาจารย์
  • *****
  • Posts: 515
  • Thanks! : 16
  • Gender: Male
  • "ทำ" กับ "ไม่ทำ" ก็เท่าั้นั้นเอง
Re: แจกสคริป สำหรับคนทำ CJ ฮะ
« Reply #2 on: October 25, 2009, 01:41:34 PM »
+1 เก็บไว้ก่อน
ขอบคุณครับ
 :wanwan017:
จากกระทู้นี้-http://www.thaiseoboard.com/index.php/topic,84528 เลยหาทางเอามาทำเองบาง และเคยเห็นกระทู้นี้ http://forums.sem.or.th/index.php?topic=20315.0 ( ความรู้เป็นของมนุษยชาติ ) เลยแจกมั่งดีกว่า
Code: [Select]
<?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($chCURLOPT_URL$url);
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse); 
curl_setopt($chCURLOPT_POSTFALSE);
curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);
curl_setopt($chCURLOPT_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) ? $page-$show;
$end = (($all-$page)<$show $all+$page+$show);

for($i=$start$i<$end$i++) {
if($i == && $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>

« Last Edit: January 08, 2010, 05:16:18 PM by melodica »



Offline IzeSem

  • นิสิตรุ่นใหญ่
  • ****
  • Posts: 194
  • Thanks! : 2
    • Share Tour Thai
Re: แจกสคริป สำหรับคนทำ CJ ฮะ
« Reply #5 on: October 25, 2009, 03:43:18 PM »
ขอบคุณครับ

Offline phong

  • ปรมาจารย์
  • *****
  • Posts: 366
  • Thanks! : 1
  • Gender: Male
    • Email
Re: แจกสคริป สำหรับคนทำ CJ ฮะ
« Reply #6 on: October 25, 2009, 08:49:14 PM »
แหล่มเลย น่าจะมีประโยชน์สำหรับคนทำ cj เก็บไว้ก่อน ขอบคุณคร้าบ


Offline subaru

  • ปรมาจารย์
  • *****
  • Posts: 369
  • Thanks! : 11
  • Gender: Male
  • I Love Amazon
    • Cheap iPod
Re: แจกสคริป สำหรับคนทำ CJ ฮะ
« Reply #8 on: October 26, 2009, 11:21:04 AM »
ขอบคุณจ้า ขอเอาไปศึกษาหน่อย

Offline In4Dex

  • ประถมศึกษา
  • **
  • Posts: 53
  • Thanks! : 0
  • www.Theidealize.com ให้หมดใจ
    • www.theidealize.com
    • Email
Re: แจกสคริป สำหรับคนทำ CJ ฮะ
« Reply #9 on: October 26, 2009, 11:58:58 AM »
โอโหหห ไม่รู้จะขอบคุณยังไงดีแล้วค่ะ  :wanwan017:

กับ api ของ cj พยายามเขียนเอง ตามหาเองบ้าง  แต่ทำไม่เคยได้เลย

จากใจจริง  ขอบคุณมากค่ะ  :wanwan017:

Offline uhuh

  • ประถมศึกษา
  • **
  • Posts: 60
  • Thanks! : 0
    • Email
Re: แจกสคริป สำหรับคนทำ CJ ฮะ
« Reply #10 on: October 29, 2009, 10:04:51 AM »
$website_id = "your web id here"  คืออะไรครับผม

Offline pinoccio

  • ประถมศึกษา
  • **
  • Posts: 41
  • Thanks! : 0
  • มือใหม่ SEM
    • บริการรับฝากซื้อขอ ebay และเว็บอื่นๆ
Re: แจกสคริป สำหรับคนทำ CJ ฮะ
« Reply #11 on: October 29, 2009, 11:08:19 AM »
ใช้ไม่เป็นอ่าครับ แต่ก็ขอบคุณครับ :wanwan017:

Offline ping-cp30

  • นิสิตรุ่นใหญ่
  • ****
  • Posts: 181
  • Thanks! : 2
  • Gender: Male
  • สู้โว้ยยยยยย
    • ShoppingLovely
Re: แจกสคริป สำหรับคนทำ CJ ฮะ
« Reply #12 on: October 29, 2009, 11:32:35 AM »
โอ้ว cj api เหรอเนี่ย
ขอบคุณมากครับ เด่วลองเล่นดู :wanwan034: