This commit is contained in:
2026-03-03 16:30:57 +07:00
parent a13304e40e
commit c253e1a370
7569 changed files with 1324841 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,134 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Map extends REST_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('url', 'maps_helper', 'quota_limiter'));
date_default_timezone_set('Asia/Jakarta');
}
public function index_get()
{
$this->response(array(
'message' => 'Map API ready',
), 200);
}
/**
* POST /api/map/directions
* Body: { "origin_lat": 0.0, "origin_lng": 0.0, "dest_lat": 0.0, "dest_lng": 0.0, "mode": "driving" }
*/
public function directions_post()
{
// Simple per-IP quota limiting for map directions.
$hour_limit = (defined('MAPS_LIMIT_PER_HOUR') && MAPS_LIMIT_PER_HOUR !== '') ? (int) MAPS_LIMIT_PER_HOUR : 1000;
$day_limit = (defined('MAPS_LIMIT_PER_DAY') && MAPS_LIMIT_PER_DAY !== '') ? (int) MAPS_LIMIT_PER_DAY : 5000;
$limits = array(
'hour' => $hour_limit,
'day' => $day_limit,
);
$key = 'maps:ip:' . $this->input->ip_address();
if (!quota_limiter_allow($key, $limits)) {
$this->response(array(
'code' => '429',
'message' => 'maps_quota_exceeded',
), 200);
return;
}
$data = json_decode(file_get_contents('php://input'), true);
if (!is_array($data)) {
$this->response(array(
'code' => '400',
'message' => 'invalid_json',
), 200);
return;
}
if (!isset($data['origin_lat'], $data['origin_lng'], $data['dest_lat'], $data['dest_lng'])) {
$this->response(array(
'code' => '400',
'message' => 'missing_coordinates',
), 200);
return;
}
$mode = isset($data['mode']) && is_string($data['mode']) ? $data['mode'] : 'driving';
$result = maps_directions(
(float) $data['origin_lat'],
(float) $data['origin_lng'],
(float) $data['dest_lat'],
(float) $data['dest_lng'],
$mode
);
if ($result === null) {
$this->response(array(
'code' => '500',
'message' => 'maps_error',
), 200);
return;
}
// Proxy Google Directions JSON structure directly so clients can parse as before.
$this->response($result, 200);
}
/**
* POST /api/map/geocode
* Body: { "lat": 0.0, "lng": 0.0 }
*/
public function geocode_post()
{
$hour_limit = (defined('MAPS_LIMIT_PER_HOUR') && MAPS_LIMIT_PER_HOUR !== '') ? (int) MAPS_LIMIT_PER_HOUR : 1000;
$day_limit = (defined('MAPS_LIMIT_PER_DAY') && MAPS_LIMIT_PER_DAY !== '') ? (int) MAPS_LIMIT_PER_DAY : 5000;
$limits = array(
'hour' => $hour_limit,
'day' => $day_limit,
);
$key = 'maps:ip:' . $this->input->ip_address() . ':geocode';
if (!quota_limiter_allow($key, $limits)) {
$this->response(array(
'code' => '429',
'message' => 'maps_quota_exceeded',
), 200);
return;
}
$data = json_decode(file_get_contents('php://input'), true);
if (!is_array($data)) {
$this->response(array(
'code' => '400',
'message' => 'invalid_json',
), 200);
return;
}
if (!isset($data['lat'], $data['lng'])) {
$this->response(array(
'code' => '400',
'message' => 'missing_lat_lng',
), 200);
return;
}
$result = maps_geocode((float) $data['lat'], (float) $data['lng']);
if ($result === null) {
$this->response(array(
'code' => '500',
'message' => 'maps_error',
), 200);
return;
}
// Proxy Google Geocode JSON structure directly.
$this->response($result, 200);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,58 @@
<?php
$server_key = "SB-Mid-server-hsIqSFfLTy9a5YPggvT48agq";
$is_production = false;
$api_url = $is_production ?
'https://app.midtrans.com/snap/v1/transactions' :
'https://app.sandbox.midtrans.com/snap/v1/transactions';
if (!strpos($_SERVER['REQUEST_URI'], '/charge')) {
http_response_code(404);
echo "wrong path, make sure it's `/charge`";
exit();
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(404);
echo "Page not found or wrong HTTP request method is used";
exit();
}
$request_body = file_get_contents('php://input');
header('Content-Type: application/json');
$charge_result = chargeAPI($api_url, $server_key, $request_body);
http_response_code($charge_result['http_code']);
echo $charge_result['body'];
function chargeAPI($api_url, $server_key, $request_body)
{
$ch = curl_init();
$curl_options = array(
CURLOPT_URL => $api_url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Basic ' . base64_encode($server_key . ':')
),
CURLOPT_POSTFIELDS => $request_body
);
curl_setopt_array($ch, $curl_options);
$result = array(
'body' => curl_exec($ch),
'http_code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
);
return $result;
}
@@ -0,0 +1,91 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Notification extends REST_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('url'));
$this->load->model('notification_model', 'notif');
date_default_timezone_set('Asia/Jakarta');
}
/**
* Simple health check for the notification API.
*/
public function index_get()
{
$this->response(array(
'message' => 'Notification API ready',
), 200);
}
/**
* Generic FCM send endpoint.
*
* Expected JSON body:
* {
* "target": "device_or_topic",
* "is_topic": false,
* "data": { ... arbitrary key/value pairs ... },
* "title": "optional notification title",
* "body": "optional notification body"
* }
*/
public function send_generic_post()
{
$raw = file_get_contents('php://input');
$decoded = json_decode($raw, true);
if (!is_array($decoded)) {
$this->response(array(
'code' => '400',
'message' => 'invalid_json',
), 200);
return;
}
$target = isset($decoded['target']) ? trim($decoded['target']) : '';
$is_topic = !empty($decoded['is_topic']);
$data = isset($decoded['data']) && is_array($decoded['data']) ? $decoded['data'] : array();
$title = isset($decoded['title']) ? (string) $decoded['title'] : '';
$body = isset($decoded['body']) ? (string) $decoded['body'] : '';
if ($target === '' || empty($data)) {
$this->response(array(
'code' => '400',
'message' => 'missing_target_or_data',
), 200);
return;
}
$options = array();
if ($title !== '' || $body !== '') {
$options['title'] = $title;
$options['body'] = $body;
}
if ($is_topic) {
$result = $this->notif->send_generic_to_topic($target, $data, $options);
} else {
$result = $this->notif->send_generic_to_token($target, $data, $options);
}
if ($result === false) {
$this->response(array(
'code' => '500',
'message' => 'fcm_send_failed_or_quota_exceeded',
), 200);
return;
}
$this->response(array(
'code' => '200',
'message' => 'success',
), 200);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,51 @@
<?php
class Xendit extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('appsettings_model', 'app');
}
public function data_post()
{
$model = $this->app->getappbyid();
$data = json_decode(file_get_contents('php://input'), true);
$key = $model['api_keyxendit']; //jika ganti xendit akun cukup ubah ini aja
$pass = "";
if($data['ServerKey'] == $model['apikey_server']){ //dan ini untuk sisi authorization dari android request ke server kita "UkFKQU1BU1RFUlNFUlZFUg=="
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.xendit.co/ewallets",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"Authorization: Basic ".base64_encode("$key:$pass")."",
"Content-Type: application/json",
//"Cookie: nlbi_2182539=BeDEGL4nnQIMRSl/jjCKbQAAAACdtzIPLHKtA/1t0rshQlnG; visid_incap_2182539=T63r/YikR3SNAzVcIiMVuBJtRl8AAAAAQUIPAAAAAAAO48RqXhljt8XIX4HsIaBQ; incap_ses_1114_2182539=ilBwI4mA+ynuqcDyQrl1DxJtRl8AAAAApLvYahTdJBFGMhOzY0AX0A=="
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
}else{
echo json_encode(array(['msg'=> "Failed Key", 'code'=> 500]));
}
}
}