首页
社区
课程
招聘
[旧帖] 请教下熟悉淘宝API调用的大神 0.00雪花
发表于: 2013-11-17 00:08 3870

[旧帖] 请教下熟悉淘宝API调用的大神 0.00雪花

2013-11-17 00:08
3870
<?php

include './../../include/admincommon.inc.php';
include("./../../top/topclient.php"); //这里是引用tae的topclient
include("./../../top/ItemGetRequest.php"); //这里是引用具体的Request类


$currentPage='goods_create';
//获取站点配置信息
$siteConfig = false;//$cacheService->get('siteConfig');
if ($siteConfig)
{
    $appkey = $siteConfig['appkey'];
    $secretKey = $siteConfig['secretKey'];
}
else if (!$siteConfig)
{
    $res = rGetSiteConfig();
    $appkey = $res['appkey'];
    $secretKey = $res['secretKey'];
}
$promotePositionArr = rGetPromotePositionArr('goods');
$categoryArr = rGetCategoryArr();
$pindaoArr = rGetPindaoArr();
$dopost = isset($_POST['dopost']) ? $_POST['dopost'] : '';
$numIid = isset($_POST['numIid']) ? trim($_POST['numIid']) : ''; //提交过来的num_iid
$createMessage = '';

if ($dopost == 'caiji')
{
    if ($numIid != "" && rRuleNum($numIid))
    {
        $c = new TopClient;
        $c->appkey = $appkey;     //top appkey
        $c->secretKey = $secretKey;  //top secretkey
        //实例化具体API对应的Request类
        $req = new ItemGetRequest();      //top 封装的php文件
        $req->setFields("num_iid,title,pic_url,detail_url,price,num,nick,freight_payer");
        $req->setNumIid($numIid);
        $resp = $c->execute($req);


        if ($resp->item)
        {
            $detail_url = $resp->item->detail_url;   //商品链接
            $num_iid = $resp->item->num_iid;        //商品ID
            $title = $resp->item->title;           //商品标题
            $nick = $resp->item->nick;            //卖家昵称
            $pic_url = $resp->item->pic_url;      //商品主图
            $num = $resp->item->num;            //商品数量
            $price = $resp->item->price;       //商品原价格
         [COLOR="Red"]   $coupon_price = $resp->item->coupon_price;   //商品现价格 [/COLOR]


            $freight_payer = $resp->item->freight_payer;       
        }else
            $createMessage = '不存在这个商品';
        //print_r($resp);
    }
    else
    {
        $createMessage = "商品ID【不能为空】并且【必须是数字】。";
    }
}

