$totalResult = 0; $category_id = isset($_GET['category_id']) ? $_GET['category_id'] : 0; $pindao_id = isset($_GET['pindao_id']) ? $_GET['pindao_id'] : 0; $sort = isset($_GET['sort']) ? $_GET['sort'] : 'default'; $goodsArr = array(); $days = isset($_GET['days']) ? $_GET['days'] : 7; $begin_date = isset($_GET['begin_date']) ? $_GET['begin_date'] : date("Y-m-d H:i:s", time()); if ($dopost == 'caiji') { if ($search_word != "") { $c = new TopClient(); $c->appkey = $appkey; //top appkey $c->secretKey = $secretKey; //top secretkey //实例化具体API对应的Request类 $req = new TaobaokeItemsCouponGetRequest(); $req->setFields("num_iid,title,pic_url,price,click_url,commission,commission_rate,volume,coupon_price,coupon_rate,coupon_start_time,coupon_end_time,shop_type"); $req->setKeyword($search_word); $req->setPageNo($page); $req->setSort($sort); $req->setPageSize($pageSize); $req->setStartCredit($start_credit); $req->setEndCredit($end_credit); $req->setStartCommissionRate($start_com_rate); $req->setEndCommissionRate($end_com_rate); $req->setShopType($shop_type); $req->setStartCouponRate($start_coupon_rate); $req->setEndCouponRate($end_coupon_rate); $resp = $c->execute($req); if (isset($resp->taobaoke_items) && isset($resp->total_results) && $resp->total_results > 0) { $goodsItems = $resp->taobaoke_items->taobaoke_item;
function xt_taobaoke_items_coupon_search($params) { $app = xt_taobao_is_ready(); if (!$app) { return new WP_Error('系统错误', '尚未配置淘宝开放平台!'); } $params = _xt_taobaoke_items_coupon_search_params($params); if (empty($params['keyword']) && (empty($params['cid']) || intval($params['cid']) == 0)) { 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/TaobaokeItemsCouponGetRequest.php'; $client = new TopClient(); $client->format = 'json'; $client->appkey = $app['appKey']; $client->secretKey = $app['appSecret']; $req = new TaobaokeItemsCouponGetRequest(); $req->setFields($params['fields']); $req->setCouponType(1); if (empty($params['keyword']) && empty($params['cid'])) { $params['cid'] = 16; } if (!empty($params['keyword'])) { $req->setKeyword($params['keyword']); } if (!empty($params['cid']) && intval($params['cid']) > 0) { $req->setCid(intval($params['cid'])); } if (!empty($params['shop_type'])) { $req->setShopType($params['shop_type']); } if (!empty($params['start_coupon_rate']) && intval($params['start_coupon_rate']) > 0) { $req->setStartCouponRate($params['start_coupon_rate']); } if (!empty($params['end_coupon_rate']) && intval($params['end_coupon_rate']) > 0) { $req->setEndCouponRate($params['end_coupon_rate']); } if (!empty($params['sort'])) { $req->setSort($params['sort']); } if (!empty($params['start_credit'])) { $req->setStartCredit($params['start_credit']); } if (!empty($params['end_credit'])) { $req->setEndCredit($params['end_credit']); } if (!empty($params['start_commissionRate']) && intval($params['start_commissionRate']) > 0) { $req->setStartCommissionRate($params['start_commissionRate']); } if (!empty($params['end_commissionRate']) && intval($params['end_commissionRate']) > 0) { $req->setEndCommissionRate($params['end_commissionRate']); } if (!empty($params['page_no'])) { $req->setPageNo(intval($params['page_no'])); } if (!empty($params['page_size'])) { $req->setPageSize(intval($params['page_size'])); } $req->setOuterCode(xt_outercode()); $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); } return $resp; }