You are on page 1of 2

public function getToken()

{
$headers = [
'Authorization' => $this->base64_auth,
'Content-Type' => 'application/x-www-form-urlencoded',
];
$client = new \GuzzleHttp\Client([
'headers' => $headers
]);

try {
$res = $client->post($this->url . '/api/oauth/token', [
'form_params' => [
'grant_type' => 'client_credentials',
]
]);
$responses = $res->getBody()->getContents();
$data = json_decode($responses, true);
$data['status'] = 200;
} catch (ClientException $e) {
$data['req'] = $e->getRequest();
$data['resp'] = $e->getResponse();
$data['msg'] = $e->getMessage();
$data['status'] = -1001;
}
return $data;
}

public function getToken() //body diluar


{
$headers = [
'Authorization' => $this->base64_auth,
'Content-Type' => 'application/x-www-form-urlencoded',
];
$bodyParams = [
'appId' => $this->appId,
'refNo' => $refNo,
'totalPrice' => $totalPrice,
'userAccount' => $userAccount,
'receiverName' => $receiverName,
'receiverPhone' => $receiverPhone,
'province' => $province,
'city' => $city,
'street' => $street,
'callbackPageUrl' => $callbackpage,
'details' => json_encode($detail),
'sign' => $sign,
];
$client = new Client([
'verify' => false,
'headers' => $headers
]);

try {
$res = $client->post($this->url . '/api/oauth/token', [
'form_params' => $bodyParams
]);
$responses = $res->getBody()->getContents();
$data = json_decode($responses, true);
$data['status'] = 200;
} catch (ClientException $e) {
$data['req'] = $e->getRequest();
$data['resp'] = $e->getResponse();
$data['msg'] = $e->getMessage();
$data['status'] = -1001;
}
return $data;
}

You might also like