esempla/govtech-api
Composer 安装命令:
composer require esempla/govtech-api
包简介
Bindings for Esempla GovTech API
README 文档
README
Prerequisites
This project contains PHP bindings for Esempla GovTech API - a set of business-related tools. Full API documentation can be found here
Please note, that current state of these bindings can be behind of API state. In such case, please feel free to send us a corresponding issue
Requirements
- PHP version >=5.4.0 (>=7.0.0)
yii2-httpclientversion ^2.0lcobucci/jwtversion ^3.3
In further releases the http client can be replaced in order to remove dependency of
yii2ecosystem
Examples
First, you need to set a params item with EsemplaGovTechConfig instance:
<?php
use Esempla\GovTech\EsemplaGovTechConfig;
const CONFIG_CREDENTIALS = 'some_config_key';
$config = new EsemplaGovTechConfig();
$config->ClientID('your_client_id');
$config->ClientSecret('your_client_secret');
$config->Sandbox(true); // by default, `sandbox` is set to false, so all API calls lead to production API installation
return array(
CONFIG_CREDENTIALS => $config
);
Authorization
<?php
use Esempla\GovTech\EsemplaGovTechSSO\EsemplaGovTechSSO;
$sso = new EsemplaGovTechSSO(CONFIG_CREDENTIALS);
if (!$sso->Login()) {
// some failure login handling
}
else {
$token = $sso->EsemplaGovTechProviderToken();
// variable $token now contains the obtained authorization token
// it is automatically cached in any `IEsemplaGovTechProvider`, but you would like to store it to use in other requests
}
Authorization token re-using
First, let's bring some boilerplate stuff:
<?php
use Esempla\GovTech\EsemplaGovTechSSO\EsemplaGovTechSSO;
use Esempla\GovTech\EsemplaGovTechInvoicing\EsemplaGovTechInvoicing;
use Esempla\GovTech\EsemplaGovTechInvoicing\EsemplaGovTechInvoicingDTO;
$authorization = '<stored-authorization-token-value>';
There are several options to re-using of authorization token. Let's understand them by following example:
<?php
/**
* @var EsemplaGovTechInvoicing $invoicing
*/
$invoicing = EsemplaGovTechSSO::Authorize(CONFIG_CREDENTIALS, $authorization, new EsemplaGovTechInvoicing());
if ($invoicing == null) {
// some failure token refreshing handling
exit(); // or `return` if in function/method
}
Or
<?php
$sso = new EsemplaGovTechSSO(CONFIG_CREDENTIALS);
$sso->EsemplaGovTechProviderToken($authorization);
if ($sso->AuthorizationNeed() && !$sso->Login()) {
// some failure token refreshing handling
exit(); // or `return` if in function/method
}
/**
* @var EsemplaGovTechInvoicing $invoicing
*/
$invoicing = $sso->ContinueWith(new EsemplaGovTechInvoicing());
Or
<?php
$invoicing = new EsemplaGovTechInvoicing(CONFIG_CREDENTIALS);
$invoicing->EsemplaGovTechProviderToken($authorization);
if ($invoicing->AuthorizationNeed()) {
$sso = new EsemplaGovTechSSO(CONFIG_CREDENTIALS);
if (!$sso->Login()) {
// some failure token refreshing handling
exit(); // or `return` if in function/method
}
$invoicing->EsemplaGovTechProviderToken($sso->EsemplaGovTechProviderToken());
}
Now, we can do some API calls, for example:
<?php
$dto = new EsemplaGovTechInvoicingDTO();
$dto->Sender('<IDNP>');
$dto->Service('<serviceID>'); // this should be equal to identifier of invoicing service, that is provided for your project
$dto->Amount(9.99); // optional (see corresponding API documentation) parameter
$invoice = $invoicing->InvoiceCreate($dto);
if ($invoice == null) {
// some failure invoice creation handling
exit(); // or `return` if in function/method
}
$invoice_id = $invoice->ID(); // returned invoice identifier
var_dump($invoice_id);
Testing
You can run tests (that are located in ./tests) for existing functionality by typing test's filename within php command. For example:
$ php ./tests/SSO/TestCheckToken.php
esempla/govtech-api 适用场景与选型建议
esempla/govtech-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 125 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 esempla/govtech-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 esempla/govtech-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 125
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2019-09-18