diglin / swisspost-barcode-php-sdk
瑞士邮政条码 Web 服务 PHP SDK
1.0.3.3
2020-08-02 19:31 UTC
Requires
- php: >=5.3.3
- ext-soap: *
- symfony/thanks: ^1.2
- wsdltophp/packagebase: ~2.0
Requires (Dev)
- phploc/phploc: *
- phpmd/phpmd: @stable
- phpunit/phpunit: ^7.5
- squizlabs/php_codesniffer: 3.*
- wsdltophp/packagegenerator: dev-master
README
此 SDK 允许使用瑞士邮政条码 Web 服务来生成运输标签或条码。API 返回跟踪码,可用于后续使用。
通过 Composer 安装
将以下要求添加到根项目级别的 composer.json 中。您不需要添加自动加载器,如果您的应用程序与 composer 兼容,则 composer 将为您处理。
composer require diglin/swisspost-barcode-php-sdk
或者
{
"require" : {
"diglin/barcode-swisspost-php-sdk": "1.*"
},
"repositories" : [
{
"type": "vcs",
"url": "git@github.com:diglin/barcode-swisspost-php-sdk.git"
}
]
}
使用方法
您可以在 tutorial.php
文件中查看一些示例,或者在 test/ServiceType
文件夹中的测试用例。
例如,要生成条码
/**
* Minimal options
*/
$options = array(
\WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_URL => $this->config->getWsdl(),
\WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_LOGIN => $this->config->getLogin(),
\WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_PASSWORD => $this->config->getPassword(),
\WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_CLASSMAP => \Diglin\Swisspost\ClassMap::get(),
);
$generate = new \Diglin\Swisspost\ServiceType\Generate($options);
$barcodeDefinition = new \Diglin\Swisspost\StructType\BarcodeDefinition();
$barcodeDefinition
->setBarcodeType(\Diglin\Swisspost\EnumType\BarcodeType::VALUE_LSO_1)
->setImageFileType('PNG')
->setImageResolution(300);
$struct = new \Diglin\Swisspost\StructType\GenerateBarcode($this->config->getLanguage(), $barcodeDefinition);
try {
/* @var $response GenerateBarcodeResponse */
if ($generate->GenerateBarcode($struct) !== false) {
$response = $generate->getResult();
} else {
$response = $generate->getLastError();
}
// PNG Picture to use further
$barcode = $response->getData()->getBarcode();
// ... your code here
} catch (\SoapFault $e) {
switch ($e->faultcode) {
case 'HTTP':
echo 'Login and/or password is not correct' . PHP_EOL;
break;
default:
echo sprintf('Error occurred with the SOAP interface with the error message "%s"', $e->faultstring);
break;
}
}
为新的 API 版本生成类
运行 composer install && php -f Generator.php
变更日志
请参阅 CHANGELOG.md 文件
许可证
作者
- Diglin GmbH
- https://www.diglin.com/
- @diglin_
- 在 github 上关注我!