$check = DB::where("credential", 1)->where("scope", 'inbound')->first();
$created_time = $check->created_time;
$db_time_with_increase_time = date('Y-m-d H:i:s', strtotime("+55 minutes", strtotime($created_time)));
$dtA = strtotime($db_time_with_increase_time);
$dtB = strtotime(date('Y-m-d H:i:s', time()));
if ($dtA < $dtB) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials&scope=ROLE_APPLICATION");
curl_setopt($ch, CURLOPT_USERPWD, $check->client_id . ':' . $check->client_secret);
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$result_data = json_decode($result, true);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$check->access_token = $result_data["access_token"];
$check->created_time = date('Y-m-d H:i:s');
$check->save();
}
Leave a comment