/**
* shopify获取订单
*/
public function getorder()
{
$url = 'https://{API_KEY}:{PASSWORD}@{SHOP_NAME}.myshopify.com/admin/api/2021-01/orders.json';
$list = file_get_contents($url);
$list = json_decode($list);
$this->success('',$list);
}
/**
* shopify获取产品
*/
public function products()
{
$url = 'https://{API_KEY}:{PASSWORD}@{SHOP_NAME}.myshopify.com/admin/api/2021-01/products/6213868355752.json';
$list = file_get_contents($url);
$list = json_decode($list);
$this->success('',$list);
}
/**
* 上传产品
*/
public function create_prodect()
{
$products_array = array(
"product"=>array(
"title"=> '',
"body_html"=> "防滑耐磨高帮",
"vendor"=> "安踏旗舰店",
"product_type"=> "鞋子",
"published"=> false ,
"variants"=>array(
array(
"id"=>'231564646466',
"sku"=>"31315465454",
"price"=>899,
"grams"=>1000,
'option1'=>'',
"taxable"=>false,
"inventory_quantity"=>11,
"inventory_management"=>'shopify'
),
array(
"id"=>'645646513133',
"sku"=>'31315465456',
"price"=>999,
"grams"=>1000,
'option1'=>40,
"taxable"=>false,
"inventory_quantity"=>10,
"inventory_management"=>'shopify'
),
),
"options"=>array(
'name'=>'尺寸'
),
"images"=>array(
array(
"src"=>"https://cdn.shopify.com/s/files/1/0530/3445/1112/products/aMubm5jb2WFn.jpg",
),
array(
"src"=>"https://cdn.shopify.com/s/files/1/0530/3445/1112/products/aHR0cjkh.jpg",
)
),
"image"=>array(
array(
"src"=>"https://cdn.shopify.com/s/files/1/0530/3445/1112/products/aHR0cHM6Ly9zdGF0.jpg",
)
)
)
);
//dump($products_array);die();
$url = "https://{API_KEY}:{PASSWORD}@{SHOP_NAME}.myshopify.com/admin/products.json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($products_array));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($curl);
curl_close ($curl);
$response = json_decode($response,true);
if ($response['errors']){
$this->error('上传失败');
}else{
$this->success('上传成功');
}
}
shopify API接口对接
最新推荐文章于 2024-06-15 09:45:33 发布