osenco / glovo
Glovo 商业 API PHP 集成
v0.20.4
2020-04-26 00:17 UTC
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- emcconville/google-map-polyline-encoding-tool: >=1.2.1
This package is auto-updated.
Last update: 2024-09-26 10:24:20 UTC
README
通过他们的商业 API 创建、检索和跟踪您的 Glovo 订单。
要求
PHP 7.2 及以上。
通过 Composer 安装包
$ composer require osenco/glovo
要在项目中使用 Glovo API,请使用 Composer 的自动加载
require_once('vendor/autoload.php');
依赖项
为了正确工作,绑定需要以下扩展
如果您使用 Composer,这些依赖项应该会自动处理。如果您手动安装,您需要确保这些扩展可用。
入门
在 Glovo 中创建账户(可以从前端应用创建)。此 api 需要与您的账户关联的信用卡。您可以从应用中添加一张卡,并且它将自动用于任何订单。要获取您的 API 凭证,您应在所需环境中登录并前往个人资料中的 凭证 部分。
示例 ApiKey & ApiSecret
$apiKey = '125238463972712'; $apiSecret = '081f8c9680d457a088b4413a62ddf84c';
示例用法可能如下所示
<?php include 'vendor/autoload.php'; use Osen\Glovo\Service; use Osen\Glovo\Exception; use Osen\Glovo\Models\Order; use Osen\Glovo\Models\Address; // get credentials on https://business.glovoapp.com/dashboard/profile or https://business.testglovo.com/dashboard/profile $api = new Service( $apiKey, $apiSecret); $api->sandbox_mode( true ); $source = new Address( Address::TYPE_PICKUP, -34.919861, -57.919027, "Diag. 73 1234", "1st floor" ); $destination = new Address( Address::TYPE_DELIVERY, -34.922945, -57.990177, "Diag. 73 75", "3A"); $order = new Order(); $order->setDescription( "1 big hammer" ); $order->setAddresses( [$source, $destination] ); //$order->setScheduleTime( ( new \DateTime( '+1 hour' ) )->setTime( 19, 0 ) ); try { $orderEstimate = $api->estimateOrderPrice( $order ); echo "Estimate: {$orderEstimate['total']['amount']}{$orderEstimate['total']['currency']} \n"; } catch(Exception $e){ echo $e->getMessage(); } try { $orderInfo = $api->createOrder( $order ); echo "Order created, ID: {$orderInfo['id']}, state: {$orderInfo['state']} \n"; } catch(Exception $e){ echo $e->getMessage(); }
在example.php中查看完整示例
更新证书
要更新 CA 根证书,可以运行
$ chmod +x ./update_certs.php $ ./update_certs.php
文档
您可以阅读 [Glovo B2B API 文档][https://api-docs.glovoapp.com/b2b/index.html#introduction]。