es
parent
28ebfe0c63
commit
70b8c8c871
@ -0,0 +1,58 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
|
||||
namespace app\common\service; |
||||
|
||||
|
||||
|
||||
/** |
||||
* 京东服务 |
||||
*/ |
||||
class Jd extends BaseService { |
||||
/** |
||||
* 获取京东商品库存 |
||||
* [getGoodsStock description] |
||||
* @param [type] $provinceId [description] |
||||
* @param [type] $cityId [description] |
||||
* @param [type] $countyId [description] |
||||
* @param [type] $skuId [description] |
||||
* @param integer $skuNum [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function getGoodsStock($provinceId, $cityId, $countyId,$skuId, $skuNum = 1){ |
||||
$data = [ |
||||
'provinceId' => $provinceId, |
||||
'cityId' => $cityId, |
||||
'countyId' => $countyId, |
||||
'townId' => 0, |
||||
'skuId' => $skuId, |
||||
'skuNum' => $skuNum, |
||||
]; |
||||
//echo 'https://vapi.jd.com/index/sku/getAsynDetail?'.http_build_query($data); |
||||
//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/' |
||||
), |
||||
)); |
||||
|
||||
$response = curl_exec($curl); |
||||
|
||||
curl_close($curl); |
||||
$res = json_decode($response, true); |
||||
if ($res && isset($res['success']) && $res['success'] == 1) { |
||||
return $res['result']; |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,241 @@ |
||||
<?php |
||||
declare(strict_types=1); |
||||
namespace app\common\service; |
||||
|
||||
|
||||
require_once(root_path() .'/extend/suning-sdk-php/SuningSdk.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/DefaultSuningClient.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/itemDetailQueryRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/custom/IsvitemlistQueryRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ProdpoolQueryRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ProdbasicdetailGetRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ProddetailGetRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ProdimageQueryRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/PasspartproductinfoQueryRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/FulladdressGetRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ListpagepriceQueryRequest.php'); |
||||
require_once(root_path() .'/extend/suning-sdk-php/request/sngoods/ShoppingcartpriceQueryRequest.php'); |
||||
|
||||
/** |
||||
* 苏宁服务 |
||||
*/ |
||||
class Suning extends BaseService { |
||||
|
||||
private $_domain = "https://open.suning.com/api/http/sopRequest"; |
||||
private $_app_key = "ea13e4bb325235bfbd39927dbc32cbbd"; |
||||
private $_app_secrect = "b4b797916f4cf211e4c043603f3d8139"; |
||||
private $_channel_code = 84; |
||||
private $_client = null; |
||||
|
||||
|
||||
public function __construct($config = array()){ |
||||
$this->_domain = $config['domain'] ?? $this->_domain; |
||||
$this->_app_key = $config['app_key'] ?? $this->_app_key; |
||||
$this->_app_secrect = $config['app_secrect'] ?? $this->_app_secrect; |
||||
$this->_channel_code = $config['channel_code'] ?? $this->_channel_code; |
||||
$this->_client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); |
||||
} |
||||
/** |
||||
* 商品池 |
||||
* [goodsPoolQuery description] |
||||
* @param [type] $page [description] |
||||
* @param [type] $limit [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function goodsPoolQuery($page, $limit){ |
||||
$req = new \ProdpoolQueryRequest(); |
||||
$req -> setChannelCode($this->_channel_code); |
||||
$req -> setPageNo($page); |
||||
$req -> setPageSize($limit); |
||||
//$req -> setStartTime("2024-01-11 01:01:01"); |
||||
//$req -> setEndTime("2022-01-11 23:59:59"); |
||||
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 |
||||
$resp = $this->_client->execute($req); |
||||
$data = json_decode($resp, true); |
||||
// echo "<pre>"; |
||||
// print_r($data); |
||||
if (isset($data['sn_responseContent']['sn_body']['queryProdpool']) && $data['sn_responseContent']['sn_body']['queryProdpool']) { |
||||
return $data['sn_responseContent']['sn_body']['queryProdpool']; |
||||
} |
||||
return []; |
||||
} |
||||
/** |
||||
* 商品基本信息 |
||||
* [goodsPoolQuery description] |
||||
* @param [type] $supplier_code [description] |
||||
* @param [type] $sku_id [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function goodsBasicInfo($supplier_code, $sku_id){ |
||||
$req = new \ProdbasicdetailGetRequest(); |
||||
$req -> setSkuId($sku_id); |
||||
$req -> setSupplierCode($supplier_code); |
||||
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 |
||||
$resp = $this->_client->execute($req); |
||||
$data = json_decode($resp, true); |
||||
// echo "<pre>"; |
||||
// print_r($data); |
||||
// exit(); |
||||
if (isset($data['sn_responseContent']['sn_body']['getProdbasicdetail']) && $data['sn_responseContent']['sn_body']['getProdbasicdetail']) { |
||||
return $data['sn_responseContent']['sn_body']['getProdbasicdetail']; |
||||
} |
||||
return []; |
||||
} |
||||
|
||||
/** |
||||
* 商品详细信息 |
||||
* [goodsPoolQuery description] |
||||
* @param [type] $supplier_code [description] |
||||
* @param [type] $sku_id [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function goodsDetail($supplier_code, $sku_id){ |
||||
$req = new \ProddetailGetRequest(); |
||||
$req -> setSkuId($sku_id); |
||||
$req -> setSupplierCode($supplier_code); |
||||
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 |
||||
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); |
||||
$resp = $this->_client->execute($req); |
||||
$data = json_decode($resp, true); |
||||
// echo "<pre>"; |
||||
// print_r($data); |
||||
// exit(); |
||||
if (isset($data['sn_responseContent']['sn_body']['getProddetail']) && $data['sn_responseContent']['sn_body']['getProddetail']) { |
||||
return $data['sn_responseContent']['sn_body']['getProddetail']; |
||||
} |
||||
return []; |
||||
} |
||||
/** |
||||
* 商品详细信息 |
||||
* [goodsPoolQuery description] |
||||
* @param [type] $supplier_code [description] |
||||
* @param [type] $sku_id [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function goodsImage($supplier_code, $sku_id){ |
||||
$req = new \ProdimageQueryRequest(); |
||||
$req -> setSkuId($sku_id); |
||||
$req -> setSupplierCode($supplier_code); |
||||
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 |
||||
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); |
||||
$resp = $this->_client->execute($req); |
||||
$data = json_decode($resp, true); |
||||
// echo "<pre>"; |
||||
// print_r($data); |
||||
// exit(); |
||||
if (isset($data['sn_responseContent']['sn_body']['queryProdimage']) && $data['sn_responseContent']['sn_body']['queryProdimage']) { |
||||
return $data['sn_responseContent']['sn_body']['queryProdimage']; |
||||
} |
||||
return []; |
||||
} |
||||
/** |
||||
* 获取通子码商品信息接口 |
||||
* [passpartproductinfo description] |
||||
* @param [type] $supplier_code [description] |
||||
* @param string $spu_id [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function passpartproductinfo($supplier_code, $spu_id = ""){ |
||||
$req = new \PasspartproductinfoQueryRequest(); |
||||
$req -> setSpuId($spu_id); |
||||
$req -> setSupplierCode($supplier_code); |
||||
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 |
||||
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); |
||||
$resp = $this->_client->execute($req); |
||||
$data = json_decode($resp, true); |
||||
echo "<pre>"; |
||||
print_r($data); |
||||
//exit(); |
||||
if (isset($data['sn_responseContent']['sn_body']['queryProdimage']) && $data['sn_responseContent']['sn_body']['queryProdimage']) { |
||||
return $data['sn_responseContent']['sn_body']['queryProdimage']; |
||||
} |
||||
return []; |
||||
} |
||||
/** |
||||
* 列表页城市维度查询价格及库存状态 |
||||
* [passpartproductinfo description] |
||||
* @param [type] $supplier_code [description] |
||||
* @param string $spu_id [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function listPagePrice($skus, $city_code = "025"){ |
||||
$req = new \ListpagepriceQueryRequest(); |
||||
$req -> setChannelCode($this->_channel_code); |
||||
$req -> setCityCode("025"); |
||||
$arr = []; |
||||
foreach ($skus as &$sku) { |
||||
list($channel, $supplier_code, $sku_id) = explode("-", $sku['unicode']); |
||||
$cmmdtyInfoList= new \CmmdtyInfoList(); |
||||
$cmmdtyInfoList->setSkuId($sku_id); |
||||
$cmmdtyInfoList->setSupplierCode($supplier_code); |
||||
$arr[] = $cmmdtyInfoList; |
||||
} |
||||
|
||||
$req -> setCmmdtyInfoList($arr); |
||||
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 |
||||
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); |
||||
$resp = $this->_client->execute($req); |
||||
$data = json_decode($resp, true); |
||||
// echo "<pre>"; |
||||
// print_r($data); |
||||
// exit(); |
||||
if (isset($data['sn_responseContent']['sn_body']['queryListpageprice']['data']) && $data['sn_responseContent']['sn_body']['queryListpageprice']['data']) { |
||||
return $data['sn_responseContent']['sn_body']['queryListpageprice']['data']; |
||||
} |
||||
return []; |
||||
} |
||||
/** |
||||
* 确定到省市区纬度且有明确购买数量的场景查询价格及库存状态 |
||||
* [passpartproductinfo description] |
||||
* @param [type] $supplier_code [description] |
||||
* @param string $spu_id [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function shoppingCartPrice($skus, $city_code = "025", $region_code = "01"){ |
||||
$req = new \ShoppingcartpriceQueryRequest(); |
||||
$req -> setChannelCode($this->_channel_code); |
||||
$req -> setCityCode($city_code); |
||||
$req -> setRegionCode($region_code); |
||||
$arr = []; |
||||
foreach ($skus as &$sku) { |
||||
list($channel, $supplier_code, $sku_id) = explode("-", $sku['unicode']); |
||||
$cmmdtyInfoList= new \CmmdtyInfoList1(); |
||||
$cmmdtyInfoList->setSkuId($sku_id); |
||||
$cmmdtyInfoList->setSupplierCode($supplier_code); |
||||
$cmmdtyInfoList->setNum($sku['num'] ?? 1); |
||||
$arr[] = $cmmdtyInfoList; |
||||
} |
||||
|
||||
$req ->setCmmdtyInfoList1($arr); |
||||
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 |
||||
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); |
||||
$resp = $this->_client->execute($req); |
||||
$data = json_decode($resp, true); |
||||
if (isset($data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data']) && $data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data']) { |
||||
return $data['sn_responseContent']['sn_body']['queryShoppingcartprice']['data']; |
||||
} |
||||
return []; |
||||
} |
||||
/** |
||||
* 全量地址接口 |
||||
* [passpartproductinfo description] |
||||
* @param [type] $supplier_code [description] |
||||
* @param string $spu_id [description] |
||||
* @return [type] [description] |
||||
*/ |
||||
public function fulladdress(){ |
||||
$req = new \FulladdressGetRequest(); |
||||
//$req -> setCheckParam('true');//api入参校验逻辑开关,当测试稳定之后建议设置为 false 或者删除该行 |
||||
$client = new \DefaultSuningClient($this->_domain, $this->_app_key,$this->_app_secrect,'json'); |
||||
$resp = $this->_client->execute($req); |
||||
$data = json_decode($resp, true); |
||||
// echo "<pre>"; |
||||
// print_r($data); |
||||
//exit(); |
||||
if (isset($data['sn_responseContent']['sn_body']['getFulladdress']['addressList']) && $data['sn_responseContent']['sn_body']['getFulladdress']['addressList']) { |
||||
return $data['sn_responseContent']['sn_body']['getFulladdress']['addressList']; |
||||
} |
||||
return []; |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue