You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/common/service/Jd.php

61 lines
1.8 KiB

<?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);
// echo "<pre>";
// print_r($res);
// exit();
if ($res && isset($res['success']) && $res['success'] == 1) {
return $res['result'];
}
return null;
}
}