定制 wedesignit/sendy-php-api-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wedesignit/sendy-php-api-client

Composer 安装命令:

composer require wedesignit/sendy-php-api-client

包简介

PHP Client for the Sendy API

README 文档

README

Formerly known as KeenDelivery.

Implementation according to the docs.

Installing

composer require wedesignit/sendy-php-api-client

Creating the connector

$client = new \WeDesignIt\Sendy\Client($apiToken);
$sendy = new \WeDesignIt\Sendy\Sendy($client);

After this, the $sendy class can return Endpoints which can be called.

The endpoint methods can either be called with plain arrays or the fluent Resource classes can be used.

Directory structure / Endpoints

The Endpoint directory structure follows the documentation (category) structure for easier recognition. The current main categories are:

  • Carrier
  • Shipment
  • Company Within these categories (category folders) the actual endpoints are located.

Usage examples

Always: Setting up

This applies to every following example and should be prepended to every example.

$client = new \WeDesignIt\Sendy\Client(
    '<your personal access token>'
);
$sendy = new \WeDesignIt\Sendy\Sendy($client);

Listing your carriers

$carriers = $sendy->carrier()->list();

Listing a carrier's services

// Retrieve carrier ID (if you haven't cached it yet)
$carriers = $sendy->carrier()->list();
// Pick the one you need. In this example we'll use the first one
if (array_key_exists('data', $carriers) && is_array($carriers['data']) && count($carriers['data']) > 0) {
    
    $carrier = $carriers['data'][0];
    $carrierId = $carrier['id'];
    
    $services = $sendy->service()->list($carrierId);
    // we could also filter the services by a couple of parameters..
    // either straight via array
    $filters = [
        \WeDesignIt\Sendy\Filters\Carrier\Service::COUNTRY => 'NL',
    ];
    // or via the fluent Filter class
    $filters = (new \WeDesignIt\Sendy\Filters\Carrier\Service())
                ->country('NL')
                ->toArray();
                
    // and use it as second parameter:
    $services = $sendy->service()->list($carrierId, $filters);            
}

Locating nearby parcel shops

// We will use the Filter class here too.
// Note that there's an extra advantage as your parameters will be checked in advance.
$filters = (new \WeDesignIt\Sendy\Filters\Carrier\ParcelShop())
            ->latitude(52.0792755)
            ->longitude(5.3327956)
            ->country('NL')
            ->toArray();

$parcelShops = $sendy->parcelShop()->list($filters);

Listing your shops

$shops = $sendy->shop()->list();

Creating a shipment

// get your shop ID if you haven't cached it yet
$shops = $sendy->shop()->list();
// we'll take the first one in this example
if (array_key_exists('data', $shops) && is_array($shops['data']) && count($shops['data']) > 0) {
    
    $shop = $shops['data'][0];
    $shopId = $shops['uuid'];
}
if (!isset($shopId)) {
    throw new \Exception('No shop ID given');
}
// get your carrier's value if you haven't cached it yet
$carrierInfo = $sendy->carrier()->get(8);
$carrierId = $carrierInfo['data']['id'];
$carrierValue = $carrierInfo['data']['value'];

// get your carrier's service value if you haven't cached it yet
$serviceInfo = $sendy->service()->get($carrierId, 85);
$serviceValue = $serviceInfo['data']['value'];

// now create your shipment 
$shipment = (new \WeDesignIt\Sendy\Resources\Shipment())
            ->carrier($carrierValue)
            ->service($serviceValue)
            ->shopId($shopId)
            ->reference('MS#1BOSS')
            ->companyName('Dunder Mifflin')
            ->contact('Dwight Schrute')
            ->email('assistant-regional-manager@dundermifflin.ext')
            ->street('1725 Slough Avenue')
            ->number('Suite 200')
            ->city('Pennsylvania')
            ->country('US')
            ->weight(3.14)
            ->amount(1)
            ->products([
                (new \WeDesignIt\Sendy\Resources\Shipment\Product())
                    ->description('Stapler')
                    ->netWeight(3.14)
                    ->quantity(1)
                    ->value(99.99)
            ])
            ->toArray();
            
$shipmentResponse = $sendy->shipment()->create($shipment);

Retrieving a shipment label

$shipmentId = $shipmentResponse['data']['uuid'];
if ($shipmentResponse['data']['has_labels'] && $shipmentResponse['data']['status'] !== 'generated'){
    // Labels weren't generated yet. Make the call to do that.
    $labelInfo = $sendy->shipment()->generateLabel($shipmentId);
    // Note this was an asychronous call, so you'll have to wait a little before making the following call
}

$label = $sendy->document()->get($shipmentId);
// The label is a base64 encoded PDF file

// Display the PDF. Of course you could also do other things with it (e.g. store it somewhere).
$pdf = base64_decode($label);
header('Content-Type: application/pdf');
echo $pdf;

wedesignit/sendy-php-api-client 适用场景与选型建议

wedesignit/sendy-php-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 713 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Sendy」 「WeDesignIt」 「Sendy API client」 「KeenDelivery」 「KeenDelivery API client」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 wedesignit/sendy-php-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wedesignit/sendy-php-api-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 wedesignit/sendy-php-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 713
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-06