Rapport-Laravel/app/Http/Requests/LambdaRequest.php

66 lines
2.2 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Support\Facades\Http;
use Auth;
use Log;
class LambdaRequest
{
protected const REMOTE_ENV = 'local';
protected const LOCAL_URLS = [
'ums' => 'http://localhost:3010/dev/',
'mag' => 'http://localhost:3012/dev/',
'wall' => 'http://localhost:3011/dev/',
'metric' => 'http://localhost:3013/dev/',
'recognition' => 'http://localhost:3014/dev/',
'form' => 'http://localhost:3015/dev/',
'detailing' => 'http://localhost:3016/dev/',
];
protected const PROD_URL = 'https://rapportapi.click/';
protected static function genurl($service, $url) {
if(self::REMOTE_ENV == 'local') {
return self::LOCAL_URLS[$service] . $url;
} else {
return self::PROD_URL . $service . '/' . $url;
}
}
public static function postrequest($service, $url, $params, $token = '') {
$params['application'] = 'rapport';
$fullurl = self::genurl($service, $url);
if($token == '') {
$response = Http::post($fullurl, $params);
} else {
$response = Http::withHeaders(['Authorization' => $token])->post($fullurl, $params);
}
$response = json_decode($response->getBody()->getContents());
return $response;
}
public static function getrequest($service, $url, $params, $token = '') {
$params['application'] = 'rapport';
$fullurl = self::genurl($service, $url);
if($token == '') {
$response = Http::get($fullurl, $params);
} else {
$response = Http::withHeaders(['Authorization' => $token])->get($fullurl, $params);
}
//$response = Http::get($fullurl, $params);
$response = json_decode($response->getBody()->getContents());
return $response;
}
public static function signedrequest($type, $service, $url, $data = [], $timeout = 30) {
$params['application'] = 'rapport';
$fullurl = self::genurl($service, $url);
if($type == 'post') {
$response = Http::timeout($timeout)->withHeaders(['Authorization' => Auth::user()->access_token])->post($fullurl, $data);
} else {
$response = Http::timeout($timeout)->withHeaders(['Authorization' => Auth::user()->access_token])->get($fullurl, $data);
}
$response = json_decode($response->getBody()->getContents());
return $response;
}
}