claassenmarius/laravel-skynet 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

claassenmarius/laravel-skynet

Composer 安装命令:

composer require claassenmarius/laravel-skynet

包简介

A laravel package to use the Skynet Courier API

README 文档

README

Tests Check & fix styling

A Laravel package to use the Skynet Courier API.

Installation

Require the package using composer:

composer require claassenmarius/laravel-skynet

Usage

Add the following environment variables to your .env file and add your Skynet account username, password, system id and account number.

SKYNET_ACCOUNT_USERNAME=
SKYNET_ACCOUNT_PASSWORD=
SKYNET_SYSTEM_ID=
SKYNET_ACCOUNT_NUMBER=

You can obtain an instance of Claassenmarius\LaravelSkynet\Skynet in any of the following ways:

Type-hinting / Dependency injection

When type-hinting Skynet in a method, Laravel will automatically resolve it from the IOC container for you.

use Claassenmarius\LaravelSkynet\Skynet;

class QuoteController extends Controller
{
    public function __invoke(Skynet $skynet)
    {
        $response = $skynet->quote(...);
        
        // do somethin with the $response
    }    
}

Facade

You can use the Skynet Facade.

use Claassenmarius\LaravelSkynet\Facades\Skynet;

class QuoteController extends Controller
{
    public function __invoke()
    {
        $response = Skynet::quote(...);
        
        // do somethin with the $response
    }   
}

Manually resolving it from the IOC container

use Claassenmarius\LaravelSkynet\Skynet;

class QuoteController extends Controller
{
    public function __invoke()
    {
        $skynet = app()->make(Skynet::class);
        
        $response = $skynet->quote(...);
        
        // do somethin with the $response
    }   
}

Manual instantiation

If you plan on instantiating Skynet manually throughout your project it won't be neccessary to add your Skynet credentials to the .env file. Instead, pass your credentials to the constructor.

use Claassenmarius\LaravelSkynet\Skynet;

class QuoteController extends Controller
{
    public function __invoke()
    {
        $skynet = new Skynet(
          'skynet_username',
          'skynet_password',
          'skynet_system_id',
          'skynet_account_number'
        );
        
        $response = $skynet->quote(...);
        
        // do somethin with the $response
    }
}

The following methods are available to get a security token, validate a suburb/postcode combination, get a list of postal codes for a suburb, get a quote for a parcel, get an ETA between two locations, generate a waybill, obtain a POD image and track a waybill. Each method returns a new Illuminate\Http\Client\Response which exposes methods to inspect the response.

Get a security token

$response = $skynet->securityToken();

Validate a suburb and postal code combination

$response = $skynet->validateSuburbAndPostalCode([
    'suburb' => 'Brackenfell',
    'postal-code' => '7560'
]);

Get a list of postal codes for a suburb

$response = $skynet->postalCodesFromSuburb('Brackenfell');

Get a quote for a parcel

$response = $skynet->quote([
    'collect-city' => 'Brackenfell',
    'deliver-city' => 'Stellenbosch',
    'deliver-postcode' => '7600',
    'service-type' => 'ON1',
    'insurance-type' => '1',
    'parcel-insurance' => '0',    
    'parcel-length' => 10, //cm
    'parcel-width' => 20, // cm
    'parcel-height' => 30, //cm
    'parcel-weight' => 20 //kg
]);

Get ETA between two locations

$response = $skynet->deliveryETA([
    'from-suburb' => 'Brackenfell',
    'from-postcode' => '7560',
    'to-suburb' => 'Stellenbosch',
    'to-postcode' => '7600',
    'service-type' => 'ON1'
]);

Generate a waybill

$response = $skynet->createWaybill([
    "customer-reference" => "Customer Reference",
    "GenerateWaybillNumber" => true,
    "service-type" => "ON1",
    "collection-date" => "2021-06-26",
    "from-address-1" => "3 Janie Street, Ferndale, Brackenfell",
    "from-suburb" => "Brackenfell",
    "from-postcode" => "7560",
    "to-address-1" => "15 Verreweide Street, Universiteitsoord, Stellenbosch",
    "to-suburb" => "Stellenbosch",
    "to-postcode" => "7600",
    "insurance-type" => "1",
    "insurance-amount" => "0",
    "security" => "N",
    "parcel-number" => "1",
    "parcel-length" => 10,
    "parcel-width" => 20,
    "parcel-height" => 30,
    "parcel-weight" => 10,
    "parcel-reference" => "12345",
    "offsite-collection" => true
]);

Get a waybill POD Image

$response = $skynet->waybillPOD('your-waybill-number');

Track a waybill

$response = $skynet->trackWaybill('your-waybill-number');

Response

Illuminate\Http\Client\Response provides the following methods to inspect the response.

Get the body of the response as a string:

$securityToken = $response->body(); 
// "{"SecurityToken":"2_f77e4922-1407-485e-a0fa-4fdd5c29e9ca"}" 

Get the JSON decoded body of the response as an array or scalar value (if a $key is passed in)

$securityToken = $response->json($key); 
// ["SecurityToken" => "2_c767aa41-bca8-4084-82a0-69d8e27fba2c"] 

Get the JSON decoded body of the response as an object.

$securityToken = $response->object(); 
// { +"SecurityToken": "2_c767aa41-bca8-4084-82a0-69d8e27fba2c" }

Get the JSON decoded body of the response as a collection.

$securityToken = $response->collect($key); 

Get a header from the response.

$header = $response->header($header); 
// "application/json; charset=utf-8"

Get the headers from the response.

$headers = $response->headers(); 
// Return an array of all headers

Get the status code of the response.

$headers = $response->status(); 
// 200

Determine if the request was successful (Whether status code >=200 & <300)

$headers = $response->successful(); 
// true

Determine if the response code was "OK". (Status code === 200)

$headers = $response->ok(); 
// true

Determine if server error occurred. (Whether status code >=500)

$headers = $response->serverError(); 
// false

Determine if client or server error occurred.

$headers = $response->failed(); 
// false

You can inspect the Laravel documentation for more information on the methods that Illuminate\Http\Client\Response provide.

Exception Handling

This package uses Laravel's Http Client behind the scenes, which does not throw exceptions on client or server errors (400 and 500 level responses from servers). You may determine if one of these errors was returned using the successful, clientError, or serverError methods.

If you have a response instance and would like to throw an instance of Illuminate\Http\Client\RequestException if the response status code indicates a client or server error, you may use the throw method:

response = $skynet->quote(...);

if($response->failed()) {
// Throw an exception if a client or server error occurred...
  $response->throw();
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email marius.claassen@outlook.com instead of using the issue tracker.

License

The MIT Licence (MIT). Please see Licence File for more information.

claassenmarius/laravel-skynet 适用场景与选型建议

claassenmarius/laravel-skynet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 claassenmarius/laravel-skynet 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-25