From: Christian Weiske Date: Sat, 25 Jan 2020 17:43:58 +0000 (+0100) Subject: Active purchasing (non-static) X-Git-Tag: v1.0.0~5 X-Git-Url: https://git.cweiske.de/stouyapi.git/commitdiff_plain/eb1adeed23d43d79841c123a9c34e4ea5c6ed2ce?hp=640eb314fdea7fa2eb9e66d00e8cae785a6cd218 Active purchasing (non-static) --- diff --git a/www/.htaccess b/www/.htaccess index 1ba4fcc..1587472 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -20,6 +20,10 @@ RewriteRule ^api/v1/discover/?$ /api/v1/discover-data/discover.json [END] RewriteRule ^api/v1/discover/(.+)$ /api/v1/discover-data/$1.json [END] #purchased games/products +# active buy requests +RewriteCond %{REQUEST_METHOD} POST +RewriteRule ^api/v1/games/(.+)/purchases?$ /api/v1/games/purchase.php [END] + RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^api/v1/games/(.+)/purchases?$ /api/v1/games/purchases-empty.json [END] diff --git a/www/api/v1/games/purchase.php b/www/api/v1/games/purchase.php new file mode 100644 index 0000000..38e58d2 --- /dev/null +++ b/www/api/v1/games/purchase.php @@ -0,0 +1,54 @@ +blob)); +if ($buyRequest === null) { + echo "Error decoding encrypted inner JSON data\n"; + exit(1); +} +if (!isset($buyRequest->uuid)) { + echo "uuid key missing in JSON data\n"; + exit(1); +} +if (!isset($buyRequest->identifier)) { + echo "identifier key missing in JSON data\n"; + exit(1); +} + +ini_set('html_errors', false); + +$productFiles = glob( + __DIR__ . '/../developers/*/products/' + . $buyRequest->identifier . '.json' +); +if (!count($productFiles)) { + echo "Cannot find product file for product identifier\n"; + exit(1); +} +$product = json_decode(file_get_contents($productFiles[0]))->products[0]; +if ($product === null) { + echo "could not find product in purchases file\n"; + exit(1); +} + +$payload = $product; +$payload->uuid = $buyRequest->uuid; + +$enc = [ + 'key' => base64_encode('0123456789abcdef'), + 'iv' => 't3jir1LHpICunvhlM76edQ==',//random bytes + 'blob' => base64_encode( + json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) + ), +]; +echo json_encode($enc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"; +?>