承接 szunisoft/laravel-unas 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

szunisoft/laravel-unas

Composer 安装命令:

composer require szunisoft/laravel-unas

包简介

Laravel package for UNAS Webshop API

README 文档

README

Build Status Latest Stable Version Total Downloads License PHP from Packagist Coverage Status

Laravel Unas

About the package

The package is not finished yet however will be maintained and developed continuously as our primary project which requires this extension will.

Naming conventions

At some point the official Unas naming convention is not that good or does not exist at all. However the package is not trying to introduce custom naming conventions it will use the official property and attribute names as they are described in the documentation.

API compatibility

The following table contains the related API endpoints. All the endpoints will be supported soon.

Endpoint Support
getProduct ✔️
setProduct
getOrder
setOrder
getStock
setStock
getCategory
setCategory
getNewsletter
setNewsletter

Future features ⭐

Configurable Rate Limiting

Will fire an event each time an endpoint is being exhausted based on the given configuration.

Requirements ❗

  • php >= 7.2
  • ext-xmlwriter
  • ext-simplexml

Install ▶️

composer require szunisoft/laravel-unas

Laravel support ✋

>= 5.5

Configure ⚙️

Export the configuration

php artisan vendor:publish --provider="SzuniSoft/Unas/Laravel/UnasServiceProvider" --tag=config
Authentication

Two authentication drivers are supported.

Legacy (default driver)

You must set the driver to legacy.

For legacy authentication you will need the following credentials:

  • username
  • password
  • shop_id
  • auth_code
Key

You must set the driver to key.

In case of key authentication you will need to generate an API key inside the Unas portal.

Error handling principles

Some kind of exceptions can be turned into events rather than throwing them. This is just a code architectural decision how a particular circumstance should be handled.

For instance we create a multi-tenancy project which will handle tons of different clients traffic behind the scenes. It is more wise to consume and intercept errors as events since we'll be able to use multiple listeners on it and we can send notification to the tenant also.

In the other hand if you'll need a very specific and custom application for a single tenant then it would be more appropriate to intercept errors as exceptions because it is probably the core component of the entire application.

By default all events are disabled and going to raise.

To adjust your needs your can freely add or remove events declared in the configuration file.

<?php 
return [
    
    // ....
    
    'events' => [
    
        // Add or remove events here.
        SzuniSoft\Unas\Laravel\Events\EndpointBlacklisted::class
    
    ]
];

The following errors can be turned into events.

Exception Event
EndpointBlacklistedException EndpointBlacklisted
InvalidConfigurationException InvalidConfiguration
AuthenticationException Unauthenticated
PremiumAuthenticationException Unauthenticated
A little talk about each exception
EndpointBlacklistedException

Thrown when an endpoint is being exhausted for a single client. You can access the client and the until Carbon instance.

InvalidConfigurationException

Thrown in case of bad client configuration.

AuthenticationException

This exception will be thrown when legacy or key credentials are invalid. You can access the field which was invalid.

PremiumAuthenticationException

Thrown when the desired authentication way is API key but related tenant has no Premium package. In this case tenant should use the legacy approach.

TooHighChunkException

Thrown when an endpoint does not allow the amount of given results per page.

Remembering clients

Sometimes you wish to have multiple clients. If you want clients to be remembered you can turn on this feature in the configuration. Remembering client will avoid creating multiple clients for the same authentication credentials.

Creating and accessing client

There are multiple ways to create clients.

Dependency Injection

This method will use the credentials given in the configuration.

<?php 
function anyFunction (SzuniSoft\Unas\Internal\Client $client) {
}
IoC Container

This method will use the credentials given in the configuration.

<?php
$client = app(SzuniSoft\Unas\Internal\Client::class);
$client = app('unas.client');

Sometimes you want to customize the client by yourself. For these kind of desires you can use the client Builder and client Factory.

Client Builder
<?php
$builder = app(SzuniSoft\Unas\Laravel\Support\ClientBuilder::class);
$builder = app('unas.client.builder');

$client = $builder
    // Apply premium authentication API key manually.
    ->withPremium('SomeApiKey')
    // Apply legacy authentication credentials manually.
    ->withLegacy('Username', 'Password', 'ShopID', 'AuthCode')
    // Override default base path to access Unas.
    // You should never set base url manually except when url changed.
    ->basePath('http://new.domain')
    // Set events that should be fired instead throwing as exception.
    ->allowedEvents(...)
    // Set events that should not be fired. Instead exception should be thrown.
    ->disallowedEvents(...)
    // Finally retrieve the client.
    ->build();
Client Factory
<?php
$factory = app(SzuniSoft\Unas\Laravel\Support\ClientFactory::class);
$factory = app('unas.client.factory');

$config = [
    // Custom client configurations..
];

$client = $factory->create($config);

Get Products

Official details

<?php

/** @var SzuniSoft\Unas\Internal\Client $client */
$client->getProducts()
    ->statusBase(...)
    ->parent(...)
    ->id(...)
    ->sku(...)
    ->timeStart(...)
    ->timeEnd(...)
    ->dateStart(...)
    ->dateEnd(...)
    ->contentType(...)
    ->contentParam(...)
    ->chunk(function (Illuminate\Support\Collection $products) {
        
        $products->each(function (SzuniSoft\Unas\Model\Product $product) {
            // Process product.
        });
        
    }, $perPage = 50);

Accessing page #1 with 50 products per page.

<?php

/** @var SzuniSoft\Unas\Internal\Client $client */
$client->getProducts()
    ->paginate(50)
    ->page(1);

szunisoft/laravel-unas 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-25