if ($dopost == 'create')
{
    $categoryId = intval($_POST["categoryId"]);
    $num_iid = $_POST["num_iid"];
    $num = intval($_POST["num"]);
    $detail_url = $_POST["detail_url"];
    $title = $_POST["title"];
    $pic_url = $_POST["pic_url"];
    $create_time = time();
    $begin_time = strtotime($_POST["begin_time"]);
    $end_time = strtotime($_POST["end_time"]);
    $price = $_POST["price"];
    $coupon_price = $_POST["coupon_price"];
    $freight_payer = $_POST['freight_payer'];
    $promote_id = intval($_POST['promote_id']);
    $pindao_id = intval($_POST['pindao_id']);
    $description = $_POST['description']; //过滤内容
    $nick = $_POST['nick'];
 

    if ($num_iid == "" || $detail_url == "" || $title == "" || $pic_url == "" || $price == "" $coupon_price == "")
    {
        $createMessage = "请把商品信息填写完整,星号为必填项!!";
    }
    else
    {

        $sql = 'SELECT * FROM `goods` WHERE `num_iid`="' . $num_iid . '" OR `title`="' . $title . '"';
        $rs = $pdo->query($sql);
        $row = $rs->fetchAll(); //取得所有记录
        if (count($row) == 0)
        {
            if (rRuleUrl($detail_url) && rRuleNum($num_iid) && rRulePrice($price) && rRulePrice($coupon_price))
            {
                $datetime = date("Y-m-d H:i:s");
                $sql = 'INSERT INTO `goods` SET 
`num_iid`="' . $num_iid . '", 
`title`="' . $title .'", 
`pic_url`="' . $pic_url . '",
`detail_url`="' . $detail_url .'", 
`price`="' . $price .'", 
`coupon_price`="' . $coupon_price .'", 
`num`="' . $num . '", 
`create_time`="' . $create_time .'", 
`description`="' . $description . '", 
`category_id`="' . $categoryId .'", 
`end_time`="' . $end_time . '", 
`promote_id`="' . $promote_id . '",
`freight_payer`="' . $freight_payer .'", 
`nick`="' . $nick . '", 
`begin_time`="' . $begin_time . '", `pindao_id`="' . $pindao_id . '"';

                $count = $pdo->exec($sql);

                if ($count > 0)
                {
                    $createMessage = "新增成功";
                }
                else
                {
                    echo $sql;
                    $createMessage = "添加失败";
                }
            }
            else
            {
                if (!rRuleUrl($detail_url))
                    $createMessage.='商品链接url填写不规范,带http://模式<br>';
                elseif (!rRuleNum($num_iid))
                    $createMessage.='商品id填写不规范,数字模式<br>';
                elseif (!rRulePrice($price))
                    $createMessage.='商品价格填写不规范,小数模式:10.00<br>';
              elseif (!rRulePrice($coupon_price))
                    $createMessage.='商品价格填写不规范,小数模式:10.00<br>';
            }
        }
        else
        {
            $createMessage = "【商品id】或者【标题】重复!!";
        }
    }
}



[LEFT]代码红色部分:
这里获取不了 看了下API文档 coupon_price是属于(增值)taobaokeAPI里的一个返回值 而我申请的Appkey没有调用增值API的权限 好像要淘宝客金账户才够申请增值API   这一切只是我的一些试验和猜想 也不知道代码有没问题 因为是下载别人的源码 有大神知道详情的请指一下这里面的问题 能提供高权限Appkey就更好了
[/LEFT]

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 41
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
首先你得熟悉了解你做的那块。给你个网址参照 http://www.taoapi.com/  然后下载淘宝API SDK文件导入你的php项目下,然后根据淘宝API使用手册,看调用你所需要的API需要哪些参数,然后再你得php文件中加载你所要用到的SDK文件 就可以直接使用了。<object width="450" height="500" align="middle" id="reader" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="window" name="wmode"><param value="true" name="allowfullscreen"><param name="allowscriptaccess" value="always"><param value="http://wenku.baidu.com/static/flash/txtreader.swf?docurl=http://wenku.baidu.com/play&docid=422cbbf59e31433239689364&title=%E6%B7%98%E5%AE%9Dapi%E8%B0%83%E7%94%A8%E6%AD%A5%E9%AA%A4&doctype=txt&fpn=50&npn=50&readertype=external&catal=0&cdnurl=http://txt.wenku.baidu.com/play" name="movie"><embed width="450" align="middle" height="500" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="reader" src="http://wenku.baidu.com/static/flash/txtreader.swf?docurl=http://wenku.baidu.com/play&docid=422cbbf59e31433239689364&title=%E6%B7%98%E5%AE%9Dapi%E8%B0%83%E7%94%A8%E6%AD%A5%E9%AA%A4&doctype=txt&fpn=50&npn=50&readertype=external&catal=0&cdnurl=http://txt.wenku.baidu.com/play" wmode="window" allowscriptaccess="always" bgcolor="#FFFFFF" ver="9.0.0" allowfullscreen="true"></embed></object>不知这样可不可以帮到你?
2013-11-21 17:59
0
游客
登录 | 注册 方可回帖
返回
//