-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteamGame.class.php
64 lines (63 loc) · 2.13 KB
/
SteamGame.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
class SteamGame {
private $appid = null;
private $gameData = null;
function __construct($appid){
$this->appid = $appid;
$context = stream_context_create(
array(
"http"=> array(
"method" => "GET",
"ignore_errors" => true
)
)
);
$json = file_get_contents("https://store.steampowered.com/api/appdetails?appids=" . $appid, false, $context);
preg_match('/HTTP\/1\.[0|1|x] ([0-9]{3})/', $http_response_header[0], $matches);
$status_code = $matches[1];
if($status_code != 200){
throw new Exception("Failed to get SteamGameData. (" . $http_response_header[0] . ")");
}
$array = json_decode($json, true);
$this->gameData = $array[$appid];
if(!$this->gameData["success"]){
throw new Exception("Failed to get SteamGameData.");
$this->gameData = null;
}
}
// ゲーム名
function getName(){
if($this->gameData == null){
throw new Exception("Failed to get SteamGameData.");
}
return $this->gameData["data"]["name"];
}
// 定価
function getInitialPrice(){
if($this->gameData == null){
throw new Exception("Failed to get SteamGameData.");
}
return $this->gameData["data"]["price_overview"]["initial"] / 100;
}
// 現在価格
function getCurrencyPrice(){
if($this->gameData == null){
throw new Exception("Failed to get SteamGameData.");
}
return $this->gameData["data"]["price_overview"]["final"] / 100;
}
// JPY 価格単位
function getCurrencyName(){
if($this->gameData == null){
throw new Exception("Failed to get SteamGameData.");
}
return $this->gameData["data"]["price_overview"]["currency"];
}
// 割引
function getDiscountPercent(){
if($this->gameData == null){
throw new Exception("Failed to get SteamGameData.");
}
return $this->gameData["data"]["price_overview"]["discount_percent"];
}
}