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

103 lines
2.9 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;
}
/**
* 实时获取商品主图和详情
* [getGoodsMainImageAndDetail description]
* @param [type] $skuId [description]
* @return [type] [description]
*/
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=";
$res = httpRequest($url);
if ($res && $res['code'] == 0 && isset($res['data'])) {
return $res['data'];
}
return [];
}
/**
* 获取京东短链接
* [getJdShortLink description]
* @param [type] $skuId [description]
* @return [type] [description]
*/
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;
$res = httpRequest($url);
if ($res && $res['code'] == 0 && isset($res['data'])) {
return $res['data'];
}
return "";
}
}