jonmadval/laravel-wubook

Laravel 5.x 的 WuBook 桥接器 http://wubook.net

dev-master / 1.0.x-dev 2018-11-03 21:05 UTC

This package is auto-updated.

Last update: 2024-09-29 04:37:14 UTC


README

此版本的 Laravel WuBook 由 Jonathan Madrid 修改,基于 Laravel WuBook 的代码创建,并由 Filippo Galante 维护,是 WuBook Wired API 的 Laravel 5 桥接器。您可以自由地查看 变更日志发布许可证贡献指南。为了使用 API,您需要通过发送电子邮件至 devel@wubook.net 请求服务提供商密钥,以连接您的 WuBook 账户,您将可以免费尝试所有功能。

此版本与 laravel 5.5.* 和 5.6* 兼容

Latest Version on Packagist Software License StyleCI Build Status Coverage Status Quality Score Total Downloads

安装

需要 PHP 5.5+ 或 HHVM 3.6+。

要获取 Laravel WuBook 的最新版本,只需使用 Composer 引入项目

$ composer require jonmadval/laravel-wubook

当然,您也可以手动更新 require 块并运行 composer update

{
    "require": {
        "jonmadval/laravel-wubook": "v1.0-dev"
    }
}

该软件包使用 fxmlrpc 客户端 来调用 Wired API 服务。使用标准依赖项创建 HTTP 客户端和消息,请自由地创建拉取请求以添加新功能。

一旦安装了 Laravel WuBook,您需要注册服务提供者。打开 config/app.php 并将以下内容添加到 providers 键。

'providers' => [
   // OTHER PROVIDERS
   'jonmadval\LaravelWubook\WuBookServiceProvider::class'
],

您还可以在 config/app.php 文件的 aliases 键中注册 WuBook 门面。

'aliases' => [
   // OTHER ALIASES
   'WuBook' => jonmadval\LaravelWubook\Facades\WuBook::class
],

配置

Laravel WuBook 需要连接配置。

要开始,您需要发布所有供应商资产

$ php artisan vendor:publish

# OR

$ php artisan vendor:publish --provider=jonmadval\LaravelWubook\WuBookServiceProvider

这将在您的应用程序中创建一个 config/wubook.php 文件,您可以根据需要修改它以设置配置。同时,请确保检查此软件包中原始配置文件在发布之间的更改。

账户参数
[
    'username' => 'your-user',              
    'password' => 'your-password',          
    'provider_key' => 'your-provider-key', 
    'lcode' => 'your-lcode',
]

lcode 参数是 WuBook 提供的属性 ID,您可以在主控制面板的“个人资料管理”部分找到它。

provider_key 由 WuBook 开发团队发布。如果您需要创建与您的 WuBook 账户关联的新密钥,请发送电子邮件至 devel@wubook.net

cache_token 参数

如果将 cache_token 参数设置为 true,则所有 API 函数将使用缓存值,并在必要时自动更新。如果您需要获取当前令牌,请调用该方法

Cache::get('wubook.token')     // ex. '9869117656.9552'

该包还将存储一个 'wubook.token.ops' 键,用于追踪使用当前令牌调用的次数,以便在达到最大操作数时刷新它。

注意:如果将 cache_token 设置为 false,则包将不会检查令牌是否超过了最大操作数!

缓存中存储的值将在 3600 秒后过期,如果将 cache_token 参数设置为 true,它将自动续订。请阅读http://tdocs.wubook.net/wired/policies.html

用法

WuBookManager

这是最有兴趣的类。它绑定到 ioc 容器中的 'wubook',可以使用 Facades\WuBook 门面访问。为了调用 Wired API,您可以调用这些方法,这些方法指的是服务的特定区域。

Facades\WuBook

此门面将动态地将静态方法调用传递到 ioc 容器中的 'wubook' 对象,默认情况下是 WuBookManager 类。

WuBookServiceProvider

此类不包含任何有趣的公共方法。应将此类添加到 config/app.php 中的 providers 数组。此类将设置 ioc 绑定。

WuBook API 方法结果

fxmlrpc 客户端始终返回一个关联数组,该数组可能由包更改以检索从 XML/RPC 函数检索到的结果数据。

如果在调用过程中发生错误,将抛出 WuBookException。如果调用成功执行(见 http://tdocs.wubook.net/wired/return.html),则返回包含这些值的数组

// An error occurred
return [
    'has_error' => true,
    'data' => 'A human readeable error message'
]

// Success
return [
    'has_error' => false,
    'data' => [ /* THE XML/RPC FUNCTION RESPONSE */ ]
]

只有 WuBookAuth API 在成功调用时返回不同的值

acquire_token()             
// returns a string (ex. '9869117656.9552'), throws an exception otherwise

release_token($token)       
// returns a boolean if the token is successfully released, throws an exception otherwise

is_token_valid($token, $request_new = false)        
// - if the token is valid returns an integer representing the total operations made with the token
// - if `request_new` is set to `true` and the token is not valid the method `aquire_token()` is called
// - false otherwise

provider_info($token = null)
// returns an array with the provider infos
真实示例

在这里,您可以看到如何轻松使用此包的示例。默认情况下,出厂时 cache_token 参数设置为 false,因此

use jonmadval\LaravelWuBook\Facades\WuBook;
// you can alias this in config/app.php if you like

// Retrieve the token
$token = WuBook::auth()->acquire_token()        // (ex. '9869117656.9552')

WuBook::rooms()->fetch_rooms(1)                 // See http://tdocs.wubook.net/wired/rooms.html#fetching-existing-rooms
// this example is simple, and there are far more methods available
// The result will be an associative array with this structure

[
    0 => [
        id => 123,
        name => 'room',
        shortname => 'ro',
        occupancy => 2,
        men => 2,
        children => 0,
        subroom => 0,
        // ...
    ],
    1 => [
        // ...
    ],
]

如果您像我一样更喜欢使用依赖注入而不是门面,则可以轻松地像这样注入管理器

use jonmadval\LaravelWuBook\WuBookManager;
use Illuminate\Support\Facades\App; // you probably have this aliased already

class RoomManager
{
    protected $wubook;

    public function __construct(WuBookManager $wubook)
    {
        $this->wubook = $wubook;
    }

    public function fetch_rooms($ancillary = 0)
    {
        $this->wubook->fetch_rooms($ancillary);
    }
}

App::make('RoomManager')->fetch_rooms(1);

有关如何使用我们幕后调用的 \LaravelWubook\WuBookManager 类的更多信息,请查看Wired API 文档

更多信息

本包中存在其他未在此文档中记录的类。这是因为它们不是供公共使用的,而是由本包内部使用。

安全

如果您在此包中发现安全漏洞,请发送电子邮件至 Filippo Galante(filippo.galante@b-ground.com),我们将及时处理所有安全漏洞。

许可协议

Laravel WuBook 采用 MIT 许可协议 (MIT) 许可。