siftscience/sift-php
Composer 安装命令:
composer require siftscience/sift-php
包简介
Sift Science PHP library
关键字:
README 文档
README
Installation
With Composer
- Add siftscience/sift-php as a composer dependency
composer require siftscience/sift-php
- Now
SiftClientwill be autoloaded into your project.
require 'vendor/autoload.php'; $sift = new SiftClient([ 'api_key' => 'my_api_key', 'account_id' => 'my_account_id' ]); // or Sift::setApiKey('my_api_key'); Sift::setAccountId('my_account_id'); $sift = new SiftClient();
Manually
-
Download the latest release.
-
Extract into a folder in your project root named "sift-php".
-
Include
SiftClientin your project like this: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([ 'api_key' => 'my_api_key', 'account_id' => 'my_account_id' ]);
Usage
Track an event
To learn more about the Events API visit our developer docs.
Optional Params
return_score::trueor:falsereturn_action::trueor:falsereturn_workflow_status::trueor:falsereturn_route_info::trueor:falseforce_workflow_run::trueor:falseinclude_score_percentiles::trueor:falsewarnings::trueor:falseabuse_types:["payment_abuse", "content_abuse", "content_abuse", "account_abuse", "legacy", "account_takeover"]
Here's an example that sends a $transaction event to Sift.
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->track('$transaction', [ '$user_id' => '23056', '$user_email' => 'buyer@gmail.com', '$seller_user_id' => '2371', '$transaction_id' => '573050', '$currency_code' => 'USD', '$amount' => 15230000, '$time' => 1327604222, 'seller_user_email' => 'seller@gmail.com', 'trip_time' => 930, 'distance_traveled' => 5.26, ]);
Label a user as good/bad
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->label('23056', [ '$is_bad' => true, '$abuse_type' => 'promotion_abuse' ]);
Unlabel a user
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->unlabel('23056', ['abuse_type' => 'content_abuse']);
Get a user's score
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->score('23056'); $response->body['scores']['payment_abuse']['score']; // => 0.030301357270181357
Get the status of a workflow run
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->getWorkflowStatus('my_run_id'); $response->body['state']; // => "running"
Get the latest decisions for a user
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->getUserDecisions('example_user'); $response->body['decisions']['account_abuse']['decision']['id']; // => "ban_user"
Get the latest decisions for an order
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->getOrderDecisions('example_order'); $response->body['decisions']['payment_abuse']['decision']['id']; // => "ship_order"
Get the latest decisions for a session
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->getSessionDecisions('example_user', 'example_session'); $response->body['decisions']['account_takeover']['decision']['id']; // => "session_decision"
List of configured Decisions
Optional Params
entity_type:userororderorsessionabuse_types:["payment_abuse", "content_abuse", "content_abuse", "account_abuse", "legacy", "account_takeover"]
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $this->client->getDecisions(['entity_type' => 'example_entity_type','abuse_types' => 'example_abuse_types']); $response->isOk()
Apply decision to a user
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->applyDecisionToUser('example_user','example_decision','example_source',['analyst' => 'analyst@example.com'] $response->isOk()
Apply decision to an order
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->applyDecisionToOrder('example_user','example_order','example_decision','example_source',['analyst' => 'analyst@example.com'] $response->isOk()
Apply decision to a session
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->applyDecisionToSession('example_user','example_session','example_decision','example_source',['analyst' => 'analyst@example.com'] $response->isOk()
Creates a new webhook with a specified URL.
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->postWebhooks(["payload_type" => "ORDER_V1_0", "status"=> "active", "url"=> "https://example1.com/", "enabled_events" => ['$create_order'], "name"=> "My webhook name", "description"=> "This is a webhook!"]); $response->isOk()
Retrieves a webhook when given an ID.
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->retrieveWebhook('webhook_id'); $response->isOk()
List All Webhooks
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->listAllWebhooks(); $response->isOk()
Update a Webhook
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->updateWebhook('webhook_id', ["payload_type" => "ORDER_V1_0", "status"=> "active", "url"=> "https://example1.com/", "enabled_events" => ['$create_order'], "name"=> "My webhook name update", "description"=> "This is a webhook! update"]); $response->isOk()
Deletes a webhook when given an ID.
$sift = new SiftClient(['api_key' => 'my_api_key', 'account_id' => 'my_account_id']); $response = $sift->deleteWebhook('webhook_id'); $response->isOk()
Contributing
Run the tests from the project root with PHPUnit like this:
composer update composer exec phpunit -v -- --bootstrap vendor/autoload.php test
Updating Packagist
-
Update
composer.jsonto reflect the new version, as well as any new requirements then merge changes into master. -
Create a new release with the version number and use it as the description. Packagist will automatically deploy a new package via the configured webhook.
HTTP connection pooling
You can substantially improve the performance of SiftClient by using HTTP connection pooling.
Because standard PHP/fastcgi deployments don't have a mechanism for persisting connections between
requests, the easiest way to pool connections is by routing requests through a proxy like Apache httpd or nginx.
Listen 8081 ... LoadModule proxy_module .../mod_proxy.so LoadModule proxy_http_module .../mod_proxy_http.so LoadModule ssl_module .../mod_ssl.so <VirtualHost localhost:8081> ServerName api.sift.com SSLProxyEngine on SSLProxyVerify require SSLProxyVerifyDepth 3 SSLProxyCACertificateFile ... ProxyPass / https://api.sift.com/ </VirtualHost>
# Read more about nginx keepalive: https://www.nginx.com/blog/tuning-nginx/#keepalive upstream sift { server api.sift.com:443; keepalive 16; } server { listen localhost:8081; server_name api.sift.com; location / { proxy_pass https://sift; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_ssl_verify on; proxy_ssl_verify_depth 3; proxy_ssl_trusted_certificate ...; proxy_ssl_name api.sift.com; proxy_ssl_server_name on; } }
For Debian-based distributions, the certificate file is /etc/ssl/certs/ca-certificates.crt
Then, instantiate SiftClient to route requests through the proxy:
$sift = new SiftClient([ 'api_key' => 'my_api_key', 'account_id' => 'my_account_id', 'api_endpoint' => 'http://api.sift.com', 'curl_opts' => [CURLOPT_CONNECT_TO => ['api.sift.com:80:localhost:8081']], ]);
Integration testing app
For testing the app with real calls it is possible to run the integration testing app, it makes calls to almost all our public endpoints to make sure the library integrates well. At the moment, the app is run on every merge to master
How to run it locally
- Add env variable
ACCOUNT_IDwith the valid account id - Add env variable
API_KEYwith the valid Api Key associated from the account - Run the following under the project root folder
# install the lib from the local source code
composer install -n
# run the app
php test_integration_app/main.php
License
MIT
siftscience/sift-php 适用场景与选型建议
siftscience/sift-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.86M 次下载、GitHub Stars 达 20, 最近一次更新时间为 2014 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「fraud」 「sift」 「sift science」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 siftscience/sift-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 siftscience/sift-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 siftscience/sift-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mob
A fraud detection tool for e-commerce platforms to analyze customer order behavior across Steadfast and Pathao couriers.
Sift Science Partnership API PHP library
Alfabank REST API integration
A PHP wrapper for Fraudshield's API
统计信息
- 总下载量: 2.86M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 25
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-01-28