talano/laravel-wubook

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

0.1.1 2020-03-20 13:47 UTC

This package is auto-updated.

Last update: 2024-09-20 23:58:51 UTC


README

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

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 talanoff/laravel-wubook

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

{
    "require": {
        "talanoff/laravel-wubook": "0.1.*"
    }
}

该包使用 fxmlrpc 客户端 调用 Wired API 服务。使用标准依赖项创建 HTTP 客户端和消息,请自由创建 pull request 以添加新功能。

安装 Laravel WuBook 后,您需要注册服务提供程序。打开 config/app.php 文件,并在 providers 键中添加以下内容。

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

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

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

配置

Laravel WuBook 需要连接配置。

在您的应用程序中创建一个 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中的提供者数组。此类将设置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 Talanoff\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 Talanoff\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) 许可。