antistatique / trustedshops-php-sdk
PHP中超级简单、最小抽象的TrustedShops API v2.x包装器
1.1.0
2024-06-27 11:29 UTC
Requires
- php: >=8.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- php-coveralls/php-coveralls: ^2.1
- php-mock/php-mock-phpunit: ^2.10
- phpmd/phpmd: ^2.6
- phpunit/php-code-coverage: ^9
- phpunit/phpunit: ^9
- symfony/dotenv: ^4.3
- vimeo/psalm: ^4.30
This package is auto-updated.
Last update: 2024-08-31 11:21:22 UTC
README
PHP中超级简单、最小抽象的TrustedShops API v2.x包装器。
我讨厌复杂的包装器。这可以让您尽可能直接地从TrustedShops API文档到代码。
入门
您可以使用Composer安装trustedshops-php-sdk
composer require antistatique/trustedshops-php-sdk
示例
请查看examples/
目录中的关键客户端功能示例。您可以通过运行内置的php网络服务器在浏览器中查看它们。
php -S localhost:8000 -t examples/
然后浏览到您指定的主机和端口(在上面的示例中,http://localhost:8000
)。
基本示例
首先使用use
类并使用您的API密钥创建一个实例
use \Antistatique\TrustedShops\TrustedShops;
列出所有商店(通过在shops/{tsid}
方法上通过get
进行public
调用)
$tsid = 'abc123abc123abc123abc123abc123'; $ts = new TrustedShops(); $response = $ts->get("shops/$tsid"); print_r($response);
获取所有评论(通过在lists/{listID}/reviews
方法上通过get
进行public
调用)
$tsid = 'abc123abc123abc123abc123abc123'; $ts = new TrustedShops(); $response = $ts->get("shops/$tsid/reviews"); print_r($response);
读取商店评论投诉指标的测量矩阵(通过在shops/{tsid}/quality/complaints
方法上通过get
进行restricted
认证调用)
更新具有更多信息列表成员(使用patch
进行更新)
$tsid = 'abc123abc123abc123abc123abc123'; $ts = new TrustedShops('restricted'); $ts->setApiCredentials( 'SECRET_USER', 'SECRET_PASSWORD'); $response = $ts->get("shops/$tsid/quality/complaints"); print_r($response);
故障排除
要获取HTTP客户端或API返回的最后一个错误,请使用getLastError()
echo $ts->getLastError();
对于进一步的调试,您可以检查响应的标头和正文
print_r($ts->getLastResponse());
如果您怀疑您发送的数据格式不正确,您可以查看包装器发送给TrustedShops的内容
print_r($ts->getLastRequest());
如果您的服务器CA根证书未更新,您可能会发现SSL验证失败并且您没有收到响应。此问题的纠正解决方案不是禁用SSL验证。解决方案是更新您的证书。如果您无法这样做,则类文件顶部有一个选项。请勿在不至少尝试更新您的证书的情况下关闭它——这是懒惰且危险的。您不是懒惰、危险的开发者,对吧?