PHP code example of sudiyi / sudiyi-open-php-sdk
1. Go to this page and download the library: Download sudiyi/sudiyi-open-php-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sudiyi / sudiyi-open-php-sdk example snippets
use Sudiyi\Open\Api;
$partner_id = "<您从速递易开放平台获得的 PartnerId>";
$partner_key = "<您从速递易开放平台获得的 PartnerKey>";
$sdyClient = new Api($partner_id, $partner_key);
$data = array(
'device_id' => 1000149, // 速递易设备ID
'box_type' => 2, // 箱格类型 0:大箱 1:中箱 2:小箱 3:冰箱
'notify_url' => 'http://your.url/to/notify.php', // 回调第三方系统的地址
'auto_upgd' => true, // 选填,是否可以自动升箱
'sender_name' => 'Stefans', // 选填,投递人姓名
'sender_mobile' => '18612345678', // 选填,投递人手机
'order_no' => '2015000001', // 第三方订单号,即自己平台的订单号
'consignee_name' => 'demon', // 收货人姓名
'consignee_mobile' => '15887654321', // 收货人手机号
'payment' => 0, // 选填,到付金额,如果不是到付件则为0
'pay_type' => 0, // 选填,超期付费方式 0:快递柜付费 1:从商户账户扣除
'duration' => 60 // 选填,预约时长,单位分钟,默认240分钟
);
// 预约速递易箱格
$result = $sdyClient->resv($data);
echo "预约成功: \n";
var_dump($result);
$resv_order_no = $result['resv_order_no'];
// 查询预约状态
$result = $sdyClient->getResv($resv_order_no);
echo "查询预约状态: \n";
var_dump($result);
use Sudiyi\Open\Api;
use Sudiyi\Open\Core\SdyException;
try {
// 预约速递易箱格
$result = $sdyClient->resv($data);
$resv_order_no = $result['resv_order_no'];
// 取消预约箱格
$result = $sdyClient->cancelResv($resv_order_no);
echo "取消预约箱格: \n";
var_dump($result);
} catch (SdyException $e) {
echo "============== ERROR ==============\n";
echo $e->getMessage() . "\n";
var_dump($e->getErrorBody());
echo "===================================\n";
}
|-- example
| |-- api_use_demo.php 案例程序代码
| `-- notify_demo.php 商户回调处理
|-- src
| |-- Core
| | |-- Base.php 基础类
| | |-- Config.php 常量配置
| | |-- Http.php Http请求处理类
| | `-- SdyException.php 异常类
| `-- Api.php 接口封装类
|-- tests/ 测试文件
|-- autoload.php PSR-4 自动加载
`-- composer.json
预约成功:
array(1) {
'resv_order_no' =>
int(20160719000001)
}
查询预约状态:
array(3) {
'status' =>
int(1)
'resv_order_no' =>
int(20160719000001)
'open_code' =>
NULL
}