v1.0.2 2018-06-14 02:07 UTC

This package is not auto-updated.

Last update: 2024-09-17 18:08:13 UTC


README

Build Status Coverage Status

Lalamove PHP非官方客户端库

库维护

这个库是Lalamove API的非官方库。目前我们正在修复所有必要的错误并添加必要的功能,以确保库继续满足您访问Lalamove API的需求。非关键问题将被关闭。如果问题持续存在,任何问题都可以重新打开。

要求

  • PHP 5.5.0 或更高版本

安装

您可以使用 Composer

Composer

如果您还没有安装Composer,请遵循安装说明

composer require lalamove/php:1.0.2

入门

报价

以下是我们为SG进行报价所需的代码

$body = array(
  "scheduleAt" => gmdate('Y-m-d\TH:i:s\Z', time() + 60 * 30), // ISOString with the format YYYY-MM-ddTHH:mm:ss.000Z at UTC time
  "serviceType" => "MOTORCYCLE",                              // string to pick the available service type
  "specialRequests" => array(),                               // array of strings available for the service type
  "requesterContact" => array(
    "name" => "Draco Yam",
    "phone" => "+6592344758"                                  // Phone number format must follow the format of your country
  ),  
  "stops" => array(
    array(
      "location" => array("lat" => "1.284318", "lng" => "103.851335"),
      "addresses" => array(
        "en_SG" => array(
          "displayString" => "1 Raffles Place #04-00, One Raffles Place Shopping Mall, Singapore",
          "country" => "SG"                                   // Country code must follow the country you are at
        )   
      )   
    ),  
    array(
      "location" => array("lat" => "1.278578", "lng" => "103.851860"),
      "addresses" => array(
        "en_SG" => array(
          "displayString" => "Asia Square Tower 1, 8 Marina View, Singapore",
          "country" => "SG"                                   // Country code must follow the country you are at
        )   
      )   
    )   
  ),  
  "deliveries" => array(
    array(
      "toStop" => 1,
      "toContact" => array(
        "name" => "Brian Garcia",
        "phone" => "+6592344837"                              // Phone number format must follow the format of your country
      ),  
      "remarks" => "ORDER #: 1234, ITEM 1 x 1, ITEM 2 x 2"
    )   
  )   
);

$request = new \Lalamove\Api\LalamoveApi('https://sandbox-rest.lalamove.com', <apiKey>, <apiSecret>, 'SG');
$result = $request->quotation($body);

示例响应

{
  "totalFeeCurrency": "SGD",
  "totalFee": "10.0"
}

下订单

报价响应需要用于下订单API以锁定价格

$body = array(
  "scheduleAt" => gmdate('Y-m-d\TH:i:s\Z', time() + 60 * 30), // ISOString with the format YYYY-MM-ddTHH:mm:ss.000Z at UTC time
  "serviceType" => "MOTORCYCLE",                              // string to pick the available service type
  "specialRequests" => array(),                               // array of strings available for the service type
  "requesterContact" => array(
    "name" => "Draco Yam",
    "phone" => "+6592344758"                                  // Phone number format must follow the format of your country
  ),  
  "stops" => array(
    array(
      "location" => array("lat" => "1.284318", "lng" => "103.851335"),
      "addresses" => array(
        "en_SG" => array(
          "displayString" => "1 Raffles Place #04-00, One Raffles Place Shopping Mall, Singapore",
          "country" => "SG"                                   // Country code must follow the country you are at
        )   
      )   
    ),  
    array(
      "location" => array("lat" => "1.278578", "lng" => "103.851860"),
      "addresses" => array(
        "en_SG" => array(
          "displayString" => "Asia Square Tower 1, 8 Marina View, Singapore",
          "country" => "SG"                                   // Country code must follow the country you are at
        )   
      )   
    )   
  ),  
  "deliveries" => array(
    array(
      "toStop" => 1,
      "toContact" => array(
        "name" => "Brian Garcia",
        "phone" => "+6592344837"                              // Phone number format must follow the format of your country
      ),  
      "remarks" => "ORDER #: 1234, ITEM 1 x 1, ITEM 2 x 2"
    )   
  ),
  "quotedTotalFee" => array(
    "amount" => "10.0",
    "currency" => "SGD"
  )
);

$request = new \Lalamove\Api\LalamoveApi('https://sandbox-rest.lalamove.com', <apiKey>, <apiSecret>, 'SG');
$result = $request->postOrder($body);

示例响应

{
  "customerOrderId": "a5232cd5-677d-49f8-8977-37380caeea72",    // use for all subsequence call such as getting order info / driver info
  "orderRef": "179802"                                          // the reference shown in driver app when driver arrived or used when calling our customer service
}

获取订单信息

一旦下单,您可以每45秒查询一次订单结果,请注意我们的系统有速率限制。不要频繁调用
获取订单信息

$request = new \Lalamove\Api\LalamoveApi('https://sandbox-rest.lalamove.com', <apiKey>, <apiSecret>, 'SG');
$result = $request->getOrderStatus(<Order id such as a5232cd5-677d-49f8-8977-37380caeea72>);

示例响应

{
  "driverId": "",
  "status": "ASSIGNING"     // During assigning, you are unable to get the driverId
}

获取司机信息

获取司机信息将帮助您的团队知道谁将取订单

$request = new \Lalamove\Api\LalamoveApi('https://sandbox-rest.lalamove.com', <apiKey>, <apiSecret>, 'SG');
$result = $request->getDriverInfo(<order id>, <driverId from the above>);

示例响应

{
    "name": "David",
    "phone": "+6582121212"
}

取消订单

订单只能在订单被取走之前和匹配后5分钟内取消。请注意,每个城市的取消缓冲时间不同,只要您能够收到200作为HTTP状态码,取消操作就成功

$request = new \Lalamove\Api\LalamoveApi('https://sandbox-rest.lalamove.com', <apiKey>, <apiSecret>, 'SG');
$result = $request->cancelOrder(<order id>);

示例响应,但HTTP状态码为200(成功)或失败(非200响应)

{}

如何提交错误、问题或功能请求

如果您想提交错误、问题或功能请求,您可以在这里找到问题,并且您可以在这里创建问题。对于错误报告,请确保您提供以下信息

  1. 您的PHP版本和框架(如果有)
  2. 您的国家/地区
  3. 重现错误的清晰步骤(主要头部、主体和URL)
  4. 描述您期望发生的情况
  5. 描述实际发生的情况

版本

20180126 (v1.0.1)

  • 由Alpha发布
  • 在所有情况下使用json_encode强制将body转换为对象

20170825 (v1.0.0)

  • 由Draco发布
  • 报价、下订单和取消API
  • 获取订单信息、司机信息和位置API
  • 持续集成设置
  • PHP Linter设置