flashbox / flashbox-api-php
FlashBox Api PHP 处理器
Requires
- php: >=5.5.9
This package is auto-updated.
Last update: 2024-09-13 18:42:20 UTC
README
此包旨在简化 FlashBox RESTful API 的应用开发。有关此 API 的更多信息,请访问 FlashBox 文档
安装
首先,您需要一个 访问令牌。所有 FlashBox API 端点都支持 JWT 认证协议。要开始发送经过身份验证的 HTTP 请求,您需要使用发送给您的 JWT 授权令牌。然后,您可以使用 Composer 安装此包,运行以下命令
composer require flashbox/flashbox-api-php
Packagist 链接: https://packagist.org.cn/packages/flashbox/flashbox-api-php
用法
0. 设置令牌 & 端点
use FlashBox\FlashBoxApiHandler; FlashBoxApiHandler::setToken(**YOUR_TOKEN**); FlashBoxApiHandler::setEndpoint();
1. 认证
use FlashBox\FlashBoxApiHandler; $apiResponse = FlashBoxApiHandler::authenticate(); if ($apiResponse && $apiResponse->status == "success") { $user = $apiResponse->object->user; echo $user->firstname . " " . $user->lastname; }
示例 API 响应
{
"status": "success",
"object": {
"user": {
"id": 99,
"phone": "09701234567",
"firstname": "john",
"lastname": "doe",
"type": "CUSTOMER",
"email": "john_doe@gmail.com",
"email_verified": 0,
"verify": 1,
"found_us": "",
"referral_code": null,
"referred_by": null,
"created_at": "2017-09-16T17:06:28+04:30",
"updated_at": "2017-09-18T16:07:02+04:30",
"deleted_at": null,
"jwt_token": **YOUR_TOKEN**,
"avatar": {
"url": "/uploads/user/99/avatar.jpg?var=1505744313"
},
"last_online": null,
"is_online": null,
"banks": []
}
}
}
2. 获取地址
此端点通过经纬度检索地点信息。
use FlashBox\Model\Location; $apiResponse = Location::getAddress("35.732595", "51.413379"); if ($apiResponse && $apiResponse->status == "success") { echo $apiResponse->object->province; }
示例 API 响应
{
"status": "success",
"message": "",
"object": {
"address": [
"288 Bremner Blvd, Toronto, ON M5V 3L9, Canada"
],
"region": "",
"country": "canada",
"city": "gta",
"province": "old toronto"
}
}
3. 位置建议
此端点通过搜索输入检索建议。结果将是一个建议数组。每个建议都包括检索到的地点的名称和区域,并为该项目提供坐标。
use FlashBox\Model\Location; // $locationName = null; // returns FlashBox Exception // $locationName = ''; // returns FlashBox Exception $locationName = "Bremner"; $apiResponse = Location::getSuggestions($locationName, "43.642691,-79.385852"); if ($apiResponse && $apiResponse->status == "success") { $locations = $apiResponse->object; echo "<ol>"; foreach ($locations as $location) { echo "<li>"; echo $location->region . ": " . $location->title; echo "</li>"; } echo "</ol>"; }
示例 API 响应
{
"status": "success",
"message": "autoComplete",
"object": [
{
"lat": "43.6415306",
"lng": "-79.3868642",
"title": "Bremner Boulevard ,Toronto ,ON ,Canada"
},
{
"lat": "43.9107096",
"lng": "-78.9255206",
"title": "Bremner Street ,Whitby ,ON ,Canada"
},
{
"lat": "43.816452",
"lng": "-79.1180552",
"title": "Bremner Pool And Spa ,Kingston Road ,Pickering ,ON ,Canada"
},
{
"lat": "43.640736",
"lng": "-79.392715",
"title": "Bremner Blvd at Spadina Ave ,Toronto ,ON ,Canada"
},
{
"lat": "43.640602",
"lng": "-79.392487",
"title": "Bremner Blvd at Spadina Ave East Side ,Toronto ,ON ,Canada"
}
]
}
4. 获取价格
请求具有起始地址和目的地址的订单报价。
use FlashBox\Model\Address; use FlashBox\Model\Order; /* * Create Origin Address */ $origin = new Address('origin', '43.642691', '-79.385852'); /* * Create First Destination */ $firstDest = new Address('destination', '43.660949', '-79.371432'); /* * Create Second Destination */ $secondDest = new Address('destination', '43.685905', '-79.403533'); /* * Create New Order */ $order = new Order('motorbike', 3, $origin, [$firstDest, $secondDest]); $order->setHasReturn(true); $apiResponse = $order->getPrice(); if ($apiResponse && $apiResponse->status == "success") { $addresses = $apiResponse->object->addresses; $origin = $addresses[0]; echo "ORIGIN: {$origin->city} ({$origin->lat} , {$origin->lng})"; echo "<br/>"; echo "Transport Type: " . $apiResponse->object->transport_type; echo "<hr/>"; $destinations = array_shift($addresses); echo "<table border='1' cellspacing='0'> <thead> <tr style='background: #bddaf5'> <th>#</th> <th>City</th> <th>Distance</th> <th>Duration</th> <th>Price</th> </tr> </thead> <tbody> "; foreach ($addresses as $destination) { echo "<tr> <td>{$destination->priority}</td> <td>{$destination->city}</td> <td>{$destination->distance}</td> <td>{$destination->duration}</td> <td>{$destination->price}</td> </tr>"; } echo "<tr style='background: #7ab2a5; text-align: center'> <td colspan='2'>Total</td> <td>{$apiResponse->object->distance}(meters)</td> <td>{$apiResponse->object->duration}(seconds)</td> <td>{$apiResponse->object->price}(toman)</td> </tr>"; }
示例 API 响应
{
"status": "success",
"message": null,
"object": {
"addresses": [
{
"type": "origin",
"lat": "43.642691",
"lng": "-79.385852",
"description": null,
"unit": null,
"number": null,
"person_fullname": null,
"person_phone": null,
"address": "288 Bremner Blvd, Toronto, ON M5V 3L9, Canada",
"city": "gta",
"priority": 0
},
{
"type": "destination",
"lat": "43.660949",
"lng": "-79.371432",
"description": null,
"unit": null,
"number": null,
"person_fullname": null,
"person_phone": null,
"address": "203 Gerrard St E, Toronto, ON M5A 2E7, Canada",
"city": "gta",
"priority": 1,
"distance": 3541,
"duration": 768,
"coefficient": 0.6458176983879247,
"price": 2
},
{
"type": "destination",
"lat": "43.685905",
"lng": "-79.403533",
"description": null,
"unit": null,
"number": null,
"person_fullname": null,
"person_phone": null,
"address": "273 Poplar Plains Rd, Toronto, ON M4V 2N9, Canada",
"city": "gta",
"priority": 2,
"distance": 4811,
"duration": 815,
"coefficient": 0.568113300769364,
"price": 2
},
{
"type": "return",
"lat": "43.642691",
"lng": "-79.385852",
"description": null,
"unit": null,
"number": null,
"person_fullname": null,
"person_phone": null,
"address": "288 Bremner Blvd, Toronto, ON M5V 3L9, Canada",
"city": "gta",
"priority": 3,
"distance": 5686,
"duration": 902,
"coefficient": 0.5326247656357299,
"price": 2
}
],
"price": 11.95,
"payment_type": "3",
"credit": false,
"distance": 14038,
"duration": 2485,
"status": "OK",
"user_credit": 0,
"delay": 0,
"city": "gta",
"transport_type": "motorbike",
"has_return": true,
"cashed": false,
"price_with_return": null,
"score": 6,
"score_detail": {
"Order Completion": 5.975
},
"final_price": 11.95,
"discount": 0,
"discount_coupons": [],
"invalid_discount_coupons": [],
"failed_final_price": 0,
"failed_discount": 0,
"failed_discount_coupons": [],
"scheduled": false,
"attributes": []
}
}
5. 创建订单
一旦计算出订单的价格,您可以使用此端点创建新的订单。
use FlashBox\Model\Address; use FlashBox\Model\Order; /* * Create Origin: Behjat Abad */ $origin = new Address('origin', '43.642691', '-79.385852'); $origin->setDescription("Behjat Abad"); // optional $origin->setUnit("44"); // optional $origin->setNumber("1"); // optional $origin->setPersonFullname("Leonardo DiCaprio"); // optional $origin->setPersonPhone("09370000000"); // optional /* * Create Second Destination: Ahmad Qasir Bokharest St */ $secondDest = new Address('destination', '35.895452', '51.589632'); $secondDest->setDescription("Ahmad Qasir Bokharest St"); // optional $secondDest->setUnit("66"); // optional $secondDest->setNumber("3"); // optional $secondDest->setPersonFullname("Matt Damon"); // optional $secondDest->setPersonPhone("09390000000"); // optional $order = new Order('motorbike', 3, $origin, [$firstDest, $secondDest]); $order->setHasReturn(true); $apiResponse = $order->create($order); var_dump($apiResponse);
6. 获取订单详情
为了获取订单详情,调用此方法。
use FlashBox\Model\Order; // $orderID = " 309 "; // $orderID = " 309<p>"; // $orderID = ''; // $orderID = null; $orderID = 309; $apiResponse = Order::getDetails($orderID); var_dump($apiResponse);
7. 取消订单
您可以在快递到达之前(在已接受状态之前)取消任何订单。
use FlashBox\Model\Order; // $orderID = " 300 "; // works fine as 300 // $orderID = " 300<p>"; // works fine as 300 // $orderID = ''; // throws FlashBoxException // $orderID = null; // throws FlashBoxException $orderID = 300; $apiResponse = Order::cancel($orderID); var_dump($apiResponse);
8. 获取批量价格
此端点与正常价格相同,但不同之处在于您可以在一个请求中计算出最多 15 对正常价格。
use FlashBox\Model\Address; use FlashBox\Model\Order; /* * Create Origin Address */ $origin = new Address('origin', '43.642691', '-79.385852'); /* * Create First Destination */ $firstDest = new Address('destination', '43.660949', '-79.371432'); /* * Create Second Destination */ $secondDest = new Address('destination', '43.685905', '-79.403533'); /* * Create New Order */ $orders[] = new Order('motorbike', 3, $origin, [$firstDest, $secondDest]); $orders[] = new Order('car', 3, $origin, [$firstDest, $secondDest]); $orders[] = new Order('cargo_s', 3, $origin, [$firstDest, $secondDest]); $orders[] = new Order('cargo', 3, $origin, [$firstDest, $secondDest]); $apiResponse = FlashBoxApiHandler::getBatchPrice($orders);
许可证
此包在 MIT 许可证 下发布。
版权 (c) 2019-2021 Markus Poerschke
在此授予任何人免费获得本软件及其相关文档副本(“软件”)的副本的权利,无限制地处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许向软件提供的人这样做,但受以下条件约束
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、针对特定目的的适用性和非侵权的保证。在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任承担责任,无论此类责任是基于合同、侵权或其他方式,源于、因或与软件或软件的使用或其他方式相关。