標準TCP接続を使用してJSONリクエストを受け取るバックエンドC++アプリケーションがあります。このアプリケーションは、すべてのビジネスロジック(ユーザー認証、トランザクション処理、データ要求および検証)を管理します。APIに接続するためのLaravel 5.2の設定方法
ユーザ認証とトランザクション処理のためにこのサーバに接続するには、Laravel 5.2をどのように設定する必要がありますか?すべてのデータがC++アプリケーションを介してアクセスされるため、Laravel側にデータベースは必要ありません。
これも可能な場合は、JWTをユーザー認証用に組み込むこともできます。
以下のコードは、現在標準のPHPを使用してアプリケーションサーバーに接続している方法です。私は同じ機能を望んでいますが、より多くのLaravelの方法で。
class tcp_client
{
private $sock;
function __construct()
{
// create the socket
$this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!is_resource($this->sock))
{
// throw exception
}
// set socket options
$this->set_options();
}
function connect($host, $port)
{
$timeout = 3;
$startTime = time();
while (!socket_connect($this->sock, $host, $port))
{
if ((time() - $startTime) >= $timeout)
{
// throw exception
}
sleep(1);
}
}
private function set_options()
{
if (!socket_set_option($this->sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 5,
'usec' => 0)))
{
// throw exception
}
if (!socket_set_option($this->sock, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 5,
'usec' => 0)))
{
// throw exception
}
}
public function request($request)
{
// the first 6 characters will indicate the length of the JSON string
$request = str_pad(strlen($request), 6, '0', STR_PAD_LEFT) . $request;
//Send the message to the server
if (!socket_send($this->sock, $request, strlen($request), 0))
{
// throw exception
}
//Now receive header from server
$header = 0;
if (socket_recv($this->sock, $header, 6, MSG_WAITALL) === FALSE)
{
// throw exception
}
//Now receive body from server
$body = "";
if (socket_recv($this->sock, $body, $header, MSG_WAITALL) === FALSE)
{
// throw exception
}
return $body;
}
}
に
config\auth.php
でプロバイダを変更同様の状況[ここ]で苦労している人々(https://www.reddit.com/r/laravel/comments/ 3b4lu2/correct_structure_for_consuming_rest_api_with /) – WitHeld