everbinding/econnect-psb-php

Procurement Service Bus 的 PHP 示例实现。

v0.9.2 2021-08-03 13:12 UTC

This package is auto-updated.

Last update: 2024-09-29 05:49:10 UTC


README

一个参考实现,旨在作为如何使用 PSB API 的 PHP 示例。

要求

  • PHP 7.2 或更高版本

安装

composer require everbinding/econnect-psb-php

然后包含 composer 自动加载器。

require __DIR__ . '/vendor/autoload.php';

配置

$config = \EConnect\Psb\Configuration::getDefaultConfiguration();

$config
    ->setUsername("{username}")
    ->setPassword("{password}");
    ->setClientId("{clientId}")
    ->setClientSecret("{clientSecret}")
    ->setHost("https://psb.econnect.eu")
    ->setApiKey('Subscription-Key', '{subscription key}');

登录

使用默认配置登录。

$config = \EConnect\Psb\Configuration::getDefaultConfiguration();

$authN = new \EConnect\Psb\Authentication($config);
$authN->login();

使用 API

登录成功后,使用默认配置使用 API。在本示例中,我们调用发送销售发票 API。用户必须在提供发送者 partyId 上有发送权限。同时确保 UBL 有效,否则它将被阻止发送。接收者 partyId 是可选的,如果未提供接收者 partyId,PSB 将使用最佳路由。如果未提供接收者 partyId,PSB 将使用最佳路由。

$config = \EConnect\Psb\Configuration::getDefaultConfiguration();

$salesInvoiceApi = new EConnect\Psb\Api\SalesInvoiceApi(
    new GuzzleHttp\Client();
    $config
);

$yourPartyId = "senderPartyId";
$filePath = "./Ubl.xml";
$receiverPartyId = null;

$salesInvoiceApi->sendSalesInvoice($yourPartyId, $filePath, $receiverPartyId);

示例客户端

有一个 简单的示例 PHP 客户端,您可以在 PHP 网络服务器上运行。使用示例,您可以 通过 Peppol 发送发票。还有一个 webhook 接收示例,您需要它来 从 Peppol 接收发票

构建自己的源代码

您也可以使用 openapi-generator-cli 生成 PHP 代码。

openapi-generator-cli generate -g php -i https://psb.econnect.eu/v1/swagger.json?subscriptionKey={your-subscription} -o C:\temp --additional-properties=invokerPackage=EConnect\Psb

并使用 Jumbojett\OpenIDConnectClient 获取访问令牌。您也可以从 Authentication.php 复制代码。

use Jumbojett\OpenIDConnectClient;

$oidc = new OpenIDConnectClient('https://identity.econnect.eu',
                                '{clientId}',
                                '{clientSecret}');

$oidc->addScope('ap');

// Add username and password
$oidc->addAuthParam(array('username'=>'{username}'));
$oidc->addAuthParam(array('password'=>'{password}'));

// to validate the JWT and whether the acces_token property is present
$token = $oidc->requestResourceOwnerToken(TRUE)->access_token;

了解更多信息

如果您想了解更多关于 Peppol 电子商务或其他采购网络的信息,请访问 采购服务总线介绍页面