locardi/php-sdk

此软件包的最新版本(v0.2.0)没有可用的许可证信息。

Locardi取证SDK

v0.2.0 2018-09-10 09:38 UTC

This package is not auto-updated.

Last update: 2024-09-25 11:36:59 UTC


README

安装

composer require locardi/php-sdk "dev-master"

使用

use Locardi\PhpSdk\Authentication\JwtAuthentication\TokenStorage\FileTokenStorage;
use Locardi\PhpSdk\LocardiClient;
use Locardi\PhpSdk\Api\OrganizationUserRequestApi;

$client = new LocardiClient(array(
    'debug' => true,
    'username' => 'myusername',
    'password' => 'mypassword',
    'endpoint' => '', // this is optional and overrides the API endpoing (used for sandbox)
    'tokenStorage' => new FileTokenStorage(__DIR__),
    'timeout' => 10, // OPTIONAL number of senconds before curl timeout (default is 30 seconds) 
));

$client->send(array(
    'organization_user_request' => array(
        // this is the type of the page that the user has opened (html_page,login,login_failed,download)
        'request_type' => OrganizationUserRequestApi::REQUEST_TYPE_HTML_PAGE,
        // the IP Address of the user
        'ip_address' => '8.8.8.8',
        // the HTTP method used by the user (GET,POST,OPTION,PUT,DELETE)
        'http_method' => 'GET',
        // the timestamp when the user request was generated
        'timestamp' => date('c'),
        // the user agent used by the user
        'user_agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36',
        // the full address requested by the user (including query string, anchors etc)
        'uri' => 'https://www.getlocardi.com/?param1=value1&param2=value2',
        // the organization in which the user is
        'organization' => array(
            'id' => '123', // note that this is a string
            'name' => 'Organization1',
        ),
        // some details on the user
        'user' => array(
            'id' => '123', // note that this is a string
            'name' => 'User1', // you can fill this field with the username,email or any other unique id
            // this is the user type and represents whether the user is internal (like an admin/editor account) or external (like a normal user)
            'type' => OrganizationUserRequestApi::USER_TYPE_INTERNAL,
            // the timezone where the user lives
            'timezone' => 'Europe/London',
        ),
    ),
));

请求类型

根据您需要跟踪的内容,您可以发送不同类型的请求。

  • 当用户访问正常网页时,使用 OrganizationUserRequestApi::REQUEST_TYPE_HTML_PAGE
  • 当用户尝试登录时,使用 OrganizationUserRequestApi::REQUEST_TYPE_LOGIN
  • 当登录尝试因任何原因失败时,使用 OrganizationUserRequestApi::REQUEST_TYPE_LOGIN_FAILED
  • 当用户下载文件时,使用 OrganizationUserRequestApi::REQUEST_TYPE_DOWNLOAD

用户类型

您可能需要区分自己的用户账户(如管理员账户等)和客户的账户。

  • OrganizationUserRequestApi::USER_TYPE_INTERNAL 这些是您认为属于您组织的用户(即管理员、编辑等)
  • OrganizationUserRequestApi::USER_TYPE_EXTERNAL 这些是使用您服务的用户(您希望跟踪的实际客户)

令牌存储

Locardi API实现了JSON Web Token认证系统。

SDK需要一种方式来存储JSON Web Token,因此我们提供了一个TokenStorageInterface,您可以使用它将令牌保存到任何存储系统中。

我们提供了一个简单的FileTokenStorage类,它将令牌保存到文件系统中,但您也可以简单地使用TokenStorageInterface编写自己的适配器。