/**
* JavaScript Client Example
*/
async function launchGame(gameCode, vendorCode, jwtToken) {
const language = 'en';
const random = generateRandomString(12);
const timestamp = new Date().toLocaleString("en-IN", {timeZone: "Asia/Kolkata"});
// Generate signature
const signString = `{"gameCode":"${gameCode}","language":${language},"phonetype":"mobile","random":"${random}","vendorCode":${vendorCode}}`;
const signature = md5(signString).toUpperCase();
try {
const response = await fetch('/api/gamesintrigrated.php', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + jwtToken,
'Content-Type': 'application/json',
'X-API-Key': 'your-api-key'
},
body: JSON.stringify({
language: language,
random: random,
signature: signature,
timestamp: timestamp,
vendorCode: vendorCode,
gameCode: gameCode,
phonetype: 'mobile',
gameNameEn: 'Demo Game'
})
});
const result = await response.json();
if (result.code === 0) {
// Redirect to game URL
window.location.href = result.data.url;
} else {
console.error('Game launch failed:', result.msg);
alert('Failed to launch game: ' + result.msg);
}
return result;
} catch (error) {
console.error('Network error:', error);
throw error;
}
}
// Helper function to generate random string
function generateRandomString(length) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
<?php
/**
* PHP Client Example
*/
class GameLauncherClient {
private $jwtToken;
private $apiUrl;
public function __construct($jwtToken, $apiUrl = 'https://your-domain.com/api/gamesintrigrated.php') {
$this->jwtToken = $jwtToken;
$this->apiUrl = $apiUrl;
}
public function launchGame($gameCode, $vendorCode, $language = 'en', $phoneType = 'mobile') {
$random = $this->generateRandomString(12);
$timestamp = date('Y-m-d H:i:s');
// Generate signature
$signString = '{"gameCode":"'.$gameCode.'","language":'.$language.',"phonetype":"'.$phoneType.'","random":"'.$random.'","vendorCode":'.$vendorCode.'}';
$signature = strtoupper(md5($signString));
$payload = [
'language' => $language,
'random' => $random,
'signature' => $signature,
'timestamp' => $timestamp,
'vendorCode' => $vendorCode,
'gameCode' => $gameCode,
'phonetype' => $phoneType,
'gameNameEn' => 'Demo Game'
];
$ch = curl_init($this->apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $this->jwtToken,
'Content-Type: application/json',
'X-API-Key: your-api-key'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [
'http_code' => $httpCode,
'response' => json_decode($response, true)
];
}
private function generateRandomString($length = 12) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
}
// Usage example
$client = new GameLauncherClient('your-jwt-token-here');
$result = $client->launchGame('poker123', '18', 'en', 'mobile');
if ($result['http_code'] === 200 && $result['response']['code'] === 0) {
header('Location: ' . $result['response']['data']['url']);
exit;
} else {
echo 'Error: ' . $result['response']['msg'];
}
?>