Aller au contenu

Api Surveillance Station Getsnapshot

Featured Replies

Posté(e)

bonjour à tous

je n'arrive pas à utilisé la commande GetSnapshot

je ramene bien un truc mais le format ne correspond pas à du jpeg

le fait de mettre le header en image/JPEG ne change rien

en PHP

//authentification
 $response = get_web_page("http://192.168.X.X:5000/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account=toto&passwd=1234&session=SurveillanceStation&format=sid");
//echo $response;
  $resArr = array();
  $resArr = ($response);
  $resArr = json_decode($response,true);

//sid in the array

$sid=array();
$sid=$resArr[data];
//echo $sid[sid];

//
//$response = get_web_page("http://192.168.X.X:5000/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=GetInfo&version=1&cameraIds=2&additional=device&_sid=".$sid[sid]);
//echo $response;

$response = get_web_page("http://192.168.X.X:5000/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=GetSnapshot&version=1&cameraId=2&_sid=".$sid[sid]);
echo $response;


function get_web_page($url) {
      $options = array (CURLOPT_RETURNTRANSFER => true, // return web page
    CURLOPT_HEADER => false, // don't return headers
    CURLOPT_FOLLOWLOCATION => true, // follow redirects
    CURLOPT_ENCODING => "", // handle compressed
    CURLOPT_USERAGENT => "test", // who am i
    CURLOPT_AUTOREFERER => true, // set referer on redirect
    CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
    CURLOPT_TIMEOUT => 120, // timeout on response
    CURLOPT_MAXREDIRS => 10 ); // stop after 10 redirects


      $ch = curl_init ( $url );
      curl_setopt_array ( $ch, $options );
      $content = curl_exec ( $ch );
      $err = curl_errno ( $ch );
      $errmsg = curl_error ( $ch );
      $header = curl_getinfo ( $ch );
      $httpCode = curl_getinfo ( $ch, CURLINFO_HTTP_CODE );
      curl_close ( $ch );

      $header ['errno'] = $err;
      $header ['errmsg'] = $errmsg;
      $header ['content'] = $content;
      return $header ['content'];
     }


si quelqu'un c'est déjà pris la tête !!!!

steve

Modifié par blair076

Posté(e)

Le code que tu donnes est truffé d'erreurs et d'inutilités.

Même corrigé, ça bloque au niveau de la 2ème requête.

Vérifie la syntaxe dans la documentation de l'API de Surveillance Station.

$response = get_web_page("http://192.168.X.X:5000/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account=toto&passwd=1234&session=SurveillanceStation&format=sid");
$resArr = json_decode($response);
echo "#resArr = ";
var_dump($resArr);

$sid = $resArr->data->sid;
echo "#sid = ";
var_dump($sid);

$response = get_web_page("http://192.168.X.X:5000/webapi/SurveillanceStation/camera.cgi?api=SYNO.SurveillanceStation.Camera&method=GetSnapshot&version=1&cameraId=1&_sid={$sid}");
echo "#response = ";
var_dump(json_decode($response));

function get_web_page($url){
	$ch = curl_init($url);
	curl_setopt_array($ch,array(
		CURLOPT_RETURNTRANSFER=>true
	));
	$content = curl_exec($ch);
	curl_close($ch);
	return $content;
}
Posté(e)
  • Auteur

:) Un grand merci pour cette réponse PiwiLabruti et la correction de mon code.

Cela ma permit de resoudre le problème.

En fait ma page était encodé en UTF8 alors qu'il faut l'encoder en ANSI.

et pour le blocage de la 2ème requête , la fonction retourne directement une image donc pas de var_dump(json_decode($response)); uniquement un echo suffit.

Encore merci.

Posté(e)

Etonnant, moi j'ai une erreur 401 sur la 2ème requête.

Enfin si ça marche pour toi, tant mieux.

  • 4 semaines après...
Posté(e)

Bonjour,

Serait-il possible de mettre à disposition le script PHP fonctionnant ?

J'obtiens aussi une erreur 401 sur la seconde requête et je n'arrive pas à finaliser la chose...

Un grand merci du retour.

  • 3 semaines après...
Posté(e)

Bonjour,

J'ai essyé un nombre incalculable de fois et je n'y arrives pas. pourtant si je passes par le navigateur avec les url, je peux le faire. Comment puis-je faire pour que cela fonctionne?

<?php 

//authentification 
 $response = get_web_page("https://IP:5001/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account=user&passwd=pwd&session=SurveillanceStation&format=sid"); 
//echo $response; 
  $resArr = array(); 
   $resArr = ($response); 

   $resArr = json_decode($response,true); 

//sid in the array 

$sid=array(); 
$sid=$resArr[data]; 
echo $sid[sid]; 

//send Start record 
$response = get_web_page("https://IP:5001/webapi/SurveillanceStation/extrecord.cgi?api=SYNO.SurveillanceStation.ExternalRecording&method=Record&version=1&cameraId=6&action=start&_sid=".$sid[sid]); 
echo $response; 

// send logoff 
 $response = get_web_page("https://IP:5001/webapi/auth.cgi?api=SYNO.API.Auth&method=Logout&version=2&session=SurveillanceStation&_sid=".$sid[sid]); 
echo $response; 

function get_web_page($url) { 
      $options = array (CURLOPT_RETURNTRANSFER => true, // return web page 
    CURLOPT_HEADER => false, // don't return headers 
    CURLOPT_FOLLOWLOCATION => true, // follow redirects 
    CURLOPT_ENCODING => "", // handle compressed 
    CURLOPT_USERAGENT => "test", // who am i 
    CURLOPT_AUTOREFERER => true, // set referer on redirect 
    CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect 
    CURLOPT_TIMEOUT => 120, // timeout on response 
    CURLOPT_MAXREDIRS => 10 ); // stop after 10 redirects 


      $ch = curl_init ( $url ); 
      curl_setopt_array ( $ch, $options ); 
      $content = curl_exec ( $ch ); 
      $err = curl_errno ( $ch ); 
      $errmsg = curl_error ( $ch ); 
      $header = curl_getinfo ( $ch ); 
      $httpCode = curl_getinfo ( $ch, CURLINFO_HTTP_CODE ); 

      curl_close ( $ch ); 

      $header ['errno'] = $err; 
      $header ['errmsg'] = $errmsg; 
      $header ['content'] = $content; 
      return $header ['content']; 
     } 
?>

Rejoindre la conversation

Vous pouvez publier maintenant et vous inscrire plus tard. Si vous avez un compte, connectez-vous maintenant pour publier avec votre compte.

Invité
Répondre à ce sujet…

Information importante

Nous avons placé des cookies sur votre appareil pour aider à améliorer ce site. Vous pouvez choisir d’ajuster vos paramètres de cookie, sinon nous supposerons que vous êtes d’accord pour continuer.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.