Class PHP Steam : Différence entre versions

De Wiki levelKro
 
(4 révisions intermédiaires par le même utilisateur non affichées)
Ligne 3 : Ligne 3 :
 
* Clé d'accès à l'API de Steam.
 
* Clé d'accès à l'API de Steam.
 
* PHP 5.4+ avec cURL
 
* PHP 5.4+ avec cURL
== SteamCommunity.Class.php ==
+
== Commandes ==
Permet d'avoir les informations;
+
* '''userPublic(''a'')'''
* D'un groupe
+
** ''a'' : Le SteamID ou le Username de l'utilisateur Steam
* D'un utilisateur
+
* '''userDetails(''a'',''b'')'''
 +
** ''a'' : Le ApiKey d'accès à Steam
 +
** ''b'' : Le SteamID de l'utilisateur Steam
 +
* '''userGames(''a'',''b'')'''
 +
** ''a'' : Le ApiKey d'accès à Steam
 +
** ''b'' : Le SteamID de l'utilisateur Steam
 +
* '''userBans(''a'',''b'')'''
 +
** ''a'' : Le ApiKey d'accès à Steam
 +
** ''b'' : Le SteamID de l'utilisateur Steam
 +
* '''marketPages(''a'',''b'')'''
 +
** ''a'' : Valeur de départ de la liste, affiche les 100 éléments suivant
 +
** ''b'' : (true) Retourne le nombre de page à consulter, utiliser ''0'' comme valeur pour ''a'' (optionnel, false par défaut)
 +
* '''marketItem(''a'')'''
 +
** ''a'' : Url complet vers la page du produit dans le marché Steam
 +
* '''group(''a'')''' : Retourne les détails d'un groupe Steam
 +
** ''a'' : Le GroupID ou le Non court du groupe Steam
 +
* '''loginUrl(''a'',''b'')''' : Obtenir le lien de connexion avec Steam
 +
** ''a'' : URL complet de retourne une fois connecté. (optionnel, retourne la page courante)
 +
** ''b'' : Utiliser & (true) au lieu de & dans le lien (optionnel, true par défaut)
 +
* '''loginValidate()''' : Valider la session de l'utilisateur (à utiliser sur la page de retour)
 +
* '''storeList()''' : Retourne la liste des produits disponible dans la boutique Steam ''(non disponible)''
 +
* '''storeItem(''a'',''b'')''' : Retourne les détails d'un produit
 +
** ''a'' : Le AppID du produit
 +
** ''b'' : 1 pour un produit seul (video,dlc,apps,games,demo,...) ou 2 pour un package (pas un bundle) (optionnel, 1 par défaut)
 +
== Codes de la Class PHP ==
 +
Enregistrer ce code dans un document comme {{Flash|txt=Steam.Class.php}}.
 
<pre>
 
<pre>
 
<?php
 
<?php
/*
+
/*
* (c) Copyright Mathieu Légaré (levelkro@yahoo.ca)
+
  * (c) Copyright Mathieu Légaré (levelkro@yahoo.ca)
* 2013-2019
+
  * 2013-2019
*/
+
  */
