在 Laravel 中,我需要与第 3 方 API 进行通信。Thay 给了我一些 PHP 实现(类),我可以用它来连接他们的 API 并与之通信。但是,当我将它作为 App 文件夹子文件夹中的一个类尝试并将其添加到我的控制器时,我收到一个找不到类的错误。
我在 App 文件夹中添加了一个文件夹“Qenner”(API 的提供者)。并在那里复制了他们的课程。在我的控制器中,我正在使用这些类并添加一个代码示例,就像他们将它发送给我一样。
控制器代码(API-KEY 替换为实际密钥):
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Qenner\Search;
use QennerSearch\ServiceClient;
class TestController extends Controller
{
public function index() {
$search = new Search('https://search.qenner.com', 'API-KEY', true, 'nl-NL');
$response = $search->getCriteria([], ['Country'], []);
if (!$response->isError()) {
$criterionSets = $response->getCriterionSets();
$countryCriterionSet = criterionSets[0];
$countries = $countryCriterionSet->getCriteria();
$resultCount = $response->getResultCount();
}
dd($response);
}
Qenner 文件夹中的 Search.php:
/**
* @file
* Contains QennerSearch\Search.
*/
namespace QennerSearch;
use QennerSearch\model\messages\CriterionTypesResponse;
use QennerSearch\model\messages\CriteriaRequest;
use QennerSearch\model\messages\CriteriaResponse;
use QennerSearch\model\messages\ErrorResponse;
use QennerSearch\model\messages\SearchRequest;
use QennerSearch\model\messages\SearchResponse;
use QennerSearch\model\messages\PriceRequest;
use QennerSearch\model\messages\PriceResponse;
use QennerSearch\model\messages\AccommodationInfoRequest;
use QennerSearch\model\messages\AccommodationInfoResponse;
use QennerSearch\model\messages\AutoCompleteRequest;
use QennerSearch\model\messages\AutoCompleteResponse;
/**
* Class Search, using ServiceClient to communicate, implementing the SearchInterface
*
* @package QennerSearch
*/
class Search extends ServiceClient implements SearchInterface {
.....
该文件夹有一个 ServiceClient.php
阿波罗的战车