webmenedzser / uvb-connector
UVB API 连接器
1.5.0.1
2024-03-05 15:11 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^5.3 || ^6.3 || ^7.3
README
此包是 Utánvét Ellenőr API 1.x 的 PHP 连接器库。
安装
安装连接器的最简单方法是使用 Composer
composer require webmenedzser/uvb-connector
然后使用您框架的自动加载,或者简单添加
<?php require 'vendor/autoload.php';
手动安装
如果您想完全省略使用 Composer,您可以从存储库下载源代码并使用任何 PSR-4 兼容的自动加载器。
入门
您可以通过创建一个新的 UVBConnector 实例并调用其 get() 或 post($outcome) 方法来开始向 Utánvét Ellenőr API 发送请求。
<?php use webmenedzser\UVBConnector\UVBConnector; $email = 'tim@apple.com'; $publicApiKey = 'aaaa'; $privateApiKey = 'bbbb'; $connector = new UVBConnector( $email, $publicApiKey, $privateApiKey );
UVBConnector 类负责您的应用程序与 Utánvét Ellenőr API 之间的通信。
通用用法
从 Utánvét Ellenőr 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,
}
}
如果您想显示这些值,请使用数字 totalRate 以及/或 good 和 bad 值。避免使用短语别名这些值,因为它们可能会误导用户。
在 UI 中使用 API 响应的示例
好的
- 3 次成功,2 次失败(投递),声誉:0.2
- 60% 的成功投递率
坏
- 订单不应履行。(为什么?没有给出明确的解释。)
- 失败投递过多。(“过多”是多少?)
- 客户声誉差。(什么样的声誉被认为是“差”的?)
将订单结果提交给 Utánvét Ellenőr API
<?php use webmenedzser\UVBConnector\UVBConnector; $email = 'tim@apple.com'; $publicApiKey = 'aaaa'; $privateApiKey = 'bbbb'; // 1 if good, -1 if bad; $outcome = 1; $orderId = '#98143'; $phoneNumber = '+36209238883'; $countryCode = 'HU'; $postalCode = '8640'; $addressLine = 'Szigligeti utca 10.'; $connector = new UVBConnector( $email, $publicApiKey, $privateApiKey ); // Submit order outcome to API $response = $connector->post( $outcome, $orderId, $phoneNumber, $countryCode, $postalCode, $addressLine );
有效负载数据成员
- outcome:成功则 +1,拒绝/未领取则 -1。
- orderId:面向公众的订单 ID,任何人都可以用来识别订单。
- phoneNumber:国际格式电话号码,以加号开头,例如:+36209238883
- countryCode:ISO 3166-1 alpha-2 格式的国家代码(例如:HU)
- postalCode:在寄件地址国家使用的邮政编码(例如:8640)
- addressLine:地址行,不包含国家、国家代码或邮政编码。多个地址行应连接成一行。
订单状态变更是最推荐和理想的触发这些 API 调用的事件。
沙盒环境
通过将 UVBConnector 构造函数的第四个参数设置为 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 的行为将与生产环境相同,只有一个例外:提供的数据将是随机的 - 不要在生产环境中使用!