novica89/erply

此软件包最新版本(dev-master)没有提供许可证信息。

Laravel 5 用于与 Erply 服务 API 交互的软件包

dev-master 2017-03-29 08:38 UTC

This package is not auto-updated.

Last update: 2024-09-24 22:10:46 UTC


README

管理 Erply API 调用,以从 Erply 服务检索或创建/更新资源

兼容性

此软件包已在基于 Laravel 5.1 的项目中使用。但是,在框架的新版本中使用它应该没有问题。已经通过在 Laravel 5.3 上使用此软件包进行几次调用进行了测试,并且它也在此版本上正常工作。祝您编码愉快!

安装

在您的应用程序根目录中运行 composer require novica89/erply dev-master

然后,将服务提供者添加到 config/app.php

'providers' => [
    Novica89\Erply\ErplyServiceProvider::class,
];

添加服务提供者后,还将别名添加到 config/app.php

'aliases' => [
    'ErplyClient' => Novica89\Erply\ErplyClient::class,
];

通过运行 php artisan vendor:publish 发布此软件包的配置文件

这将把 \vendor\novica89\erply\config\erply.php 配置文件复制到 config\erply.php,并将默认的 Erply 凭据设置为 Erply 演示凭据。

您可以编辑此配置文件并设置自己的 Erply 凭据,或编辑 .env 文件并添加以下行

  • ERPLY_USER=your_erply_user
  • ERPLY_PASS=your_erply_pass
  • ERPLY_CLIENT_CODE=your_erply_client_code

使用方法

向 Erply 服务发送请求

正如您在 Erply 开发者文档中所看到的,您可以通过使用 getRecordName 调用来检索记录。例如,getCustomers 将检索您的 Erply 客户列表。

您可以通过以下方式使用此软件包进行此调用

$customers = ErplyClient::getCustomers(['getBalanceInfo' => 1, 'getAddresses' => 1]);

或者这样做

$customers = ErplyClient::request('getCustomers', ['getBalanceInfo' => 1, 'getAddresses' => 1]);

使用您喜欢的任何方法。请注意,如果使用第一种方法,只需在 ErplyClient 门面中使用对应于您要向 Erply 发出的调用的方法名称(在这种情况下是 getCustomers 方法)。

您可以在 Erply 开发者文档中查看所有支持的调用

请求后获取请求状态

因此,您已向 Erply 发送了调用,但如何知道它是否成功?不要担心,这就像学习数学一样简单。开个玩笑...

// making a call to get all invoices from Erply and storing response in $invoices variable
$invoices = ErplyClient::getSalesDocuments(['getRowsForAllInvoices' => 1]);

// checking if a request that we just made to Erply to retrieve all the invoices was successfull
if($invoices->wasSuccess()) {
    // happy dance
}

获取整个响应对象

现在,您的 Erply 请求已成功,但如何检索响应数据?就是这样

// making a call to get all invoices from Erply and storing response in $invoices variable
$invoices = ErplyClient::getSalesDocuments(['getRowsForAllInvoices' => 1]);

// checking if a request that we just made to Erply to retrieve all the invoices was successfull
if($invoices->wasSuccess()) {
    // instead of happy dance, let's try to be a bit more productive this time and get the whole response object back
    $response = $invoices->response();
    
    // HINT: do a dd($response); here to see your response and it's structure
}

从响应中获取仅状态对象

您可以从响应中返回部分内容,例如只包含有关您的请求和从 Erply 成功请求后返回的响应的信息的状态对象。

// making a call to get all invoices from Erply and storing response in $invoices variable
$invoices = ErplyClient::getSalesDocuments(['getRowsForAllInvoices' => 1]);

// checking if a request that we just made to Erply to retrieve all the invoices was successfull
if($invoices->wasSuccess()) {
    // instead of whole response object, let's say we are only interested in response status section of response data
    $responseStatus = $invoices->responseStatus();
    
    // HINT: do a dd($responseStatus); here to see your response status object only and it's data
}

从响应中获取仅记录对象

就像在向 Erply 发出成功调用后只返回 Erply 响应的状态部分一样,您还可以检索 Erply 服务返回给您的记录。这将返回一个记录对象的数组。

// making a call to get all invoices from Erply and storing response in $invoices variable
$invoices = ErplyClient::getSalesDocuments(['getRowsForAllInvoices' => 1]);

// checking if a request that we just made to Erply to retrieve all the invoices was successfull
if($invoices->wasSuccess()) {
    // instead of whole response object, let's say we are only interested in response status section of response data
    $responseRecords = $invoices->records();
    
    // HINT: do a dd($responseRecords); here to see your array of response records objects and their data
}