diff --git a/app/common/service/Jd.php b/app/common/service/Jd.php index 7367ddab..1c16d490 100644 --- a/app/common/service/Jd.php +++ b/app/common/service/Jd.php @@ -1,4 +1,5 @@ $provinceId, 'cityId' => $cityId, @@ -33,18 +36,18 @@ class Jd extends BaseService { //exit(); $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://vapi.jd.com/index/sku/getAsynDetail?'.http_build_query($data), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_HTTPHEADER => array( - 'Host: vapi.jd.com', - 'Referer: https://bpro.jd.com/' - ), + CURLOPT_URL => 'https://vapi.jd.com/index/sku/getAsynDetail?' . http_build_query($data), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Host: vapi.jd.com', + 'Referer: https://bpro.jd.com/' + ), )); $response = curl_exec($curl); @@ -65,9 +68,10 @@ class Jd extends BaseService { * @param [type] $skuId [description] * @return [type] [description] */ - public function getGoodsMainImageAndDetail($skuId){ + public function getGoodsMainImageAndDetail($skuId) + { //$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId="; - $url = "http://8.130.98.31:8811/api/goods/info/v2?sku=".$skuId."&areaId="; + $url = "http://8.130.98.31:8811/api/goods/info/v2?sku=" . $skuId . "&areaId="; $res = httpRequest($url); if ($res && $res['code'] == 0 && isset($res['data'])) { return $res['data']; @@ -81,9 +85,10 @@ class Jd extends BaseService { * @param [type] $skuId [description] * @return [type] [description] */ - public function getJdShortLink($skuId){ + public function getJdShortLink($skuId) + { //$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId="; - $url = "http://8.130.98.31:8811/api/link?sku=".$skuId; + $url = "http://8.130.98.31:8811/api/link?sku=" . $skuId; $res = httpRequest($url); if ($res && $res['code'] == 0 && isset($res['data'])) { return $res['data']; @@ -91,13 +96,33 @@ class Jd extends BaseService { return ""; } + /** + * 获取京东短链接 + * [getJdShortLink description] + * @param [type] $skuId [description] + * @return [type] [description] + */ + public function getJdShortLinks($skuData) + { + //$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId="; + // 确保 $skuData 是一个数组,并且包含 'ids' 键 + if (is_array($skuData) && isset($skuData['goods_on']) && is_array($skuData['goods_on'])) { + $skuIds = $skuData['goods_on']; + } else { + // 如果传入的不是一个有效的数组,返回错误信息或抛出异常 + return "无效的输入数据"; + } + // 将数组转换为逗号分隔的字符串 + $skuIdStr = implode(',', $skuIds); + // 构建 URL + $url = "http://8.130.98.31:8811/api/link?sku=" . urlencode($skuIdStr); - - - - - - + $res = httpRequest($url); + if ($res && $res['code'] == 0 && isset($res['data'])) { + return $res['data']; + } + return ""; + } } diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 22d64f04..2af11818 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -627,4 +627,19 @@ class Goods extends Controller return $this->renderSuccess('操作成功'); } + + public function selectSku() + { + $model = new jd(); + $list = $model->getJdShortLinks($this->postForm()); + return $this->renderSuccess(compact('list')); + + } + + public function JDShortLinks() + { + $detail = ModelTipoff::where('id',$this->request->param('id'))->select()->toArry(); + $JdModel = new jd(); + } + }