Skip to content
Snippets Groups Projects
Commit 92948319 authored by SaktiWidyatmaja's avatar SaktiWidyatmaja
Browse files

feat: add premium request api

parent fd47ebd9
No related merge requests found
<?php
require_once __DIR__ . '/../../../config/config.php';
if (isset($_ENV['SOAP_URL'])) {
$url = $_ENV['SOAP_URL'];
} else if (isset($_ENV['SOLO_DOCKER'])) {
$url = "http://host.docker.internal:8888/ws/subscription";
} else {
$url = "http://localhost:8888/ws/subscription";
}
$id = $_POST['user_id'];
$request_param = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<approveRequest xmlns="http://services.appnote/">
<arg0 xmlns="">'. $id . '</arg0>
<arg1 xmlns="">'. $_ENV['REST_API_KEY'] . '</arg1>
</approveRequest>
</soap:Body>
</soap:Envelope>
';
printf("ppp");
printf($_ENV['REST_API_KEY']);
printf($id);
printf("ppp");
$headers = array(
"Content-Type: text/xml;charset=\"utf-8\"",
'Content-Length: ' .strlen($request_param),
'X-API-Key: ' . $_ENV['SOAP_API_KEY']
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
if ($response === FALSE) {
printf("CURL error (#%d): %s<br>\n", curl_errno($ch),
htmlspecialchars(curl_error($ch)));
}
$response1 = str_replace('<?xml version=\'1.0\' encoding=\'UTF-8\'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:approveRequestResponse xmlns:ns2="http://services.appnote/"><return>',"",$response);
$response2 = str_replace("</return></ns2:approveRequestResponse></S:Body></S:Envelope>","",$response1);
printf($response);
$obj = json_decode($response2);
$data = $obj->data;
// $row_count = 0;
// for ($i = 0; $i < count($data); $i++) {
// $row_count += $subscription_model->upsertSubscription($data[$i]->creator_id, $data[$i]->subscriber_id, $data[$i]->status);
// }
http_response_code(200);
echo json_encode($data);
\ No newline at end of file
<?php
require_once __DIR__ . '/../../../config/config.php';
if (isset($_ENV['SOAP_URL'])) {
$url = $_ENV['SOAP_URL'];
} else if (isset($_ENV['SOLO_DOCKER'])) {
$url = "http://host.docker.internal:8888/ws/subscription";
} else {
$url = "http://localhost:8888/ws/subscription";
}
$request_param = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getAllRequest xmlns="http://services.appnote/">
<arg0 xmlns="">'. $_ENV['REST_API_KEY'] . '</arg0>
</getAllRequest>
</soap:Body>
</soap:Envelope>
';
$headers = array(
"Content-Type: text/xml;charset=\"utf-8\"",
'Content-Length: ' .strlen($request_param),
'X-API-Key: ' . $_ENV['SOAP_API_KEY']
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
if ($response === FALSE) {
printf("CURL error (#%d): %s<br>\n", curl_errno($ch),
htmlspecialchars(curl_error($ch)));
}
$response = trim($response); // Remove leading/trailing whitespace
// Remove any extra content after </S:Envelope>
$response = preg_replace('/<\/S:Envelope>.*$/s', '</S:Envelope>', $response);
$doc = new DOMDocument();
$doc->loadXML($response);
// Mendapatkan semua elemen 'return'
$returns = $doc->getElementsByTagName('return');
$data = array();
foreach ($returns as $return) {
// Mendapatkan elemen-elemen di dalam 'return'
$status = $return->getElementsByTagName('status')->item(0)->nodeValue;
$userId = $return->getElementsByTagName('userId')->item(0)->nodeValue;
// Menambahkan ke dalam array data
$data[] = array('status' => $status, 'userId' => $userId);
}
// Menghasilkan format JSON yang diinginkan
$result = json_encode(array('data' => $data));
// Mengirimkan response JSON
http_response_code(200);
echo $result;
<?php
require_once __DIR__ . '/../../../config/config.php';
if (isset($_ENV['SOAP_URL'])) {
$url = $_ENV['SOAP_URL'];
} else if (isset($_ENV['SOLO_DOCKER'])) {
$url = "http://host.docker.internal:8888/ws/subscription";
} else {
$url = "http://localhost:8888/ws/subscription";
}
$id = $_POST['user_id'];
$request_param = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<rejectRequest xmlns="http://services.appnote/">
<arg0 xmlns="">'. $id . '</arg0>
<arg1 xmlns="">'. $_ENV['REST_API_KEY'] . '</arg1>
</rejectRequest>
</soap:Body>
</soap:Envelope>
';
$headers = array(
"Content-Type: text/xml;charset=\"utf-8\"",
'Content-Length: ' .strlen($request_param),
'X-API-Key: ' . $_ENV['SOAP_API_KEY']
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_param);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
if ($response === FALSE) {
printf("CURL error (#%d): %s<br>\n", curl_errno($ch),
htmlspecialchars(curl_error($ch)));
}
$response1 = str_replace('<?xml version=\'1.0\' encoding=\'UTF-8\'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:rejectRequestResponse xmlns:ns2="http://services.appnote/"><return>',"",$response);
$response2 = str_replace("</return></ns2:rejectRequestResponse></S:Body></S:Envelope>","",$response1);
$obj = json_decode($response2);
$data = $obj->data;
// $row_count = 0;
// for ($i = 0; $i < count($data); $i++) {
// $row_count += $subscription_model->upsertSubscription($data[$i]->creator_id, $data[$i]->subscriber_id, $data[$i]->status);
// }
http_response_code(200);
echo json_encode($data);
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment