99designs / sipht
Sift Science REST API的PHP客户端
Requires
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- phpunit/phpunit: ~3.7.0
This package is not auto-updated.
Last update: 2023-06-10 09:12:38 UTC
README
Sift Science REST API的PHP客户端。
注意:Sift Science现在提供自己的PHP绑定,见这里。
此客户端支持Sift API公开的三个基本操作:发布事件、标记用户和获取分数。
当前支持的API版本是v203
。
创建客户端实例
通过将API密钥传递给其构造函数,通过Sift\Client
与API进行交互。
$client = new Sift\Client('my-api-key');
任何客户端请求可能会抛出以下错误
-
Sift\Exception\BadRequestException
:HTTP 40x;请求被API拒绝 -
Sift\Exception\ServerErrorException
:HTTP 50x;API端点遇到内部问题 -
Sift\Exception\HttpException
:在HTTP请求过程中生成的任何其他异常(例如,重定向过多)
发布事件
创建Sift\Event
的实例,例如。
$event = new Sift\Event(array( '$type' => Sift\Event::TYPE_TRANSACTION, '$user_id' => '1234', // ... ));
或者,为每种事件类型提供了工厂构造函数。
$event = Sift\Event::transactionEvent(array( '$user_id' => '1234', // ... ));
然后通过Sift\Client::postEvent()
发布事件。
$response = $client->postEvent($event);
有关发布事件数据的更多信息,请参阅https://siftscience.com/docs/references/events-api。
标记用户
使用Sift\Label
的工厂方法创建标签对象,例如。
// Label a user as fraudulent, optionally specifying reason codes and an explanation: $reasons = array(Sift\Label::REASON_SPAM); $label = Sift\Label::bad($reasons, 'User engaged in phishing attack') // Alternatively, correct a false positive by labelling a user as non-fraudulent: $good = Sift\Label::good('Mistakenly identified as fraudulent');
然后通过Sift\Client::labelUser()
发布事件。
$response = $client->labelUser('some-user-id', $label);
有关标记用户的更多信息,请参阅https://siftscience.com/docs/references/labels-api。
获取分数
通过Sift\Client::userScore()
获取用户的欺诈分数数据。
$score = $client->userScore('some-user-id');
这返回一个Sift\Score
实例。注意,如果给定用户没有捕获到事件,将抛出Sift\Exception\ScoreException
。
有关获取用户欺诈分数的更多信息,请参阅https://siftscience.com/docs/getting-scores。