Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
1,563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. <?php
  2.  
  3. class SteamAPI {
  4.  
  5. const version = '1.0';
  6. private $ids = '';
  7. private $api_key;
  8. private $pre_url = 'https://api.steampowered.com/';
  9.  
  10.  
  11.  
  12. ###################
  13. # GENERAL METHODS #
  14. ###################
  15.  
  16. private function add_steam_id($steamid){
  17. if(count($this->ids) == 0){
  18. $this->ids .= $steamid;
  19. } else {
  20. $this->ids .= ',' . $steamid;
  21. }
  22. }
  23.  
  24. public function set_api_key($api_key){
  25. $this->api_key = $api_key;
  26. }
  27.  
  28. private function get_content($uri){
  29. try{
  30. $content = file_get_contents($uri);
  31. $content = json_decode($content, true);
  32. return $content;
  33. } catch(Exception $e){
  34. echo $e->getMessage();
  35. }
  36.  
  37. }
  38.  
  39. private function array_steamids($steamids){
  40. return explode(',', $steamids);
  41. }
  42.  
  43.  
  44. ###############
  45. # API METHODS #
  46. ###############
  47.  
  48.  
  49. public function GetGamePrice($appid, $currency=[]){
  50. $country_codes = array(
  51. 'ae', 'au', 'br', 'cn', 'dk', 'es', 'gb', 'hr', 'ie', 'ir', 'jp', 'lt', 'ly', 'mx', 'no', 'ph', 'pt', 'rs', 'se', 'sk', 'tw', 'ar',
  52. 'be', 'ca', 'cz', 'dz', 'fi', 'gr', 'hu', 'il', 'is', 'kr', 'lu', 'mk', 'my', 'nz', 'pk', 're', 'ru', 'sg', 'th', 'ua', 'za', 'at',
  53. 'bg', 'cl', 'de', 'ee', 'fr', 'hk', 'id', 'in', 'it', 'kz', 'lv', 'mo', 'nl', 'pe', 'pl', 'ro', 'sa', 'si', 'tr', 'us', 'by'
  54. );
  55.  
  56. $array_countries = [];
  57.  
  58.  
  59. if(!empty($currency) && is_array($currency)){
  60. $array_countries = $currency;
  61. } else {
  62. $array_countries = $country_codes;
  63. }
  64.  
  65. $prices = [];
  66. foreach ($array_countries as $code) {
  67. $url = 'http://store.steampowered.com/api/appdetails?appids=' . $appid . '&filters=price_overview&cc=' . $code;
  68. $handler = $this->get_content($url);
  69.  
  70. if($handler[$appid]['success']){
  71. foreach ($handler[$appid]['data'] as $h) {
  72. $price = [];
  73. $price['appid'] = $appid;
  74. $price['currency'] = $h['currency'];
  75. $price['initial'] = $h['initial'];
  76. $price['final'] = $h['final'];
  77. $price['discount_percent'] = $h['discount_percent'];
  78. array_push($prices, $price);
  79. }
  80. }
  81. }
  82.  
  83. return $prices;
  84. }
  85.  
  86. }
  87.  
  88.  
  89. $file = "prices.json";
  90. $steam_id = '57690';
  91. $api_key = 'BE66BE20E6C1C22C563A4DE0BCE08AAD';
  92. $steamAPI = new SteamAPI($steam_id, $api_key);
  93. $handler = $steamAPI->GetGamePrice($steam_id, array('pl', 'us'));
  94.  
  95. header('Content-type:application/json;charset=utf-8');
  96. echo json_encode($handler);
  97. file_put_contents($file, json_encode($handler));
  98.  
  99.  
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement