luminjo / php-sdk
此包的最新版本(v1)没有可用的许可信息。
v1
2019-10-24 15:38 UTC
Requires
- php: >=5.4.0
- awelty/security: dev-master
- guzzlehttp/guzzle: ^6.2
- symfony/options-resolver: ^3.2|^4.0
This package is not auto-updated.
Last update: 2024-09-20 06:21:52 UTC
README
PHP SDK for https://fr.luminjo.com
安装
composer require luminjo/php-sdk:dev-master
最终将发布一个稳定版本...
创建客户端
<?php
use Luminjo\PhpSdk\Luminjo;
$luminjo = new Luminjo($publicKey, $privateKey, $guzzleOptions = []);
用法
- 验证您能否进行API请求
<?php
use Luminjo\PhpSdk\LuminjoException;
// ...
try {
// eveything is ok
$luminjo->auth()->verify();
} catch (LuminjoException $e) {
$code = $e->getCode(); // see error handling
$message = $e->getMessage();
// the PSR response can be retrieved
$originalResponse = $e->getResponse();
}
- 创建工单
<?php
$response = $luminjo->ticket()->create([
// required fields
'from' => 'client@email.com',
'subject' => '$subject',
'content' => '$htmlContent',
// optionnal
'url' => 'http://www.google.com', // a related url or whatever you want..
'user_agent' => $userAgent,
'folder' => 'My folder', // a folder name, will be created if missing
'tags' => ['tag 1', 'tag 2'], // some tags
'files' => [
[
'filename' => 'test avatar api.jpg', // display usage
'path' => 'path/to/file', // a fopen-able path
]
],
'extra_fields' => [ // values MUST be scalar
'a' => 'b',
'any' => 'key-value pair'
]
]);
// 201 empty response
$ticketUrl = $response->getHeader('Location');
- 查找工单
<?php
$tickets = $luminjo->ticket()->find([
// required fields
'email' => 'client@email.com',
]);
您将收到一个数组响应
Array
(
[0] => stdClass Object
(
[subject] => My ticket // can be null
[url] => https://posao.luminjo.com/tickets/123
[type] => 1 // see "Ticket types" chapter
)
)
- 获取FAQ(行为与网站上的相同:索引高亮问题)
<?php
$questions = $luminjo->faq()->index([
// optionnal
'category' => $categoryId,
]);
响应
Array
(
[0] => stdClass Object
(
[id] => 1
[qustion] => "How change my password"
[response] => "<p>Seriously ?</p>" // html content
[highlight] => true / false
)
)
- FAQ类别
<?php
$categories = $luminjo->faq()->categories();
响应
Array
(
[0] => stdClass Object
(
[id] => 1
[name] => "My category"
)
)
工单类型
工单可以是简单的工单,例如当您接到客户电话时。记住,只有工单类型1应该对客户可见,其他类型是隐藏的。
- 工单:1
- 电话:2
- 会面:3
- 其他:4
错误处理
每个API调用都必须捕获try catch来处理客户端错误。LuminjoException包含响应、错误代码和消息。消息是针对开发者的,代码可以帮助您向最终用户显示适当的错误消息。
<?php
use Luminjo\PhpSdk\LuminjoException;
// ...
try {
$response = $luminjo->whatever();
} catch (LuminjoException $e) {
$code = $e->getCode();
$message = $e->getMessage();
$originalResponse = $e->getResponse();
}
代码
- 1: 超出速率限制。您进行了太多的请求,您应该在下一次请求之前等待60秒。
- 2: 不允许。您当前的计划不允许您使用API。
- 3: 认证失败。API密钥可能不正确。
请注意,将来可以添加代码。
限制
当前限制是每分钟60次请求。