class STEAMcommunity {
+
class SteamLVK {
  function=nameVAC($id){
+
/* Variables */
switch($id){
+
const STEAM_LOGIN = 'https://steamcommunity.com/openid';
case '0':
+
const STEAM_OPENID = 'http://specs.openid.net/auth/2.0';
return "En règle";
+
const STEAM_COMMUNITY = 'https://steamcommunity.com';
break;
+
const STEAM_API = 'http://api.steampowered.com';
case '1':
+
const STEAM_STORE = 'https://store.steampowered.com';
return "Suspendu";
+
const STEAM_MARKET = 'https://steamcommunity.com/market';
break;
+
const STEAM_CDN = 'https://steamcdn-a.akamaihd.net';
default:
+
 
return "Non déterminé";
+
/*
}
+
Tools Functions
  }
+
*/
  function=nameTrade($id)
+
function=nameVAC($id){
switch($id){
+
  switch($id){
case 'None':
+
  case '0':
return "En règle";
+
    return "En règle";
break;
+
    break;
case 'Probation':
+
  case '1':
return "Limité";
+
    return "Suspendu";
break;
+
    break;
default:
+
  default:
return "Non déterminé";
+
    return "Non déterminé";
}
+
  }
  }
+
}
      function=nameVisibility($id){
+
function=nameTrade($id)
switch($id){
+
  switch($id){
case '1':
+
  case 'None':
return "Privé";
+
    return "En règle";
break;
+
    break;
case '2':
+
  case 'Probation':
case '3':
+
    return "Limité";
return "Public";
+
    break;
break;
+
  default:
default:
+
    return "Non déterminé";
return "Non déterminé";
+
  }
}
+
}
};    
+
function=nameVisibility($id){
   
+
  switch($id){
function OpenURL($url){
+
  case '1':
// Code for get content of remote URL
+
    return "Privé";
$ch = curl_init();
+
    break;
curl_setopt($ch,CURLOPT_URL,$url);
+
  case '2':
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
+
  case '3':
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
+
    return "Public";
curl_setopt($ch,CURLOPT_TIMEOUT,1000);
+
    break;
$result = curl_exec($ch);
+
  default:
return $result;
+
    return "Non déterminé";
curl_close($ch);
+
  }
}
+
}
       
+
function OpenUrl($url){
function group($id){
+
  $ch = curl_init();
// Return information about a Steam Group
+
  curl_setopt($ch,CURLOPT_URL,$url);
$values = self::OpenURL("http://steamcommunity.com/groups/".$id."/memberslistxml/?xml=1");
+
  curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
try{
+
  curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
$values = (array) simplexml_load_string($values);
+
  curl_setopt($ch,CURLOPT_TIMEOUT,1000);
$values['groupDetails'] = (array) $values['groupDetails'];
+
  $result = curl_exec($ch);
$values['groupDetails']['groupName'] = (string) $values['groupDetails']['groupName'];
+
  return $result;  
$values['groupDetails']['groupURL'] = (string) $values['groupDetails']['groupURL'];
+
   curl_close($ch);
$values['groupDetails']['headline'] = (string) $values['groupDetails']['headline'];
+
}
$values['groupDetails']['summary'] = (string) $values['groupDetails']['summary'];
 
$values['groupDetails']['avatarIcon'] = (string) $values['groupDetails']['avatarIcon'];
 
$values['groupDetails']['avatarMedium'] = (string) $values['groupDetails']['avatarMedium'];
 
$values['groupDetails']['avatarFull'] = (string) $values['groupDetails']['avatarFull'];
 
$values['members'] = (array) $values['members'];
 
return $values;
 
} catch (Exception $e) {
 
return false;
 
}
 
}
 
function user($id){
 
// Return information about a Steam Group
 
$values = self::OpenURL("http://steamcommunity.com/id/".$id."/?xml=1");
 
try{
 
$values = (array) simplexml_load_string($values);
 
$values['steamID'] = (string) $values['steamID'];
 
$values['stateMessage'] = (string) $values['stateMessage'];
 
$values['avatarIcon'] = (string) $values['avatarIcon'];
 
$values['avatarMedium'] = (string) $values['avatarMedium'];
 
$values['avatarFull'] = (string) $values['avatarFull'];
 
$values['customURL'] = (string) $values['customURL'];
 
$values['steamRating'] = (string) $values['steamRating'];
 
$values['headline'] = (string) $values['headline'];
 
$values['location'] = (string) $values['location'];
 
$values['realname'] = (string) $values['realname'];
 
$values['summary'] = (string) $values['summary'];
 
 
$values['mostPlayedGames'] = (array) $values['mostPlayedGames'];
 
$values['mostPlayedGames'] = (array) $values['mostPlayedGames']['mostPlayedGame'];
 
$values['groups'] = (array) $values['groups'];
 
$values['groups'] = (array) $values['groups']['group'];
 
return $values;
 
} catch (Exception $e) {
 
return false;
 
}
 
}
 
