public function collectShopCates() { setTimeLimit(3600); global $_FANWE; include_once FANWE_ROOT . 'sdks/taobao/TopClient.php'; include_once FANWE_ROOT . 'sdks/taobao/request/ShopcatsListGetRequest.php'; Cache::getInstance()->loadCache('business'); $sort_file = FANWE_ROOT . '/public/records/cate.sort.php'; $sort = (int) @file_get_contents($sort_file); $client = new TopClient(); $client->appkey = trim($_FANWE['cache']['business']['taobao']['app_key']); $client->secretKey = trim($_FANWE['cache']['business']['taobao']['app_secret']); $req = new ShopcatsListGetRequest(); $req->setFields("cid,parent_cid,name,is_parent"); $resp = $client->execute($req); $sort = 0; if (isset($resp->shop_cats) && isset($resp->shop_cats->shop_cat)) { foreach ($resp->shop_cats->shop_cat as $item) { $item = (array) $item; $cate = array(); $cate['type'] = 'taobao'; $cate['id'] = $item['cid']; $cate['pid'] = $item['parent_cid'] == 0 ? '' : $item['parent_cid']; $cate['name'] = $item['name']; $cate['pids'] = ''; $cate['sort'] = ++$sort; FDB::insert('shop_cates', $cate, false, true); } } return true; }
/** * 获取前台显示的店铺类目 * * @return array */ public function ShopCatesList() { require_once 'Request/ShopcatsListGetRequest.php'; $req = new ShopcatsListGetRequest(); $req->setFields("cid,parent_cid,name,is_parent"); $resp = $this->_topClient->execute($req); return is_array($resp) && isset($resp['shop_cats']['shop_cat']) ? $resp['shop_cats']['shop_cat'] : array(); }
function xt_taobao_shopcats_list($fields = 'cid,parent_cid,name,is_parent') { $app = xt_taobao_is_ready(); if (!$app) { return new WP_Error('系统错误', '尚未配置淘宝开放平台!'); } include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/RequestCheckUtil.php'; include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/TopClient.php'; include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/request/ShopcatsListGetRequest.php'; $client = new TopClient(); $client->format = 'json'; $client->appkey = $app['appKey']; $client->secretKey = $app['appSecret']; $req = new ShopcatsListGetRequest(); $req->setFields($fields); $resp = $client->execute($req); if (isset($resp->sub_code)) { return new WP_Error($resp->sub_code > 0 ? $resp->sub_code : '500', $resp->sub_msg); } elseif (isset($resp->code)) { return new WP_Error($resp->code > 0 ? $resp->code : '500', $resp->msg); } if (isset($resp->shop_cats) && isset($resp->shop_cats->shop_cat)) { return $resp->shop_cats->shop_cat; } return array(); }