Shopify 全套接口开发,产品上传、订单检索、自动履行【PHP接口】开发

PHP 接口:

以下接口为基础实现接口,可以自由调用。

以下基础方法实现了:
产品的自动发布,将产品直接发布到店铺中。
订单的自动检索,将店铺中需要履行的订单全部拉下来。
订单的自动履行(发货),将运单号同步到店铺后台发货。
产品上传推荐使用CSV 方式,即将多个产品按一定的格式汇出成一个CSV表格,将CSV上传到店铺产品管理中。

CSV参考:
参考:
https://shopify.dev/api/admin-rest/2021-10/resources/order#[get]/admin/api/2021-10/orders.json
参考:
https://shopify.dev/api/admin-rest/2021-10/resources/fulfillment#[post]/admin/api/2021-10/orders/{order_id}/fulfillments.json

shopify 是一家加拿大的自发货独立站,目前可以通过三种途径接入,
私有应用:仅对自己的店铺有效
公有应用:可以公开使用,对所有店铺授权
专属应用:需要自己创建到账号密码给到平台方授权

第一种适合于测试,第二种适合系统足够强大且完善的平台,第三种适合初创公司。
推荐使用第三种:
在店铺后台选择应用,右侧页面拉到最下面,点击管理专有应用
在这里插入图片描述
根据提示获取账号密码,创建类似于 如下链接的格式:

'https://' . $username . ':' . $password . '@' . $shop . '.myshopify.com/admin/api/2021-07/orders.json';

将产品的读取、写入,订单的读取、订单的履行等等权限开通(根据需要可以在店铺后台选择开通哪些权限)。

以下代码为基础实现接口,不包含实际业务接口。

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/5/19
 * Time: 10:52
 */

namespace app\shopify;


class Shopify
{
   
    private $max_time;

    public function __construct()
    {
   
        $this->max_time = date('Y-m-d', strtotime('+3 days')) . 'T11:00:00-05:00';
    }


    /**
     * 检索位置列表
     * @param $username
     * @param $password
     * @param $shop
     * @param $u_id
     * @return mixed|string
     */
    public function getThisLocations($username, $password, $shop, $u_id)
    {
   
        $url = 'https://' . $username . ':' . $password . '@' . $shop . '.myshopify.com/admin/api/2021-07/locations.json';
        $result = $this->requestHandle($url, $data = [], $method = 'GET');
        if (isset($result['locations']) && is_array($result['locations'])) {
   
            foreach ($result['locations'] as $k => $node) {
   
                $data = [
                    'location_id' => $node['id'],
                    'u_id' => $u_id,
                    'shop' => $shop,
                    'name' => $node['name'],
                    'address1' => $node['address1'],
                    'address2' => $node['address2'],
                    'city' => $node['city'],
                    'zip' => $node['zip'],
                    'province' => $node['province'],
                    'country' => $node['country'],
                    'phone' => $node['phone'],
                    'country_code' => $node['country_code'],
                    'country_name' => $node['country_name'],
                    'province_code' => $node['province_code'],
                    'active' => $node['active'],
                    'localized_country_name' => $node['localized_country_name'],
                    'localized_province_name' => $node['localized_province_name'],
                ];

                if (db('shop_locations')->where('location_id', $node['id'])->where('u_id', $u_id)->value('id')) {
   
                    db('shop_locations')->where('location_id', $node['id'])->where('u_id', $u_id)->update($data);
                } else {
   
                    db('shop_locations')->insertGetId($data);
                }
            }
        }


        return $result;
    }

    /**
     * 获得订单信息
     * @param $username
     * @param $password
     * @param $shop
     * @param  $time
     * @return mixed|string
     * https://shopify.dev/api/admin-rest/2021-10/resources/order#[get]/admin/api/2021-10/orders.json
     */
    public function getShopifyOrderLists($username, $password, $shop, $time)
    {
   
        if (!$time) {
   
            $time = $this->max_time;
        }
        $url = 'https://' . $username . ':' . $password . '@' . $shop . '.myshopify.com/admin/api/2021-07/orders.json';
        $data = [
            'financial_status' => 'paid',
            'limit' => 50,
            'created_at_max' => $time
        ];
        $result = $this->requestHandle($url, $data, $method = 'GET');
        return $result;

    }

    /**
     * 检索订单计数
     * @param $shop
     * @param $username
     * @param $password
     * @param $time
     * @return array|string
     */
    public function getOrderCount($shop, $username, $password, $time)
    {
   

        if (!$time) {
   
            $time = $this->max_time;
        }
        $url = 'https://' . $username . ':' . $password . '@' . $shop . '.myshopify.com/admin/api/2021-07/orders/count.json';

        $data = [
            'financial_status' => 'paid',
            'created_at_max' => $time
        ];

        $result = $this->requestHandle($url, $data, $method = 'GET');
        return $result;
    }


    /**
     * 获取店铺产品列表
     * @param array $opt
     * @return mixed
     */
    public function getShopProductList($shop, $opt = [])
    {
   

        $shop_stroe_list = db('shop_store')->where('url', $shop)->find();
        $username = $shop_stroe_list['username'];
        $password = $shop_stroe_list['password'];
        $data = [
            'status' => 'active'
        ];
        $data = array_merge($data, $opt);
        $query = 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jason Ho

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值