표준 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;
}
}
다른 찾을 수
createBlahProvider
가 어쩌구 사용자 공급자에
config\auth.php
에서 공급자를 변경 내 새 드라이버도 추가 기능을 포함하도록\vendor\laravel\framework\src\Illuminate\Auth\CreatesUserProviders.php
에createUserProvider
기능을 확장 유사한 상황 [여기] (https://www.reddit.com/r/laravel/comments/)으로 어려움을 겪고있는 사람들 3b4lu2/correct_structure_for_consuming_rest_api_with /) – WitHeld