宇宙主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

欧基零壹微头条IP归属甄别会员请立即修改密码
查看: 3260|回复: 2

php淘宝客api单品例子,求解

[复制链接]
发表于 2012-12-27 21:14:35 | 显示全部楼层 |阅读模式
文档提要淘宝客单品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;
    }
    >
发表于 2013-1-5 21:20:38 | 显示全部楼层
太乱了 没心情看下去。。
发表于 2013-1-10 17:37:50 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|宇宙主机交流论坛

GMT+8, 2024-10-31 19:18 , Processed in 0.057976 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表