|
文档提要淘宝客单品API获取示例操作提示保存以下代码为top.php,测试地址top.phpiid=3303906039,其中iid值可从taobao.items.get或taobao.taobaoke.items.get获取
以下源码不完善,求补充,木有办法了!只能来这里求救!
$appKey,
'method' => 'taobao.taobaoke.items.detail.get',
'format' => 'xml',
'v' => '2.0',
'timestamp' => date('Y-m-d H:i:s'),
'fields' => 'click_url,shop_click_url,seller_credit_score,iid,detail_url,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,auto_repost,approve_status,postage_id,product_id,auction_point,property_alias,item_imgs,prop_imgs,skus,outer_id,is_virtual,is_taobao,is_ex,videos,is_3D,score,volume,one_station,postage_id',
'num_iids' => $iid,
'nick' => $usernick,
);
//生成签名
$sign = createSign($paramArr);
//组织参数
$strParam = createStrParam($paramArr);
$strParam .= 'sign='.$sign;
//访问服务
$url = 'http://gw.api.taobao.com/router/rest'.$strParam;
$result = file_get_contents($url);
$result = getXmlData($result); $titles = $result ['taobaoke_item_details']['taobaoke_item_detail']['item']['title'];
$click_url = $result ['taobaoke_item_details']['taobaoke_item_detail']['click_url'];
$desc = $result ['taobaoke_item_details']['taobaoke_item_detail']['item']['desc'];
$price = $result ['taobaoke_item_details']['taobaoke_item_detail']['item']['price'];
$pic_url = $result ['taobaoke_item_details']['taobaoke_item_detail']['item']['pic_url']; echo "商品标题:".$titles."
";
echo "商品图片:".$pic_url."
";
echo "推广链接:".$click_url."
";
echo "商品价格:".$price."
";
echo "商品详情:".$desc."
";//签名函数
function createSign ($paramArr) {
global $appSecret;
$sign = $appSecret;
ksort($paramArr);
foreach ($paramArr as $key => $val) {
if ($key !='' && $val !='') {
$sign .= $key.$val;
}
}
$sign = strtoupper(md5($sign));
return $sign;
}//组参函数
function createStrParam ($paramArr) {
$strParam = '';
foreach ($paramArr as $key => $val) {
if ($key != '' && $val !='') {
$strParam .= $key.'='.urlencode($val).'&';
}
}
return $strParam;
} //解析xml函数
function getXmlData ($strXml) {
$pos = strpos($strXml, 'xml');
if ($pos) {
$xmlCode=simplexml_load_string($strXml,'SimpleXMLElement', LIBXML_NOCDATA);
$arrayCode=get_object_vars_final($xmlCode);
return $arrayCode ;
} else {
return '';
}
}
function get_object_vars_final($obj){
if(is_object($obj)){
$obj=get_object_vars($obj);
}
if(is_array($obj)){
foreach ($obj as $key=>$value){
$obj[$key]=get_object_vars_final($value);
}
}
return $obj;
}
> |
|