淘宝客如何根据关键字显示对应的商品

作者:     目录: 赚美元     发表: 2021年07月06日

在网站上调用淘宝客api,根据关键字自动生成对应的产品信息,显示效果如下:

淘宝客如何根据关键字显示对应的商品

具体代码如下:

include “taoke/TopSdk.php”;

<?php
//get alimama
$c = new TopClient;
$c->appkey = ‘改成你自己的’;
$c->secretKey = ‘改成你自己的’;

$req = new TbkDgMaterialOptionalRequest;
$req->setPageSize(“4”);
$req->setSort(“total_sales”);
$req->setQ($post_keyword);
$req->setAdzoneId(“110900750278”);
$req->setIncludePayRate30(“true”);
$req->setIncludeGoodRate(“true”);
$req->setIncludeRfdRate(“true”);
$resp= $c->execute($req);

$resp=json_decode(json_encode($resp), true);
$resp=$resp[‘result_list’][‘map_data’];
$num=count($resp);

if($num>0){
echo “<div class=’tb’>”;
echo ‘<div style=”text-align:center; color:#00f; padding:0 0 5px 0; font-size:30px; line-height:180%;”>—– 相关产品报价 —– </div>’;
for ($i=0; $i<$num; $i++){
$resp_item=$resp[$i];
$title=$resp_item[‘title’];
$url=$resp_item[‘url’];
$pict_url=$resp_item[‘pict_url’];
$zk_final_price=$resp_item[‘zk_final_price’];
if($title<>””){
echo “<div class=’tb_item’ id=’tb_”.$i.”‘>”;
echo “<a href='”.$url.”‘ target=’_blank’ title='”.$title.”‘>”;
echo “<img src='”.$pict_url.”‘ alt='”.$title.”‘ />”;
echo “<span class=’tb_title’>”.$title.”</span>”;
echo “<span class=’tb_info’>实时价 ¥”.$zk_final_price.”</span>”;
echo “</a></div>”;
}
}
echo “</div>”;
}
?>

Post Comment

Your email address will not be published. Required fields are marked *