Это ошибка, которую я получаю от функции authMiddleware () с GuzzleHttp. Я использую это для VismaSign и получаю эти ошибки. Я не уверен, в чем именно заключается проблема:
Uncaught TypeError: Аргумент 1, передаваемый в app \ handlers \ integrarations \ VismaSign :: authMiddleware (), должен быть экземпляром GuzzleHttp \ Psr7 \ Request, instance GuzzleHttp \ HandlerStack.
Вот мой код:
<?php
namespace app\handlers\integrations;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
class VismaSign {
const API_URL = "https://sign.visma.net/api/v1/";
const CLIENT_IDENTIFIER = "ddf58116-6082-4bfc-a775-0c0bb2f945ce";
const SECRET_KEY = "jp7SjOOr4czRTifCo30qx0sZAIw9PW+vVpsbP09pQaY=";
private $client;
private $clientHandler;
public function __construct() {
$this->client = new Client();
$this->clientHandler = $this->client->getConfig('handler');
}
public function authMiddleware(Request $request) {
$request = new Request('POST', 'https://httpbin.org/post');
//return $request->withHeader('Authorization', $this->authorizationHeader(self::CLIENT_IDENTIFIER, base64_decode(self::SECRET_KEY), $request->getMethod(), (string)$request->getBody(), ($request->getHeader('Content-Type') ?: [''])[0], $request->getHeader('Date')[0], $request->getUri()->getPath() . ($request->getUri()->getQuery() ? '?' . $request->getUri()->getQuery() : '')));
return $request->withHeader(
'Authorization',
$this->authorizationHeader(
self::CLIENT_IDENTIFIER,
base64_decode(self::SECRET_KEY),
$request->getMethod(),
(string)$request->getBody(),
($request->getHeader('Content-Type') ?: [''])[0],
$request->getHeader('Date')[0],
$request->getUri()->getPath() .
($request->getUri()->getQuery() ? '?' . $request->getUri()->getQuery() : '')
)
);
}
private function authorizationHeader($username, $secret, $method, $body, $contentType, $date, $path) {
$str = join("\n", [
$method,
base64_encode(hash('md5', $body, true)),
$contentType,
$date,
$path
]);
$header = 'Onnistuu ' . $username . ':' . base64_encode(hash_hmac('sha512', $str, $secret, true));
return $header;
}
public function createDocument() {
$response = $this->client->request('POST', self::API_URL . 'document/', [
'json' => [
'document' => [
'name' => 'Test document ' . date(\DateTime::ATOM),
]
],
'headers' => [
'Date' => date('r'),
],
'handler' => $this->authMiddleware($this->clientHandler),
]);
if ($response->getStatusCode() !== 201) {
echo 'Could not create document';
return;
}
return $response->getHeader('Location')[0];
}
}