API:Исследователь:Example2

Материал из КардиоКВАРК
Перейти к: навигация, поиск
<?php
$s = curl_init();
curl_setopt($s, CURLOPT_URL, 'https://b-api.cardioqvark.ru:1443/cardiogram?minId=7000');
curl_setopt($s, CURLOPT_HTTPHEADER, array('Range: items=0-24'));
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
curl_setopt($s, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($s, CURLOPT_CAINFO, 'cardio-ca-crt.pem');
curl_setopt($s, CURLOPT_SSLCERT, 'cardio-account-XXXX.pem'); # сертификат Исследователя
curl_setopt($s, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1_2');
$body = curl_exec($s);
$status = curl_getinfo($s, CURLINFO_HTTP_CODE);
curl_close($s);
if ($status == 200) {
	echo '<style>table{border-collapse:collapse;}table,th,td{border:1px solid black;}th,td{padding:5px;}</style>' .
		'<table><tr><th>Id</th><th>Date</th><th>Duration</th></tr>';
	foreach(json_decode($body) as $c) {
		echo '<tr><td>' . $c->id . '</td><td>' . date('y-M-d H:i:s', $c->date) .
			'</td><td>' . $c->duration . '</td></tr>';
	}
	echo '</table>';
} else echo 'error: ' . $status;