แจกสคริป สำหรับคนทำ CJ ฮะ

เริ่มโดย ohmohm, 25 ตุลาคม 2009, 01:46:53

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

ohmohm

จากกระทู้นี้ http://www.thaiseoboard.com/index.php/topic,84528 เลยหาทางเอามาทำเองบาง และเคยเห็นกระทู้นี้ http://www.thaiseoboard.com/index.php?topic=76620.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($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/>";
//print ( "<pre>" ); print_r( $pxml ); print ( "</pre><br />" );
if ( isset ( $pxml->products->product ) )
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>


pguroo

ขอบคุณครับ ว่าแต่ website id มันเป็นลักษณะยังงัยเหรอครับ
[direct=http://www.indashcardvdplayer.com/]DVD Players [/direct][direct=http://www.projectorlampcheap.com]Cheap projector lamp[/direct][direct=http://www.inkjet-laser.com/]Inkjet printers[/direct][direct=http://www.viziovbr122.co.cc/]VIZIO VBR122 Blu-ray Player[/direct]

HomHuan

ไม่แนะนำวิธีใช้หน่อยเหรอครับ

ohmohm

สคริปหน้าตาไม่คอยสวยอ่ะครับ ต้องเอาไปต่อยอดกันเอาเองนะครับ

website id ไปดูได้จากช่อง Web Site Settings (รูปแทน)
http://forums.thaisem.com/index.php?topic=8179.0

developer key ไปขอได้จากที่นี่ ต้องสัมพันธ์กับ website id ด้วย ( หนึ่งคนมีได้1 developer key ถ้าในสคริป developer key กับ website id ไม่เหมือนไม่สอดคลองกับที่ขอไว้ตอนแรก อาจไม่ได้เงินค่าคอม )
https://api.cj.com/sign_up.cj

อ่าน Terms of Use ก่อนละ ( อาจเจออะไรแปลกๆ เช่นห้ามห่างเกิน 5 pixels )

ที่ foreach คือเนื้อหาสินค้า เอาไปปะในส่วนที่เป็นเนื้อหาก็ได้
ตรงล่างสุด echo $nav; คือ navigation page ย้ายเอาไปปะล่างๆ หน่อยก็ได้

IzeSem

#5
ขอบคุณครับ

D-N-A

[direct=http://www.tarad2u.net ]ลงประกาศฟรี[/direct]
tarad2u
[direct=http://www.thaipet2u.com]ตลาดซื้อขายสัตว์เลี้ยง[/direct]
thaipet2u
[direct=http://www.talad-pra.com]ตลาดพระเครื่อง[/direct]
พระเครื่อง
[direct=http://www.buycar4u.com]ซื้อขายรถยนต์มือสอง[/direct]
buycar4u
[direct=http://www.bike2hand.net]ตลาดมอเตอร์ไซค์ [/direct]
bike2hand

ขาย youtube แชนแนล พระเครื่อง 70k follow ทำเงินได้หลายทาง
T.086-9165783,line:taladpra

adsene5438

ขอบคุณคับ เก่งจังเลยครับ 55555555555555555555

Luckyz

ขอบคุณค่ะ ไปลองสมัครดูแล้วค่ะ
โอ้ววว  CJ developer key ยาวประมาณ 1 กม.  :wanwan021:
[direct=http://www.web-pra.com/Shop/GoodLuckAmulet]ร้านนะโม โคราช[/direct]
[direct=https://www.youtube.com/channel/UCxMer0SVddC3-tjMJnJEtkw] บ้านแสนสุข LovePopeBell [/direct]

ohmohm

#9
รู้สึกผมจะลืมตรวจว่า $pxml->products->product ใน foreach ( $pxml->products->product as $prdlist ) มันมีให้ใช้หรือเปล่า http://www.thaiseoboard.com/index.php?topic=77888.0 ดัดแปลงโค้ดกันหน่อยนะครับ ใส่ if ( isset ( $pxml->products->product ) ) ก่อน foreach
(แก้ที่ตรงแจกโค้ดแล้วครับ)