-
-
[旧帖]
请教下熟悉淘宝API调用的大神
0.00雪花
-
发表于:
2013-11-17 00:08
3870
-
[旧帖] 请教下熟悉淘宝API调用的大神
0.00雪花
<?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直播授课