rrd108 / uvb-connector
1.2.0
2020-12-10 11:54 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle: ^6.3
README
本包是 UV-B API 1.0 的 PHP 连接器库。
安装
安装连接器的最简单方法是使用 Composer
composer require webmenedzser/uvb-connector
然后使用您框架的自动加载,或者简单添加
<?php require 'vendor/autoload.php';
手动安装
如果您希望完全省略使用 Composer,您可以从存储库下载源代码并使用任何兼容 PSR-4 的自动加载器。
入门指南
您可以通过创建一个新的 UVBConnector
实例并调用它的 get()
或 post($outcome)
方法来开始向 UV-B API 发送请求。
<?php use webmenedzser\UVBConnector\UVBConnector; $email = 'tim@apple.com'; $publicApiKey = 'aaaa'; $privateApiKey = 'bbbb'; $connector = new UVBConnector( $email, $publicApiKey, $privateApiKey );
UVBConnector
类负责您的应用程序和 UV-B API 服务器之间的通信。
通用用法
从 UV-B API 获取电子邮件声誉
<?php use webmenedzser\UVBConnector\UVBConnector; $email = 'tim@apple.com'; $publicApiKey = 'aaaa'; $privateApiKey = 'bbbb'; $threshold = 0.5; $connector = new UVBConnector( $email, $publicApiKey, $privateApiKey ); // Set a threshold for the request $connector->threshold = $threshold; // Get reputation by hash $response = $connector->get();
API 将以类似以下结构的 JSON 字符串响应
{ "status": 200, "message": { "good": 3, "bad": 5, "goodRate": 0.375, "badRate": 0.625, "totalRate": -0.25, } }
将订单结果提交给 UV-B API
<?php use webmenedzser\UVBConnector\UVBConnector; $email = 'tim@apple.com'; $publicApiKey = 'aaaa'; $privateApiKey = 'bbbb'; // 1 if good, -1 if bad; $outcome = 1; $connector = new UVBConnector( $email, $publicApiKey, $privateApiKey ); // Submit order outcome to API $response = $connector->post($outcome);
沙箱环境
通过将 UVBConnector 构造函数的第 4 个参数设置为 false,库将使用沙箱环境而不是生产环境。 请在此功能测试您的商店或集成时使用。
<?php use webmenedzser\UVBConnector\UVBConnector; $email = 'tim@apple.com'; $publicApiKey = 'aaaa'; $privateApiKey = 'bbbb'; $production = false; $threshold = 0.5; $connector = new UVBConnector( $email, $publicApiKey, $privateApiKey, $production ); // Set a threshold for the request $connector->threshold = $threshold; // Get reputation by hash $response = $connector->get();
沙箱 API 的行为与生产环境相同,但有一个例外:它提供的数据将被随机化 - 请勿在生产环境中使用!