cobwebinfo / cobra5-php-sdk
COBRA5的PHP SDK
Requires
- php: ^8.0.2
- illuminate/support: ^10.0
Requires (Dev)
- mockery/mockery: ^1.6
- phpunit/phpunit: ^10.0
This package is not auto-updated.
Last update: 2024-09-26 14:39:56 UTC
README
COBRA5 API可用于从Cobweb Information Ltd的内容API检索内容。
此存储库包含用于将COBRA5 API集成到您的PHP应用程序中的开源PHP SDK。COBRA5 PHP SDK采用MIT许可证。
此包需要PHP >= 7.0.0。如果您正在使用较旧的PHP版本,请参阅1.0.x版本。
为了访问COBRA5 API,您需要由Cobweb Information Ltd颁发的API密钥。您还将收到有关COBRA5 API每个资源的完整文档,以及示例请求和响应。
安装
将cobwebinfo/cobra5-php-sdk添加到composer.json的要求中
{
"require": {
"cobwebinfo/cobra5-php-sdk": "1.1.*"
}
}
身份验证
COBRA5 API基于称为Web服务的开放标准,包括简单对象访问协议(SOAP)、Web服务定义语言(WSDL)和XML模式定义语言(XSD)。
为了与COBRA5 API进行身份验证,您需要创建一个SoapClient并设置正确的授权头。可以使用此存储库中的服务类实现这一点
首先,创建一个新的SoapClient并传递WSDL的URI
$soap = new SoapClient('http://api.cobwebinfo.com/server/soap?wsdl');
接下来,创建一个新的SoapApiKeyAuthentication对象,并将SoapHeader的名称和您的api_key作为参数传递
use CobwebInfo\Cobra5Sdk\Authentication\SoapApiKeyAuthentication; $auth = new SoapApiKeyAuthentication('Auth', 'api_key');
然后,创建一个新的Cobra5SoapClient,并将SoapClient和SoapApiKeyAuthentication对象作为参数传递
use CobwebInfo\Cobra5Sdk\Client\Cobra5SoapClient; $client = new Cobra5SoapClient($soap, $auth);
最后,创建一个新的Cobra5实例,并将Cobra5SoapClient对象作为参数传递
use CobwebInfo\Cobra5Sdk\Cobra5; $cobra5 = new Cobra5($client);
返回值
COBRA5 PHP SDK的每个方法都将返回一个集合或实体。
集合是一个可迭代的对象,实现了一些帮助方法来处理资源集合。集合将是Illuminate\Support\Collection的实例。
每个实体都有一些方法,使处理实体对象更加容易。某些实体还具有额外的帮助方法。您可以在CobwebInfo\Cobra5Sdk\Entity下找到实体类。
可用方法
以下是可用方法的列表以及如何在$cobra5对象上调用它们。有关COBRA5 API的方法、请求和响应的更详细概述,请参阅随API密钥提供的文档。
$cobra5->getStores();
getStores()方法将返回一个您通过API密钥可以访问的数据存储的Illuminate\Support\Collection。
$cobra5->getStore(9);
getStore()方法将返回一个CobwebInfo\Cobra5Sdk\Entity\Datastore实例。
$cobra5->getStoreByName('BOP');
getStoreByName()方法将返回一个CobwebInfo\Cobra5Sdk\Entity\Datastore实例。
$cobra5->getDocuments();
getDocuments()方法将返回一个您通过API密钥可以访问的文档的Illuminate\Support\Collection。
$cobra5->getDocument(1444);
getDocument()方法将返回一个CobwebInfo\Cobra5Sdk\Entity\Document实例。
$cobra5->getLastEditedDocument();
getLastEditedDocument()方法将以CobwebInfo\Cobra5Sdk\Entity\Document实例返回系统中最后编辑的文档。
$cobra5->getEditedDocuments('1388534400', '1391126400');
getEditedDocuments()方法将返回一个在两个Unix时间戳之间编辑的文档的Illuminate\Support\Collection。
$cobra5->getDocumentsByDataStore(9);
getDocumentsByDataStore()方法将返回一个通过特定数据存储可以访问的文档的Illuminate\Support\Collection。
$cobra5->getDocumentsForCategory(1197);
getDocumentsForCategory() 方法将返回一个 Illuminate\Support\Collection 类型的文档集合,这些文档通过特定分类可供您使用。
$cobra5->getCategory(1197);
getCategory() 方法将返回一个 CobwebInfo\Cobra5Sdk\Entity\Category 实例。
$cobra5->getCategoriesForStore(9);
getCategoriesForStore() 方法将返回一个 Illuminate\Support\Collection 类型的分类集合,这些分类通过特定的数据存储可供您使用。
$cobra5->getDocumentXml(1444);
getDocumentXml() 方法将返回文档的 XML 版本,并以字符串形式返回。
$cobra5->getDocumentPdf(1444);
getDocumentPdf() 方法将返回文档的 PDF 版本,并以 base64 编码的字符串形式返回。
$cobra5->getDocumentHtml(1444);
getDocumentHtml(1444) 方法将返回文档的 HTML 版本,并以字符串形式返回。
$cobra5->documentSearch('business', 0, 10);
documentSearch() 方法允许您在 API 中搜索特定术语。您将获得一个 Illuminate\Support\Collection 类型的结果集合。
错误和异常
如果在使用 COBRA5 API 时出现问题,将抛出一个 SoapFault 异常。该异常可以在您的应用程序中被捕获并优雅地处理。
try { $this->getDocument(999999999); } catch(SoapFault $e) { // deal with error }