summer-wqm / sift-php
Sift Science PHP 库
dev-master
2018-11-05 08:29 UTC
Requires
- php: >=5.0.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-10-02 21:04:37 UTC
README
安装
使用 Composer
-
在 composer.json 中添加 siftscience/sift-php 作为依赖。
"require": { ... "siftscience/sift-php" : "2.*" ... }
-
运行
composer update
。 -
现在
SiftClient
将自动加载到您的项目中。require 'vendor/autoload.php'; $sift = new SiftClient(array( 'api_key' => 'my_api_key', 'account_id' => 'my_account_id' )); // or Sift::setApiKey('my_api_key'); Sift::setAccountId('my_account_id'); $sift = new SiftClient();
手动
-
下载最新版本。
-
将其解压缩到项目根目录中名为 "sift-php" 的文件夹中。
-
将
SiftClient
包含到您的项目中,如下所示require 'sift-php/lib/Services_JSON-1.0.3/JSON.php'; require 'sift-php/lib/SiftRequest.php'; require 'sift-php/lib/SiftResponse.php'; require 'sift-php/lib/SiftClient.php'; require 'sift-php/lib/Sift.php'; $sift = new SiftClient(array( 'api_key' => 'my_api_key', 'account_id' => 'my_account_id' ));
用法
跟踪事件
以下示例向 sift 发送一个 $transaction
事件。
$sift = new SiftClient(array('api_key' => 'my_api_key'));
$response = $sift->track('$transaction', array(
'$user_id' => '23056',
'$user_email' => 'buyer@gmail.com',
'$seller_user_id' => '2371',
'$seller_user_email' => 'seller@gmail.com',
'$transaction_id' => '573050',
'$currency_code' => 'USD',
'$amount' => 15230000,
'$time' => 1327604222,
'trip_time' => 930,
'distance_traveled' => 5.26,
));
将用户标记为良好/不良
$sift = new SiftClient(array('api_key' => 'my_api_key'));
$response = $sift->label('23056', array(
'$is_bad' => true,
'$abuse_type' => 'promotion_abuse'
));
取消标记用户
$sift = new SiftClient(array('api_key' => 'my_api_key'));
$response = $sift->unlabel('23056', array('abuse_type' => 'content_abuse'));
获取用户的分数
$sift = new SiftClient(array('api_key' => 'my_api_key'));
$response = $sift->score('23056');
$response->body['scores']['payment_abuse']['score']; // => 0.030301357270181357
获取工作流程运行状态
$sift = new SiftClient(array('api_key' => 'my_api_key', 'account_id' => 'my_account_id'));
$response = $sift->getWorkflowStatus('my_run_id');
$response->body['state']; // => "running"
获取用户的最新决策
$sift = new SiftClient(array('api_key' => 'my_api_key', 'account_id' => 'my_account_id'));
$response = $sift->getUserDecisions('example_user');
$response->body['decisions']['account_abuse']['decision']['id']; // => "ban_user"
获取订单的最新决策
$sift = new SiftClient(array('api_key' => 'my_api_key', 'account_id' => 'my_account_id'));
$response = $sift->getOrderDecisions('example_order');
$response->body['decisions']['payment_abuse']['decision']['id']; // => "ship_order"
贡献
从项目根目录使用 PHPUnit 运行测试
phpunit --bootstrap vendor/autoload.php test
更新 Packagist
-
更新
composer.json
以反映新版本,以及任何新的需求,然后将更改合并到 master 中。
许可证
MIT