Created
December 1, 2021 11:06
-
-
Save srsohan150626/41e062fea2e9b05e089eca7670e54022 to your computer and use it in GitHub Desktop.
Guzzle Http Api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://docs.guzzlephp.org/en/stable/quickstart.html | |
<?php | |
namespace App\Http\Controllers\Web; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use GuzzleHttp\Client; | |
use Exception; | |
class LoyalityMemberController extends Controller | |
{ | |
private $base_url = 'http://192.168.1.4/CloudPOS_Rise/api/app/'; | |
private $header; | |
private $method = 'GET'; | |
private $response; | |
private $verify = false; | |
private $suffix; | |
public function checkapiresponse(Request $request) | |
{ | |
$header = [ | |
'Authorization' => 'ms:tf42+QsVrA+0QF9iKfd4ng==' | |
]; | |
$this->header = $header; | |
$this->suffix = 'GetCustomer/01001024'; | |
try{ | |
$client = new \GuzzleHttp\Client(['base_uri' => $this->base_url, 'verify' => $this->verify]); | |
$response = $client->request($this->method, $this->suffix, [ | |
'headers' => $this->header | |
]); | |
}catch(Exception $e){ | |
dd($e->getMessage()); | |
} | |
// $response->getStatusCode() | |
$x = $response->getBody(); | |
$this->response = json_decode($x->getContents()); | |
// dd($this->response->Data->CUSTOMER_DISC_PRCNT); | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment