whoami7 - Manager
:
/
home
/
simspala
/
yoursimzone.com
/
Upload File:
files >> /home/simspala/yoursimzone.com/refresh.php
<?php /** * refresh.php — yoursimzone.com * ✅ Full version with raw + parsed logging, fallback parsing, and clean numeric airtime */ declare(strict_types=1); header('Content-Type: application/json'); date_default_timezone_set('Africa/Lagos'); $input = json_decode(file_get_contents('php://input'), true); $msisdn = $input['msisdn'] ?? null; if (!$msisdn) { echo json_encode(['status' => false, 'message' => 'Missing msisdn']); exit; } $auth = $_SERVER['HTTP_AUTHORIZATION'] ?? ''; $url = 'https://mtn-dxl-ucut-services.mymtnnxgeaprod.mtnnigeria.net/v1/ucut/customerBalance'; $log = __DIR__ . '/refresh_log.txt'; /*────────────────────────────── | 🔁 Call MTN UCUT API *──────────────────────────────*/ $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 45, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_HTTPHEADER => [ 'Authorization: ' . $auth, 'Channel: MTNAPPNXG', 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode(['msisdn' => $msisdn]), ]); $response = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $err = curl_error($ch); curl_close($ch); /*────────────────────────────── | 🧾 Log RAW response *──────────────────────────────*/ file_put_contents( $log, sprintf("[%s] HTTP %d | %s | %s\n", date('Y-m-d H:i:s'), $code, $msisdn, substr($response ?: $err, 0, 400)), FILE_APPEND ); if (!$response) { echo json_encode(['status' => false, 'message' => $err ?: 'No response from UCUT']); exit; } /*────────────────────────────── | 🧩 Decode JSON *──────────────────────────────*/ $json = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { echo json_encode(['status' => false, 'message' => 'Invalid JSON from UCUT']); exit; } /*────────────────────────────── | 🧠 Extract Airtime + Data + Expiry *──────────────────────────────*/ $airtime = $data = $expire = null; // 1️⃣ Fallback if MTN omits "balance" if (empty($json['data']['balance']) && !empty($json['data']['usageCounterAndThreshold'])) { foreach ($json['data']['usageCounterAndThreshold'] as $item) { $counter = $item['usageCounter'] ?? []; if (!empty($counter['value'])) { $json['data']['balance'][] = [ 'balanceType' => 'Main Balance', 'balanceDetail' => [ 'activeValue' => str_replace(',', '', $counter['value']), 'activeUnit' => $counter['unit'] ?? 'NGN' ], 'wallets' => [] ]; } } } // 2️⃣ Parse final balances foreach ($json['data']['balance'] ?? [] as $b) { $type = strtolower($b['balanceType'] ?? ''); $detail = $b['balanceDetail'] ?? []; if ($type === 'main balance') { $raw = $detail['activeValue'] ?? null; if ($raw !== null) { // Remove commas and cast to float $clean = str_replace(',', '', $raw); $airtime = is_numeric($clean) ? (float)$clean : $clean; } } elseif ($type === 'data bundle') { $val = $detail['activeValue'] ?? null; $unit = $detail['activeUnit'] ?? ''; $data = trim(($val ? "{$val} {$unit}" : '')); $expire = $b['wallets'][0]['expiryDate'] ?? null; if ($expire) { $expire = date('Y-m-d H:i:s', strtotime($expire)); } } } /*────────────────────────────── | 🧾 Log parsed info *──────────────────────────────*/ file_put_contents( $log, sprintf("[%s] PARSED | %s | airtime=%s | data=%s | expire=%s\n", date('Y-m-d H:i:s'), $msisdn, $airtime ?? 'null', $data ?? 'null', $expire ?? 'null' ), FILE_APPEND ); /*────────────────────────────── | ✅ Return normalized response *──────────────────────────────*/ http_response_code($code); echo json_encode($json);
Copyright ©2021 || Defacer Indonesia