|
|
@ -1,4 +1,5 @@ |
|
|
|
<?php |
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1); |
|
|
|
declare(strict_types=1); |
|
|
|
|
|
|
|
|
|
|
|
namespace app\common\service; |
|
|
|
namespace app\common\service; |
|
|
@ -8,7 +9,8 @@ namespace app\common\service; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 京东服务 |
|
|
|
* 京东服务 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class Jd extends BaseService { |
|
|
|
class Jd extends BaseService |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取京东商品库存 |
|
|
|
* 获取京东商品库存 |
|
|
@ -20,7 +22,8 @@ class Jd extends BaseService { |
|
|
|
* @param integer $skuNum [description] |
|
|
|
* @param integer $skuNum [description] |
|
|
|
* @return [type] [description] |
|
|
|
* @return [type] [description] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function getGoodsStock($provinceId, $cityId, $countyId,$skuId, $skuNum = 1){ |
|
|
|
public function getGoodsStock($provinceId, $cityId, $countyId, $skuId, $skuNum = 1) |
|
|
|
|
|
|
|
{ |
|
|
|
$data = [ |
|
|
|
$data = [ |
|
|
|
'provinceId' => $provinceId, |
|
|
|
'provinceId' => $provinceId, |
|
|
|
'cityId' => $cityId, |
|
|
|
'cityId' => $cityId, |
|
|
@ -33,18 +36,18 @@ class Jd extends BaseService { |
|
|
|
//exit(); |
|
|
|
//exit(); |
|
|
|
$curl = curl_init(); |
|
|
|
$curl = curl_init(); |
|
|
|
curl_setopt_array($curl, array( |
|
|
|
curl_setopt_array($curl, array( |
|
|
|
CURLOPT_URL => 'https://vapi.jd.com/index/sku/getAsynDetail?'.http_build_query($data), |
|
|
|
CURLOPT_URL => 'https://vapi.jd.com/index/sku/getAsynDetail?' . http_build_query($data), |
|
|
|
CURLOPT_RETURNTRANSFER => true, |
|
|
|
CURLOPT_RETURNTRANSFER => true, |
|
|
|
CURLOPT_ENCODING => '', |
|
|
|
CURLOPT_ENCODING => '', |
|
|
|
CURLOPT_MAXREDIRS => 10, |
|
|
|
CURLOPT_MAXREDIRS => 10, |
|
|
|
CURLOPT_TIMEOUT => 0, |
|
|
|
CURLOPT_TIMEOUT => 0, |
|
|
|
CURLOPT_FOLLOWLOCATION => true, |
|
|
|
CURLOPT_FOLLOWLOCATION => true, |
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
|
|
|
CURLOPT_CUSTOMREQUEST => 'GET', |
|
|
|
CURLOPT_CUSTOMREQUEST => 'GET', |
|
|
|
CURLOPT_HTTPHEADER => array( |
|
|
|
CURLOPT_HTTPHEADER => array( |
|
|
|
'Host: vapi.jd.com', |
|
|
|
'Host: vapi.jd.com', |
|
|
|
'Referer: https://bpro.jd.com/' |
|
|
|
'Referer: https://bpro.jd.com/' |
|
|
|
), |
|
|
|
), |
|
|
|
)); |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($curl); |
|
|
|
$response = curl_exec($curl); |
|
|
@ -65,9 +68,10 @@ class Jd extends BaseService { |
|
|
|
* @param [type] $skuId [description] |
|
|
|
* @param [type] $skuId [description] |
|
|
|
* @return [type] [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://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); |
|
|
|
$res = httpRequest($url); |
|
|
|
if ($res && $res['code'] == 0 && isset($res['data'])) { |
|
|
|
if ($res && $res['code'] == 0 && isset($res['data'])) { |
|
|
|
return $res['data']; |
|
|
|
return $res['data']; |
|
|
@ -81,9 +85,10 @@ class Jd extends BaseService { |
|
|
|
* @param [type] $skuId [description] |
|
|
|
* @param [type] $skuId [description] |
|
|
|
* @return [type] [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://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); |
|
|
|
$res = httpRequest($url); |
|
|
|
if ($res && $res['code'] == 0 && isset($res['data'])) { |
|
|
|
if ($res && $res['code'] == 0 && isset($res['data'])) { |
|
|
|
return $res['data']; |
|
|
|
return $res['data']; |
|
|
@ -91,13 +96,33 @@ class Jd extends BaseService { |
|
|
|
return ""; |
|
|
|
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 ""; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|