<?php
date_default_timezone_set('Asia/Seoul');
require '/home/www/DB/key_upbit_trade.php';
$ACCESS_KEY = $UPBIT_ACCESS_KEY ?? '';
$SECRET_KEY = $UPBIT_SECRET_KEY ?? '';
$SERVER_URL = "https://api.upbit.com";
$b64url = function($d) { return rtrim(strtr(base64_encode($d), '+/', '-_'), '='); };
$make_jwt = function($ak, $sk, $query = []) use ($b64url) {
$h = ['alg'=>'HS256','typ'=>'JWT'];
$p = ['access_key'=>$ak,'nonce'=>uniqid('',true)];
if (!empty($query)) {
$qs = http_build_query($query);
$p['query_hash'] = hash('sha512', $qs);
$p['query_hash_alg'] = 'SHA512';
}
$hh = $b64url(json_encode($h));
$pp = $b64url(json_encode($p));
$ss = $b64url(hash_hmac('sha256', "$hh.$pp", $sk, true));
return "$hh.$pp.$ss";
};
// 게시판 최근 날짜
$row = sql_fetch("SELECT x2_time FROM g5_write_moving_assets ORDER BY x2_time DESC LIMIT 1");
$gnu_last_date = $row['x2_time'] ?: '2000-01-01 00:00:00';
// 입금 최근 100개
$params = ['limit'=>100];
$jwt = $make_jwt($ACCESS_KEY, $SECRET_KEY, $params);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $SERVER_URL."/v1/deposits?".http_build_query($params),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$jwt}"],
CURLOPT_TIMEOUT => 10,
]);
$dep_raw = json_decode(curl_exec($ch), true);
curl_close($ch);
// 출금 최근 100개
$params = ['limit'=>100];
$jwt = $make_jwt($ACCESS_KEY, $SECRET_KEY, $params);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $SERVER_URL."/v1/withdraws?".http_build_query($params),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$jwt}"],
CURLOPT_TIMEOUT => 10,
]);
$wit_raw = json_decode(curl_exec($ch), true);
curl_close($ch);
// 게시판 최근 날짜 이후 + ACCEPTED만 필터링
$dep = [];
if (is_array($dep_raw)) {
foreach ($dep_raw as $d) {
$api_date = date('Y-m-d H:i:s', strtotime($d['created_at']));
if ($api_date > $gnu_last_date && ($d['state'] ?? '') === 'ACCEPTED') $dep[] = $d;
}
}
$wit = [];
if (is_array($wit_raw)) {
foreach ($wit_raw as $d) {
$api_date = date('Y-m-d H:i:s', strtotime($d['created_at']));
if ($api_date > $gnu_last_date && ($d['state'] ?? '') === 'ACCEPTED') $wit[] = $d;
}
}
// 글쓰기 주소
$write_url_base = "write.php?bo_table={$bo_table}&w=";
$target_num = 1;
$page_num = 1;
?>
<style>
.api-table { width:100%; border:1px solid #1e293b; border-bottom: 0px; border-radius: 5px; margin-bottom:40px; }
.api-table th { background: #101c30; color:#94a3b8; padding:6px 10px; text-align:left; border-bottom:1px solid #333; font-size: 1rem; text-align:center; padding:10px; }
.api-table td { border-bottom:1px solid #222; font-size:0.9rem; padding:15px 20px; }
.api-table tr.has-link:hover td { background:#1e293b; cursor:pointer; }
.api-h2 { color:#f0a500; font-size:1.2rem; margin:20px 0 8px; padding-left:15px; }
.no-data { color:#64748b; text-align: center; }
</style>
<h2 class="api-h2">입금</h2>
<table class="api-table">
<tr><th>번호</th><th>날짜</th><th>CURRENCY</th><th>AMOUNT</th><th>TRANSACTION_TYPE</th><th>STATE</th><th>UUID</th></tr>
<?php if (count($dep) > 0): foreach ($dep as $d):
$link = $write_url_base
. '&type='.urlencode('입금')
. '&date='.urlencode($d['created_at'])
. '&target='.count($dep) +1 - $target_num++;
?>
<tr class="has-link" onclick="location.href='<?php echo $link; ?>'">
<td align="center"><?php echo count($dep) +1 - $page_num++; ?></td>
<td><?php echo $d['created_at'] ?? ''; ?></td>
<td><?php echo $d['currency'] ?? ''; ?></td>
<td><?php echo $d['amount'] ?? ''; ?></td>
<td><?php echo $d['transaction_type'] ?? ''; ?></td>
<td><?php echo $d['state'] ?? ''; ?></td>
<td style="font-size:10px;"><?php echo $d['uuid'] ?? ''; ?></td>
</tr>
<?php endforeach; else: ?>
<tr><td colspan="7" class="no-data">업데이트 없음</td></tr>
<?php endif; ?>
</table>
<h2 class="api-h2">출금</h2>
<table class="api-table">
<tr><th>번호</th><th>날짜</th><th>CURRENCY</th><th>AMOUNT</th><th>TRANSACTION_TYPE</th><th>STATE</th><th>UUID</th></tr>
<?php if (count($wit) > 0): foreach ($wit as $d):
$link = $write_url_base
. '&type='.urlencode('출금')
. '&date='.urlencode($d['created_at'])
. '&target='.count($dep) +1 - $target_num++;
?>
<tr class="has-link" onclick="location.href='<?php echo $link; ?>'">
<td align="center"><?php echo $page_num++; ?></td>
<td><?php echo $d['created_at'] ?? ''; ?></td>
<td><?php echo $d['currency'] ?? ''; ?></td>
<td><?php echo $d['amount'] ?? ''; ?></td>
<td><?php echo $d['transaction_type'] ?? ''; ?></td>
<td><?php echo $d['state'] ?? ''; ?></td>
<td style="font-size:10px;"><?php echo $d['uuid'] ?? ''; ?></td>
</tr>
<?php endforeach; else: ?>
<tr><td colspan="7" class="no-data">업데이트 없음</td></tr>
<?php endif; ?>
</table>