Skip to content

Instantly share code, notes, and snippets.

@Tampa
Created October 27, 2024 03:18
Show Gist options
  • Save Tampa/af55bb150f423e78bfa3d144bf98bc85 to your computer and use it in GitHub Desktop.
Save Tampa/af55bb150f423e78bfa3d144bf98bc85 to your computer and use it in GitHub Desktop.
New landtool.php for php7.4 and up
<?php
$request_xml = file_get_contents("php://input");
function preflightBuyLandPrep($method_name, $params, $app_data)
{
$req = new SimpleXMLElement(file_get_contents("php://input"));
$amount = $req->params[0]->param[0]->value[0]->struct[0]->member[3]->value[0]->int;
// Define the response data with the required order
$response_data = [
'membership' => [],
'landuse' => [
'upgrade' => false,
'action' => "http://invaliddomaininvalid.com/"
],
'success' => true,
'confirm' => "asdfajsdkfjasdkfjalsdfjasdf",
'currency' => [
'estimatedCost' => (int)$amount
]
];
// Initialize the root element
$response_xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><methodResponse></methodResponse>');
$params = $response_xml->addChild('params');
$param = $params->addChild('param');
$value = $param->addChild('value');
// Build the structure manually
$struct = $value->addChild('struct');
// Recursive function to add struct members in the correct order
function addStructMember(SimpleXMLElement $parent, $name, $value) {
$member = $parent->addChild('member');
$member->addChild('name', htmlspecialchars($name));
$val = $member->addChild('value');
if (is_array($value)) {
$subStruct = $val->addChild('struct');
foreach ($value as $key => $subValue) {
addStructMember($subStruct, $key, $subValue);
}
} else {
if (is_bool($value)) {
$val->addChild('boolean', $value ? '1' : '0');
} elseif (is_int($value)) {
$val->addChild('i4', $value);
} else {
$val->addChild('string', htmlspecialchars($value));
}
}
}
// Add each member to the struct in the correct order
foreach ($response_data as $key => $val) {
addStructMember($struct, $key, $val);
}
header("Content-type: text/xml");
print $response_xml->asXML();
return "";
}
$xmlrpc_server = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpc_server, "preflightBuyLandPrep", "preflightBuyLandPrep");
xmlrpc_server_call_method($xmlrpc_server, $request_xml, array());
xmlrpc_server_destroy($xmlrpc_server);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment