mirror of
https://github.com/ManfredAabye/opensimcurrencyserver-dotnet-tests.git
synced 2026-08-14 00:47:56 +00:00
Update moneyserver_api.php V3
This commit is contained in:
+115
-43
@@ -1,20 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Moneyserver API Tester</title>
|
||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||
</head>
|
||||
<body class="w3-light-grey">
|
||||
|
||||
<div class="w3-container w3-padding w3-card-4 w3-margin w3-white">
|
||||
<h2 class="w3-text-blue">Moneyserver API Test</h2>
|
||||
<form class="w3-container" method="post">
|
||||
<label class="w3-text-blue">API URL</label>
|
||||
<input class="w3-input w3-border w3-margin-bottom" name="url" value="<?= htmlspecialchars($_POST['url'] ?? 'http://localhost:8008/api/json') ?>" required>
|
||||
<label class="w3-text-blue">API Key</label>
|
||||
<input class="w3-input w3-border w3-margin-bottom" name="apiKey" value="<?= htmlspecialchars($_POST['apiKey'] ?? '123456789') ?>" required>
|
||||
<label class="w3-text-blue">Allowed User</label>
|
||||
<input class="w3-input w3-border w3-margin-bottom" name="allowedUser" value="<?= htmlspecialchars($_POST['allowedUser'] ?? 'myadminuser') ?>" required>
|
||||
<label class="w3-text-blue">User ID</label>
|
||||
<input class="w3-input w3-border w3-margin-bottom" name="userID" value="<?= htmlspecialchars($_POST['userID'] ?? 'test-user-id') ?>" required>
|
||||
<button class="w3-button w3-blue w3-margin-top" type="submit">Tests starten</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// UTF-8 für Sonderzeichen (z.B. Emojis)
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST'):
|
||||
$url = $_POST['url'] ?? 'http://localhost:8008/api/json';
|
||||
$apiKey = $_POST['apiKey'] ?? '123456789';
|
||||
$allowedUser = $_POST['allowedUser'] ?? 'myadminuser';
|
||||
$userID = $_POST['userID'] ?? 'test-user-id';
|
||||
|
||||
// Fehlerausgabe aktivieren
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
function assertEquals($expected, $actual, $message) {
|
||||
if ($expected === $actual) {
|
||||
echo "<span class='w3-tag w3-green w3-round w3-small'>✔ $message</span><br>";
|
||||
} else {
|
||||
echo "<span class='w3-tag w3-red w3-round w3-small'>✘ $message (Erwartet: " . htmlspecialchars(var_export($expected, true)) . ", Bekommen: " . htmlspecialchars(var_export($actual, true)) . ")</span><br>";
|
||||
}
|
||||
}
|
||||
|
||||
$url = 'http://localhost:8008/api/json'; // ggf. anpassen
|
||||
$apiKey = '123456789';
|
||||
$allowedUser = 'myadminuser';
|
||||
$userID = 'test-user-id'; // Ersetze ggf. durch gültige UUID oder Namen
|
||||
|
||||
function sendRequest($data)
|
||||
{
|
||||
function sendRequest($data, $check = null) {
|
||||
global $url, $apiKey, $allowedUser;
|
||||
|
||||
$data['apiKey'] = $apiKey;
|
||||
$data['allowedUser'] = $allowedUser;
|
||||
|
||||
@@ -26,24 +50,21 @@ function sendRequest($data)
|
||||
'timeout' => 10
|
||||
]
|
||||
];
|
||||
|
||||
$context = stream_context_create($options);
|
||||
$result = @file_get_contents($url, false, $context);
|
||||
|
||||
echo "<div style='margin-bottom:1em;border-bottom:1px solid #ccc;'>";
|
||||
echo "<b>➡️ Aktion:</b> <code>{$data['action']}</code><br>";
|
||||
echo "<div class='w3-card w3-margin w3-padding'>";
|
||||
echo "<b class='w3-text-blue'>➡️ Aktion:</b> <code>" . htmlspecialchars($data['action']) . "</code><br>";
|
||||
|
||||
if ($result === FALSE) {
|
||||
// Fehlerausgabe im Browser
|
||||
echo "<span style='color:red;'>❌ Fehler beim Zugriff auf die API!</span><br>";
|
||||
// HTTP-Header anzeigen, falls vorhanden
|
||||
echo "<span class='w3-tag w3-red w3-round'>❌ Fehler beim Zugriff auf die API!</span><br>";
|
||||
global $http_response_header;
|
||||
if (isset($http_response_header)) {
|
||||
echo "<b>HTTP-Header:</b> <pre>" . htmlspecialchars(implode("\n", $http_response_header)) . "</pre>";
|
||||
echo "<b>HTTP-Header:</b> <pre class='w3-small'>" . htmlspecialchars(implode("\n", $http_response_header)) . "</pre>";
|
||||
}
|
||||
$error = error_get_last();
|
||||
if ($error) {
|
||||
echo "<b>Fehlertext:</b> <pre>" . htmlspecialchars($error['message']) . "</pre>";
|
||||
echo "<b>Fehlertext:</b> <pre class='w3-small'>" . htmlspecialchars($error['message']) . "</pre>";
|
||||
}
|
||||
echo "</div>";
|
||||
return;
|
||||
@@ -51,40 +72,65 @@ function sendRequest($data)
|
||||
|
||||
$response = json_decode($result, true);
|
||||
echo "<b>Antwort:</b><br>";
|
||||
echo "<pre>" . htmlspecialchars(print_r($response, true)) . "</pre>";
|
||||
echo "<pre class='w3-small'>" . htmlspecialchars(print_r($response, true)) . "</pre>";
|
||||
|
||||
if ($check) {
|
||||
$check($response);
|
||||
}
|
||||
|
||||
echo "</div>";
|
||||
}
|
||||
|
||||
// Aktionen testen
|
||||
sendRequest(['action' => 'getbalance', 'userID' => $userID]);
|
||||
sendRequest(['action' => 'getTransactionNum', 'userID' => $userID, 'startTime' => 0, 'endTime' => time()]);
|
||||
sendRequest(['action' => 'UserExists', 'userID' => $userID]);
|
||||
// Tests für alle wichtigen API-Aktionen:
|
||||
sendRequest(['action' => 'getbalance', 'userID' => $userID], function($res) {
|
||||
assertEquals(true, isset($res['balance']), 'Balance-Feld vorhanden');
|
||||
assertEquals(true, is_numeric($res['balance'] ?? null), 'Balance ist numerisch');
|
||||
});
|
||||
|
||||
sendRequest(['action' => 'getTransactionNum', 'userID' => $userID, 'startTime' => 0, 'endTime' => time()], function($res) {
|
||||
assertEquals(true, isset($res['num']), 'num-Feld vorhanden');
|
||||
});
|
||||
|
||||
sendRequest(['action' => 'UserExists', 'userID' => $userID], function($res) {
|
||||
assertEquals(true, isset($res['exists']), 'Exists-Feld vorhanden');
|
||||
assertEquals(true, is_bool($res['exists'] ?? null), 'Exists ist boolean');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'withdrawMoney',
|
||||
'userID' => $userID,
|
||||
'transactionID' => '00000000-0000-0000-0000-000000000000',
|
||||
'amount' => 100
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (withdrawMoney)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'giveMoney',
|
||||
'transactionID' => '00000000-0000-0000-0000-000000000000',
|
||||
'receiverID' => 'some-receiver-id',
|
||||
'amount' => 50
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (giveMoney)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'BuyMoney',
|
||||
'transactionID' => '00000000-0000-0000-0000-000000000000',
|
||||
'amount' => 75
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (BuyMoney)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'addTransaction',
|
||||
'transaction' => [
|
||||
'TransactionID' => '00000000-0000-0000-0000-000000000000',
|
||||
'UserID' => $userID,
|
||||
// weitere Felder je nach Definition
|
||||
'UserID' => $userID
|
||||
]
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (addTransaction)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'addUser',
|
||||
@@ -92,29 +138,39 @@ sendRequest([
|
||||
'balance' => 1000,
|
||||
'status' => 1,
|
||||
'type' => 0
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (addUser)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'BuyCurrency',
|
||||
'userID' => $userID,
|
||||
'amount' => 50
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (BuyCurrency)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'SetTransExpired',
|
||||
'deadTime' => 600
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (SetTransExpired)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'ValidateTransfer',
|
||||
'secureCode' => 'abc123',
|
||||
'transactionID' => '00000000-0000-0000-0000-000000000000'
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['valid']), 'valid-Feld vorhanden (ValidateTransfer)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'FetchUserInfo',
|
||||
'userID' => $userID
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['userID']), 'userID-Feld vorhanden (FetchUserInfo)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'updateTransactionStatus',
|
||||
@@ -122,19 +178,25 @@ sendRequest([
|
||||
'transactionID' => '00000000-0000-0000-0000-000000000000',
|
||||
'status' => 2,
|
||||
'description' => 'Updated via test script'
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (updateTransactionStatus)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'DoTransfer',
|
||||
'userID' => $userID,
|
||||
'transactionID' => '00000000-0000-0000-0000-000000000000'
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (DoTransfer)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'DoAddMoney',
|
||||
'userID' => $userID,
|
||||
'transactionID' => '00000000-0000-0000-0000-000000000000'
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (DoAddMoney)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'FetchTransaction',
|
||||
@@ -142,7 +204,9 @@ sendRequest([
|
||||
'startTime' => 0,
|
||||
'endTime' => time(),
|
||||
'lastIndex' => 0
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['transactions']), 'transactions-Feld vorhanden (FetchTransaction)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'TryAddUserInfo',
|
||||
@@ -153,7 +217,9 @@ sendRequest([
|
||||
'Status' => 1,
|
||||
'Type' => 0
|
||||
]
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (TryAddUserInfo)');
|
||||
});
|
||||
|
||||
sendRequest([
|
||||
'action' => 'UpdateUserInfo',
|
||||
@@ -165,5 +231,11 @@ sendRequest([
|
||||
'Status' => 2,
|
||||
'Type' => 1
|
||||
]
|
||||
]);
|
||||
], function($res) {
|
||||
assertEquals(true, isset($res['success']), 'Success-Feld vorhanden (UpdateUserInfo)');
|
||||
});
|
||||
|
||||
endif;
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user