        function=userAPI($apikey,$value){
 
$result=$this->remoteUrl("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$apikey."&steamids=".$value."&format=json");
 
$pro=json_decode($result);
 
return (array) $pro->response->players[0];
 
}  
 
        function=userGames($apikey,$steamID){
 
    $json = $this->remoteUrl("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=".$apikey."&steamid=".$steamID."&format=json");
 
    $result = json_decode($json,true);
 
    return $result['response']['games'];    
 
        }
 
    function=userBan($apikey,$steamID){
 
          $result = false;
 
          $json = $this->remoteUrl("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=".$apikey."&steamids=".$steamID."&format=json");
 
          $array = json_decode($json,true);
 
          return $array['players']['0'];
 
        }
 
}
 
</pre>
 
== SteamMarket.Class.php ==
 
Permet d'avoir les informations;
 
* Nombre total de produits
 
* Résultat depuis 'X' des items (100 éléments maximum)
 
* Détails d'un produit du marché spécifique (avec URL)
 
<pre>
 
<?php
 
/*
 
* (c) Copyright Mathieu Légaré (levelkro@yahoo.ca)
 
* 2013-2019
 
*/
 
class STEAMmarket {   
 
// Récupérer le contenu d'une page distant
 
function getUrlContent($url){
 
$ch = curl_init();
 
curl_setopt($ch,CURLOPT_URL,$url);
 
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
 
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
 
curl_setopt($ch,CURLOPT_TIMEOUT,1000);
 
$result = curl_exec($ch);
 
return $result;
 
curl_close($ch);
 
}
 
  
// Récupère la listes des 100 éléments suivants
+
/* Steam Community */
function getListDetails($s=0){
+
function group($id){
$l="https://steamcommunity.com/market/search/render/?query=&start=".$s."&count=100&norender=1";
+
  $values = self::OpenUrl(self::STEAM_COMMUNITY."/groups/".$id."/memberslistxml/?xml=1");
$s=getUrlContent($l);
+
  try{
$n=(array) json_decode($s, true);
+
  $values = (array) simplexml_load_string($values);
return $n;
+
  $values['groupDetails'] = (array) $values['groupDetails'];
}
+
  $values['groupDetails']['groupName'] = (string) $values['groupDetails']['groupName'];
 +
  $values['groupDetails']['groupURL'] = (string) $values['groupDetails']['groupURL'];
 +
  $values['groupDetails']['headline'] = (string) $values['groupDetails']['headline'];
 +
  $values['groupDetails']['summary'] = (string) $values['groupDetails']['summary'];
 +
  $values['groupDetails']['avatarIcon'] = (string) $values['groupDetails']['avatarIcon'];
 +
  $values['groupDetails']['avatarMedium'] = (string) $values['groupDetails']['avatarMedium'];
 +
  $values['groupDetails']['avatarFull'] = (string) $values['groupDetails']['avatarFull'];
 +
  $values['members'] = (array) $values['members'];
 +
  return $values;
 +
  } catch (Exception $e) {
 +
  return false;
 +
  }
 +
}
 +
function userPublic($id){
 +
  $values = self::OpenUrl(self::STEAM_COMMUNITY."/id/".$id."/?xml=1");
 +
  try{
 +
  $values = (array) simplexml_load_string($values);
 +
  $values['steamID'] = (string) $values['steamID'];
 +
  $values['stateMessage'] = (string) $values['stateMessage'];
 +
  $values['avatarIcon'] = (string) $values['avatarIcon'];
 +
  $values['avatarMedium'] = (string) $values['avatarMedium'];
 +
  $values['avatarFull'] = (string) $values['avatarFull'];
 +
  $values['customURL'] = (string) $values['customURL'];
 +
  $values['steamRating'] = (string) $values['steamRating'];
 +
  $values['headline'] = (string) $values['headline'];
 +
  $values['location'] = (string) $values['location'];
 +
  $values['realname'] = (string) $values['realname'];
 +
  $values['summary'] = (string) $values['summary'];
 +
  $values['mostPlayedGames'] = (array) $values['mostPlayedGames'];
 +
  $values['mostPlayedGames'] = (array) $values['mostPlayedGames']['mostPlayedGame'];
 +
  $values['groups'] = (array) $values['groups'];
 +
  $values['groups'] = (array) $values['groups']['group'];
 +
  return $values;
 +
  } catch (Exception $e) {
 +
  return false;
 +
  }
 +
}
 +
function=userDetails($apikey,$value){
 +
  $result=self::OpenUrl(self::STEAM_API."/ISteamUser/GetPlayerSummaries/v2/?key=".$apikey."&steamids=".$value."&format=json");
 +
  $pro=json_decode($result);
 +
  return (array) $pro->response->players[0];
 +
}  
 +
function=userGames($apikey,$steamID){
 +
  $json = self::OpenUrl(self::STEAM_API."/IPlayerService/GetOwnedGames/v1/?key=".$apikey."&steamid=".$steamID."&format=json");  
 +
  $result = json_decode($json,true);
 +
  return $result['response']['games']; 
 +
}
 +
function=userBans($apikey,$steamID){
 +
  $result = false;
 +
  $json = self::OpenUrl(self::STEAM_API."/ISteamUser/GetPlayerBans/v1/?key=".$apikey."&steamids=".$steamID."&format=json");
 +
  $array = json_decode($json,true);
 +
  return $array['players']['0'];
 +
}
  
// Récupère le nombre d'éléments à importer
+
function marketPages($s=0,$l=false){
function getListPages(){
+
  $s=self::OpenUrl(self::STEAM_MARKET."/search/render/?query=&start=".$s."&count=100&norender=1");
$l="https://steamcommunity.com/market/search/render/?query=&start=0&count=100&norender=1";
+
  $n=(array) json_decode($s, true);
$s=getUrlContent($l);
+
  if($l===true) $n['total_count']  
$n=(array) json_decode($s, true);
+
  else return $n;
return $n['total_count'];
+
}
}
+
function marketItem($p){
function getInfos($p){
+
  // Steam XML/JSon details not found, use the public page
// Get informations about the item in Market
+
  $source = self::OpenUrl($p);
$source = self::OpenURL($p);
+
  $htmlsrc=explode("<!-- main body -->",$source); // The beginning
$htmlsrc=explode("<!-- main body -->",$source); // The beginning
+
  $htmlsrc=explode("<div id=\"market_activity_section\">",$htmlsrc[1]); // The end of part of code
$htmlsrc=explode("<div id=\"market_activity_section\">",$htmlsrc[1]); // The end of part of code
+
  $htmlsrc=$htmlsrc[0];  
$htmlsrc=$htmlsrc[0];  
+
  $htmlsrc=str_replace("&"."#36;","",$htmlsrc);    
$htmlsrc=str_replace("&"."#36;","",$htmlsrc);    
+
  $htmlsrc=str_replace("\r","",$htmlsrc);
$htmlsrc=str_replace("\r","",$htmlsrc);
+
  $htmlsrc=str_replace("\t","",$htmlsrc);
$htmlsrc=str_replace("\t","",$htmlsrc);
+
  $htmlsrc=str_replace("\n","",$htmlsrc);
$htmlsrc=str_replace("\n","",$htmlsrc);
+
  $htmlsrc=str_replace("&gt;","",$htmlsrc);
$htmlsrc=str_replace("&gt;","",$htmlsrc);
+
  $htmlsrc=str_replace("<div id=\"BG_bottom\"><div id=\"mainContents\"><div class=\"market_listing_nav_container\"><div class=\"market_listing_nav\">","<item>\r\n",$htmlsrc);
$htmlsrc=str_replace("<div id=\"BG_bottom\"><div id=\"mainContents\"><div class=\"market_listing_nav_container\"><div class=\"market_listing_nav\">","<item>\r\n",$htmlsrc);
+
  $htmlsrc=str_replace("<div style=\"clear: both;\"></div>","",$htmlsrc);
$htmlsrc=str_replace("<div style=\"clear: both;\"></div>","",$htmlsrc);
+
  $htmlsrc=preg_replace("/<\/a>/i","</a>\r\n", $htmlsrc);
$htmlsrc=preg_replace("/<\/a>/i","</a>\r\n", $htmlsrc);
+
  $htmlsrc=explode("<div id=\"largeiteminfo\">",$htmlsrc);
$htmlsrc=explode("<div id=\"largeiteminfo\">",$htmlsrc);
+
  $htmlsrc=$htmlsrc[0];
$htmlsrc=$htmlsrc[0];
+
  $htmlsrc=str_replace("</div></div><div class=\"market_page_fullwidth market_listing_firstsection\"><div class=\"market_listing_iteminfo\"><div class=\"market_listing_largeimage\">","",$htmlsrc);
$htmlsrc=str_replace("</div></div><div class=\"market_page_fullwidth market_listing_firstsection\"><div class=\"market_listing_iteminfo\"><div class=\"market_listing_largeimage\">","",$htmlsrc);
+
  $htmlsrc=preg_replace("/<a href=\"(.+)search(.+)=(.+)\">(.+)<\/a>/i","<catAppid>$3</catAppid>\r\n<catName>$4</catName>", $htmlsrc);
$htmlsrc=preg_replace("/<a href=\"(.+)search(.+)=(.+)\">(.+)<\/a>/i","<catAppid>$3</catAppid>\r\n<catName>$4</catName>", $htmlsrc);
+
  $htmlsrc=preg_replace("/<a href=\"(.+)listing(.+)\">(.+)<\/a>/i","<itemUrl>$1listing$2</itemUrl>\r\n<itemName>$3</itemName>", $htmlsrc);
$htmlsrc=preg_replace("/<a href=\"(.+)listing(.+)\">(.+)<\/a>/i","<itemUrl>$1listing$2</itemUrl>\r\n<itemName>$3</itemName>", $htmlsrc);
+
  $htmlsrc=preg_replace("/<img src=\"(.+)\" alt=\"\" \/><\/div>/i","<itemImage>$1</itemImage>", $htmlsrc);
$htmlsrc=preg_replace("/<img src=\"(.+)\" alt=\"\" \/><\/div>/i","<itemImage>$1</itemImage>", $htmlsrc);
+
  $htmlsrc=$htmlsrc."</item>";
$htmlsrc=$htmlsrc."</item>";
+
  $htmlsrc="<?phpxml version=\"1.0\" encoding=\"UTF-8\"?>\r\n".$htmlsrc."";
$htmlsrc="<?phpxml version=\"1.0\" encoding=\"UTF-8\"?>\r\n".$htmlsrc."";
+
  $htmlsrc=str_replace("&","&amp;",$htmlsrc);
$htmlsrc=str_replace("&","&amp;",$htmlsrc);
+
  try{
try{
+
  $htmlsrc = simplexml_load_string($htmlsrc);
$htmlsrc = simplexml_load_string($htmlsrc);
+
  $htmlsrc = (array) $htmlsrc;
$htmlsrc = (array) $htmlsrc;
+
  } catch (Exception $e) {
} catch (Exception $e) {
+
  $htmlsrc=array();
$htmlsrc=array();
+
  }  
}  
+
  $jsonAsrc=explode("var g_rgAppContextData = ",$source);
$jsonAsrc=explode("var g_rgAppContextData = ",$source);
+
  $jsonAsrc=explode("var g_rgAssets",$jsonAsrc[1]);
$jsonAsrc=explode("var g_rgAssets",$jsonAsrc[1]);
+
  $jsonAsrc=explode("\"".$htmlsrc['catAppid']."\":",$jsonAsrc[0]);
$jsonAsrc=explode("\"".$htmlsrc['catAppid']."\":",$jsonAsrc[0]);
+
  $jsonAsrc=explode("};",$jsonAsrc[1]);
$jsonAsrc=explode("};",$jsonAsrc[1]);
+
  if(strpos($jsonAsrc[0],"},")){
if(strpos($jsonAsrc[0],"},")){
+
  $jsonAsrc=explode("},",$jsonAsrc[0]);
$jsonAsrc=explode("},",$jsonAsrc[0]);
+
  $jsonAsrc=explode(":{",$jsonAsrc[1]);
$jsonAsrc=explode(":{",$jsonAsrc[1]);
+
  $jsonAsrc=(array) json_decode("{".$jsonAsrc[1],true);
$jsonAsrc=(array) json_decode("{".$jsonAsrc[1],true);
+
  }
}
+
  else{
else{
+
  $jsonAsrc=(array) json_decode($jsonAsrc[0],true);
$jsonAsrc=(array) json_decode($jsonAsrc[0],true);
+
  }
}
+
  $jsonBsrc=explode("var g_rgAssets = ",$source);
$jsonBsrc=explode("var g_rgAssets = ",$source);
+
  $jsonBsrc=explode("var g_rgListingInfo",$jsonBsrc[1]);
$jsonBsrc=explode("var g_rgListingInfo",$jsonBsrc[1]);
+
  $jsonBsrc=explode("\"".$htmlsrc['catAppid']."\":",$jsonBsrc[0]);
$jsonBsrc=explode("\"".$htmlsrc['catAppid']."\":",$jsonBsrc[0]);
+
  $jsonBsrc=explode("};",$jsonBsrc[1]);
$jsonBsrc=explode("};",$jsonBsrc[1]);
+
  $jsonBsrc=(array) json_decode($jsonBsrc[0],true);
$jsonBsrc=(array) json_decode($jsonBsrc[0],true);
+
  foreach($jsonBsrc as $jsonItemsrc){
foreach($jsonBsrc as $jsonItemsrc){
+
  $jsonBsrc=$jsonItemsrc;
$jsonBsrc=$jsonItemsrc;
+
  }
}
+
  $o=1;
$o=1;
+
  foreach($jsonBsrc as $jsonItemsrc){
foreach($jsonBsrc as $jsonItemsrc){
+
  if($o==1){
if($o==1){
+
    $jsonItem=$jsonItemsrc;
$jsonItem=$jsonItemsrc;
+
    $o++;
$o++;
+
  }
}
+
  }
}
+
  $jsonItemDesc="";
$jsonItemDesc="";
+
  foreach($jsonItem['descriptions'] as $jsonDescsrc){
foreach($jsonItem['descriptions'] as $jsonDescsrc){
+
  $jsonItemDesc.=$jsonDescsrc['value']."<br/>";
$jsonItemDesc.=$jsonDescsrc['value']."<br/>";
+
  }
}
+
  $jsonItem['descriptions']=$jsonItemDesc;
$jsonItem['descriptions']=$jsonItemDesc;
+
  $output=array();
$output=array();
+
  $output['base']=$htmlsrc;
$output['base']=$htmlsrc;
+
  $output['parent']=$jsonAsrc;
$output['parent']=$jsonAsrc;
+
  $output['item']=$jsonItem;
$output['item']=$jsonItem;
+
  return $output;
return $output;
+
}
}
+
public static function loginUrl($returnTo=false, $useAmp=true) {
      }
+
  $returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] : $returnTo;
</pre>
+
  $params = array('openid.ns'=>self::STEAM_OPENID,'openid.mode'=>'checkid_setup','openid.return_to'=> $returnTo,'openid.realm'=>(!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],'openid.identity'=>self::STEAM_OPENID.'/identifier_select','openid.claimed_id'=>self::STEAM_OPENID.'/identifier_select');
== SteamStore.Class.php ==
+
  $sep = ($useAmp) ? '&amp;' : '&';
Permet d'avoir les informations;
+
  return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
* De tous les produits disponibles (sans les exclus, désactivés, supprimés, etc...)
+
}
* De tous les packages associés aux produits
+
public static function loginValidate() {
* D'un produit spécifique
+
  $params = array('openid.assoc_handle'=>$_GET['openid_assoc_handle'],'openid.signed'=>$_GET['openid_signed'],'openid.sig'=>$_GET['openid_sig'],'openid.ns'=>self::STEAM_OPENID);
<pre>
+
  $signed = explode(',', $_GET['openid_signed']);
<?php
+
  foreach($signed as $item) {
/*
+
  $val = $_GET['openid_' . str_replace('.', '_', $item)];
* (c) Copyright Mathieu Légaré (levelkro@yahoo.ca)
+
  $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val;
* 2013-2019
+
  }
*/
+
  $params['openid.mode'] = 'check_authentication';
class STEAMstore {   
+
  $data =  http_build_query($params);
    }
+
  $context = stream_context_create(array('http' => array('method'=>'POST','header'=>"Accept-language: en\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: ".strlen($data)."\r\n",'content'=>$data)));
</pre>
+
  $result = file_get_contents(self::STEAM_LOGIN."/login", false, $context);
== SteamLogin.Class.php ==
+
  preg_match("#^".self::STEAM_LOGIN."/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
Requis pour l'identification avec Steam, utilise le OpenID Auth 2.0.
+
  $steamid64 = is_numeric($matches[1]) ? $matches[1] : 0;
<pre>
+
  return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamid64 : false;
<?php
+
}
/*
+
}
*/
 
class STEAMSignIn {
 
const STEAM_LOGIN = 'https://steamcommunity.com/openid/login';
 
 
public static function genUrl($returnTo = false, $useAmp = true) {
 
$returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] : $returnTo;
 
$params = array(
 
'openid.ns' => 'http://specs.openid.net/auth/2.0',
 
'openid.mode' => 'checkid_setup',
 
'openid.return_to' => $returnTo,
 
'openid.realm' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],
 
'openid.identity' => 'http://specs.openid.net/auth/2.0/identifier_select',
 
'openid.claimed_id' => 'http://specs.openid.net/auth/2.0/identifier_select',
 
);
 
$sep = ($useAmp) ? '&amp;' : '&';
 
return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
 
}
 
public static function validate() {
 
$params = array(
 
'openid.assoc_handle' => $_GET['openid_assoc_handle'],
 
'openid.signed' => $_GET['openid_signed'],
 
'openid.sig' => $_GET['openid_sig'],
 
'openid.ns' => 'http://specs.openid.net/auth/2.0',
 
);
 
$signed = explode(',', $_GET['openid_signed']);
 
foreach($signed as $item) {
 
$val = $_GET['openid_' . str_replace('.', '_', $item)];
 
$params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val;
 
}
 
$params['openid.mode'] = 'check_authentication';
 
$data =  http_build_query($params);
 
$context = stream_context_create(array(
 
'http' => array(
 
'method'  => 'POST',
 
'header'  =>
 
"Accept-language: en\r\n".
 
"Content-type: application/x-www-form-urlencoded\r\n" .
 
"Content-Length: " . strlen($data) . "\r\n",
 
'content' => $data,
 
),
 
));
 
$result = file_get_contents(self::STEAM_LOGIN, false, $context);
 
preg_match("#^https://steamcommunity.com/openid/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
 
$steamid64 = is_numeric($matches[1]) ? $matches[1] : 0;
 
return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamid64 : false;
 
}
 
}
 
 
</pre>
 
</pre>
 
[[Catégorie:Programmation]]
 
[[Catégorie:Programmation]]

Version actuelle datée du 29 janvier 2019 à 02:31

Steam offre un API mais peu de documentation, voici des codes pour vous aider à inclure Steam dans votre site.

Pré-requis

  • Clé d'accès à l'API de Steam.
  • PHP 5.4+ avec cURL

Commandes

  • userPublic(a)
    • a : Le SteamID ou le Username de l'utilisateur Steam
  • userDetails(a,b)
    • a : Le ApiKey d'accès à Steam
    • b : Le SteamID de l'utilisateur Steam
  • userGames(a,b)
    • a : Le ApiKey d'accès à Steam
    • b : Le SteamID de l'utilisateur Steam
  • userBans(a,b)
    • a : Le ApiKey d'accès à Steam
    • b : Le SteamID de l'utilisateur Steam
  • marketPages(a,b)
    • a : Valeur de départ de la liste, affiche les 100 éléments suivant
    • b : (true) Retourne le nombre de page à consulter, utiliser 0 comme valeur pour a (optionnel, false par défaut)
  • marketItem(a)
    • a : Url complet vers la page du produit dans le marché Steam
  • group(a) : Retourne les détails d'un groupe Steam
    • a : Le GroupID ou le Non court du groupe Steam
  • loginUrl(a,b) : Obtenir le lien de connexion avec Steam
    • a : URL complet de retourne une fois connecté. (optionnel, retourne la page courante)
    • b : Utiliser & (true) au lieu de & dans le lien (optionnel, true par défaut)
  • loginValidate() : Valider la session de l'utilisateur (à utiliser sur la page de retour)
  • storeList() : Retourne la liste des produits disponible dans la boutique Steam (non disponible)
  • storeItem(a,b) : Retourne les détails d'un produit
    • a : Le AppID du produit
    • b : 1 pour un produit seul (video,dlc,apps,games,demo,...) ou 2 pour un package (pas un bundle) (optionnel, 1 par défaut)

Codes de la Class PHP

Enregistrer ce code dans un document comme Steam.Class.php.

<?php
 /*
  * (c) Copyright Mathieu Légaré (levelkro@yahoo.ca)
  * 2013-2019
  */
class SteamLVK {
 /* Variables */
 const STEAM_LOGIN = 'https://steamcommunity.com/openid';
 const STEAM_OPENID = 'http://specs.openid.net/auth/2.0';
 const STEAM_COMMUNITY = 'https://steamcommunity.com';
 const STEAM_API = 'http://api.steampowered.com';
 const STEAM_STORE = 'https://store.steampowered.com';
 const STEAM_MARKET = 'https://steamcommunity.com/market';
 const STEAM_CDN = 'https://steamcdn-a.akamaihd.net';

 /*
	Tools Functions
 */
 function=nameVAC($id){
  switch($id){
   case '0':
    return "En règle";
    break;
   case '1':
    return "Suspendu";
    break;
   default:
    return "Non déterminé";
  }
 }
 function=nameTrade($id)
  switch($id){
   case 'None':
    return "En règle";
    break;
   case 'Probation':
    return "Limité";
    break;
   default:
    return "Non déterminé";
  }	
 }
 function=nameVisibility($id){
  switch($id){
   case '1':
    return "Privé";
    break;
   case '2':
   case '3':
    return "Public";
    break;
   default:
    return "Non déterminé";
  }			
 }
 function OpenUrl($url){
  $ch = curl_init();
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3");
  curl_setopt($ch,CURLOPT_TIMEOUT,1000);
  $result = curl_exec($ch);
  return $result; 
  curl_close($ch);
 }	

 /* Steam Community */
 function group($id){
  $values = self::OpenUrl(self::STEAM_COMMUNITY."/groups/".$id."/memberslistxml/?xml=1");
  try{
   $values = (array) simplexml_load_string($values);
   $values['groupDetails'] = (array) $values['groupDetails'];				
   $values['groupDetails']['groupName'] = (string) $values['groupDetails']['groupName'];
   $values['groupDetails']['groupURL'] = (string) $values['groupDetails']['groupURL'];
   $values['groupDetails']['headline'] = (string) $values['groupDetails']['headline'];
   $values['groupDetails']['summary'] = (string) $values['groupDetails']['summary'];
   $values['groupDetails']['avatarIcon'] = (string) $values['groupDetails']['avatarIcon'];
   $values['groupDetails']['avatarMedium'] = (string) $values['groupDetails']['avatarMedium'];
   $values['groupDetails']['avatarFull'] = (string) $values['groupDetails']['avatarFull'];
   $values['members'] = (array) $values['members'];
   return $values;
  } catch (Exception $e) {
   return false;
  } 		
 }	
 function userPublic($id){
  $values = self::OpenUrl(self::STEAM_COMMUNITY."/id/".$id."/?xml=1");
  try{
   $values = (array) simplexml_load_string($values);
   $values['steamID'] = (string) $values['steamID'];
   $values['stateMessage'] = (string) $values['stateMessage'];
   $values['avatarIcon'] = (string) $values['avatarIcon'];
   $values['avatarMedium'] = (string) $values['avatarMedium'];
   $values['avatarFull'] = (string) $values['avatarFull'];
   $values['customURL'] = (string) $values['customURL'];
   $values['steamRating'] = (string) $values['steamRating'];
   $values['headline'] = (string) $values['headline'];
   $values['location'] = (string) $values['location'];
   $values['realname'] = (string) $values['realname'];
   $values['summary'] = (string) $values['summary'];
   $values['mostPlayedGames'] = (array) $values['mostPlayedGames'];
   $values['mostPlayedGames'] = (array) $values['mostPlayedGames']['mostPlayedGame'];
   $values['groups'] = (array) $values['groups'];
   $values['groups'] = (array) $values['groups']['group'];
   return $values;
  } catch (Exception $e) {
   return false;
  } 		
 }	
 function=userDetails($apikey,$value){
  $result=self::OpenUrl(self::STEAM_API."/ISteamUser/GetPlayerSummaries/v2/?key=".$apikey."&steamids=".$value."&format=json");
  $pro=json_decode($result);
  return (array) $pro->response->players[0];
 }	  
 function=userGames($apikey,$steamID){
  $json = self::OpenUrl(self::STEAM_API."/IPlayerService/GetOwnedGames/v1/?key=".$apikey."&steamid=".$steamID."&format=json"); 
  $result = json_decode($json,true);	
  return $result['response']['games'];   
 }
 function=userBans($apikey,$steamID){
  $result = false;
  $json = self::OpenUrl(self::STEAM_API."/ISteamUser/GetPlayerBans/v1/?key=".$apikey."&steamids=".$steamID."&format=json");		
  $array = json_decode($json,true);
  return $array['players']['0'];
 }

 function marketPages($s=0,$l=false){
  $s=self::OpenUrl(self::STEAM_MARKET."/search/render/?query=&start=".$s."&count=100&norender=1");
  $n=(array) json_decode($s, true);
  if($l===true) $n['total_count'] 
  else return $n;
 }
 function marketItem($p){
  // Steam XML/JSon details not found, use the public page
  $source = self::OpenUrl($p);
  $htmlsrc=explode("<!-- main body -->",$source);	// The beginning
  $htmlsrc=explode("<div id=\"market_activity_section\">",$htmlsrc[1]); // The end of part of code
  $htmlsrc=$htmlsrc[0]; 
  $htmlsrc=str_replace("&"."#36;","",$htmlsrc);	   
  $htmlsrc=str_replace("\r","",$htmlsrc);
  $htmlsrc=str_replace("\t","",$htmlsrc);	
  $htmlsrc=str_replace("\n","",$htmlsrc);	
  $htmlsrc=str_replace(">","",$htmlsrc);
  $htmlsrc=str_replace("<div id=\"BG_bottom\"><div id=\"mainContents\"><div class=\"market_listing_nav_container\"><div class=\"market_listing_nav\">","<item>\r\n",$htmlsrc);	
  $htmlsrc=str_replace("<div style=\"clear: both;\"></div>","",$htmlsrc);
  $htmlsrc=preg_replace("/<\/a>/i","</a>\r\n", $htmlsrc);
  $htmlsrc=explode("<div id=\"largeiteminfo\">",$htmlsrc);
  $htmlsrc=$htmlsrc[0];
  $htmlsrc=str_replace("</div></div><div class=\"market_page_fullwidth market_listing_firstsection\"><div class=\"market_listing_iteminfo\"><div class=\"market_listing_largeimage\">","",$htmlsrc);
  $htmlsrc=preg_replace("/<a href=\"(.+)search(.+)=(.+)\">(.+)<\/a>/i","<catAppid>$3</catAppid>\r\n<catName>$4</catName>", $htmlsrc);
  $htmlsrc=preg_replace("/<a href=\"(.+)listing(.+)\">(.+)<\/a>/i","<itemUrl>$1listing$2</itemUrl>\r\n<itemName>$3</itemName>", $htmlsrc);
  $htmlsrc=preg_replace("/<img src=\"(.+)\" alt=\"\" \/><\/div>/i","<itemImage>$1</itemImage>", $htmlsrc);
  $htmlsrc=$htmlsrc."</item>";
  $htmlsrc="<?phpxml version=\"1.0\" encoding=\"UTF-8\"?>\r\n".$htmlsrc."";
  $htmlsrc=str_replace("&","&",$htmlsrc);
  try{
   $htmlsrc = simplexml_load_string($htmlsrc);
   $htmlsrc = (array) $htmlsrc;
  } catch (Exception $e) {
   $htmlsrc=array();
  } 
  $jsonAsrc=explode("var g_rgAppContextData = ",$source);
  $jsonAsrc=explode("var g_rgAssets",$jsonAsrc[1]);
  $jsonAsrc=explode("\"".$htmlsrc['catAppid']."\":",$jsonAsrc[0]);
  $jsonAsrc=explode("};",$jsonAsrc[1]);
  if(strpos($jsonAsrc[0],"},")){
   $jsonAsrc=explode("},",$jsonAsrc[0]);
   $jsonAsrc=explode(":{",$jsonAsrc[1]);
   $jsonAsrc=(array) json_decode("{".$jsonAsrc[1],true);
  }
  else{
   $jsonAsrc=(array) json_decode($jsonAsrc[0],true);
  }
  $jsonBsrc=explode("var g_rgAssets = ",$source);
  $jsonBsrc=explode("var g_rgListingInfo",$jsonBsrc[1]);
  $jsonBsrc=explode("\"".$htmlsrc['catAppid']."\":",$jsonBsrc[0]);
  $jsonBsrc=explode("};",$jsonBsrc[1]);
  $jsonBsrc=(array) json_decode($jsonBsrc[0],true);
  foreach($jsonBsrc as $jsonItemsrc){
   $jsonBsrc=$jsonItemsrc;
  }			
  $o=1;
  foreach($jsonBsrc as $jsonItemsrc){
   if($o==1){
    $jsonItem=$jsonItemsrc;
    $o++;
   }
  }
  $jsonItemDesc="";
  foreach($jsonItem['descriptions'] as $jsonDescsrc){
   $jsonItemDesc.=$jsonDescsrc['value']."<br/>";
  }			
  $jsonItem['descriptions']=$jsonItemDesc;
  $output=array();
  $output['base']=$htmlsrc;
  $output['parent']=$jsonAsrc;
  $output['item']=$jsonItem;
  return $output;
 }
 public static function loginUrl($returnTo=false, $useAmp=true) {
  $returnTo = (!$returnTo) ? (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] : $returnTo;
  $params = array('openid.ns'=>self::STEAM_OPENID,'openid.mode'=>'checkid_setup','openid.return_to'=> $returnTo,'openid.realm'=>(!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'],'openid.identity'=>self::STEAM_OPENID.'/identifier_select','openid.claimed_id'=>self::STEAM_OPENID.'/identifier_select');
  $sep = ($useAmp) ? '&' : '&';
  return self::STEAM_LOGIN . '?' . http_build_query($params, '', $sep);
 }
 public static function loginValidate() {
  $params = array('openid.assoc_handle'=>$_GET['openid_assoc_handle'],'openid.signed'=>$_GET['openid_signed'],'openid.sig'=>$_GET['openid_sig'],'openid.ns'=>self::STEAM_OPENID);
  $signed = explode(',', $_GET['openid_signed']);
  foreach($signed as $item) {
   $val = $_GET['openid_' . str_replace('.', '_', $item)];
   $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val; 
  }
  $params['openid.mode'] = 'check_authentication';
  $data =  http_build_query($params);
  $context = stream_context_create(array('http' => array('method'=>'POST','header'=>"Accept-language: en\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: ".strlen($data)."\r\n",'content'=>$data)));
  $result = file_get_contents(self::STEAM_LOGIN."/login", false, $context);
  preg_match("#^".self::STEAM_LOGIN."/id/([0-9]{17,25})#", $_GET['openid_claimed_id'], $matches);
  $steamid64 = is_numeric($matches[1]) ? $matches[1] : 0;
  return preg_match("#is_valid\s*:\s*true#i", $result) == 1 ? $steamid64 : false;
 }
}