luketowers/php-shopify-api
Composer 安装命令:
composer require luketowers/php-shopify-api
包简介
PHP wrapper for Shopify API
README 文档
README
A simple PHP wrapper around the Shopify API.
Installation
Install via Composer by running composer require luketowers/php-shopify-api in your project directory.
Usage
In order to use this wrapper library you will need to provide credentials to access Shopify's API.
You will either need an access token for the shop you are trying to access (if using a public application) or an API Key and Secret for a private application.
Examples
Make an API call
use LukeTowers\ShopifyPHP\Shopify; // Initialize the client $api = new Shopify('exampleshop.myshopify.com', 'mysupersecrettoken'); // Get all products $result = $api->call('GET', 'admin/products.json'); // Get the products with ids of '632910392' and '921728736' with only the 'id', 'images', and 'title' fields $result = $api->call('GET', 'admin/products.json', [ 'ids' => '632910392,921728736', 'fields' => 'id,images,title', ]); // Create a new "Burton Custom Freestyle 151" product $result = $api->call('POST', 'admin/products.json', [ 'product' => [ "title" => "Burton Custom Freestyle 151", "body_html" => "<strong>Good snowboard!</strong>", "vendor" => "Burton", "product_type" => "Snowboard", "tags" => 'Barnes & Noble, John's Fav, "Big Air"', ], ]);
Use Private Application API Credentials to authenticate API requests
use LukeTowers\ShopifyPHP\Shopify; $api = new Shopify($data['shop'], [ 'api_key' => '...', 'secret' => '...', ]);
Use an access token to authenticate API requests
use LukeTowers\ShopifyPHP\Shopify; $storedToken = ''; // Retrieve the stored token for the shop in question $api = new Shopify('exampleshop.myshopify.com', $storedToken);
Request an access_token for a shop
use LukeTowers\ShopifyPHP\Shopify; function make_authorization_attempt($shop, $scopes) { $api = new Shopify($shop, [ 'api_key' => '...', 'secret' => '...', ]); $nonce = bin2hex(random_bytes(10)); // Store a record of the shop attempting to authenticate and the nonce provided $storedAttempts = file_get_contents('authattempts.json'); $storedAttempts = $storedAttempts ? json_decode($storedAttempts) : []; $storedAttempts[] = ['shop' => $shop, 'nonce' => $nonce, 'scopes' => $scopes]; file_put_contents('authattempts.json', json_encode($storedAttempts)); return $api->getAuthorizeUrl($scopes, 'https://example.com/handle/shopify/callback', $nonce); } header('Location: ' . make_authorization_attempt('exampleshop.myshopify.com', ['read_product'])); die();
Handle Shopify's response to the authorization request
use LukeTowers\ShopifyPHP\Shopify; function check_authorization_attempt() { $data = $_GET; $api = new Shopify($data['shop'], [ 'api_key' => '...', 'secret' => '...', ]); $storedAttempt = null; $attempts = json_decode(file_get_contents('authattempts.json')); foreach ($attempts as $attempt) { if ($attempt->shop === $data['shop']) { $storedAttempt = $attempt; break; } } return $api->authorizeApplication($storedAttempt->nonce, $data); } $response = check_authorization_attempt(); if ($response) { // Store the access token for later use $response->access_token; }
luketowers/php-shopify-api 适用场景与选型建议
luketowers/php-shopify-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.61k 次下载、GitHub Stars 达 35, 最近一次更新时间为 2018 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「shopify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 luketowers/php-shopify-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 luketowers/php-shopify-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 luketowers/php-shopify-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Shopify package for Laravel to aide in app development
A basic Shopify API wrapper with REST and GraphQL support.
A set of APIs to retrieve data from Shopify
Alfabank REST API integration
PHP SDK for Shopify API
统计信息
- 总下载量: 10.61k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 35
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-07