동행복권에서 지원해주는 로또 번호 가져와 보기, 로또 API , 동행복권 api
페이지 정보
작성자본문
기존 동행복권 api 가 막히는 바람에 다시 코드 테스트 했습니다.
동행복권에서는 로또 번호에 대한 회차번호를 지원해 준다.
주소값에 회차만 입력하면 바로 가져올 수 있는데
아래 주소에서 확인해주세요.
https://ety.kr/lotto.php
https://lotto.ety.kr/ (무료 로또 데이터 분석기 + 8개 자동게임)
<?php
/**
* 최신 로또 회차 계산 함수
*/
function getLatestDrwNo() {
$firstDate = strtotime('2002-12-07'); // 1회차 추첨일
$today = time();
$weeks = floor(($today - $firstDate) / (60 * 60 * 24 * 7));
return $weeks + 1;
}
/**
* 네이버 파싱 함수
*/
function getLottoFromNaver($drwNo) {
if (!$drwNo) $drwNo = getLatestDrwNo();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = ['User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$html = curl_exec($ch);
curl_close($ch);
if (!$html) return ["status" => "error", "message" => "네이버 접속 실패"];
$data = ['drwNo' => $drwNo];
preg_match_all('/<span class="ball[^>]*">(\d+)<\/span>/', $html, $matches);
if (isset($matches[1]) && count($matches[1]) >= 7) {
for($i=1; $i<=6; $i++) { $data["drwtNo$i"] = $matches[1][$i-1]; }
$data['bnusNo'] = $matches[1][6];
$data['status'] = "success";
} else {
$data['status'] = "error";
$data['message'] = "파싱 실패";
}
return $data;
}
function getBallColorClass($num) {
if ($num <= 10) return 'ball-yellow';
if ($num <= 20) return 'ball-blue';
if ($num <= 30) return 'ball-red';
if ($num <= 40) return 'ball-gray';
return 'ball-green';
}
// GET 파라미터로 회차 받기, 없으면 최신회차
$selectedNo = isset($_GET['drwNo']) ? (int)$_GET['drwNo'] : getLatestDrwNo();
$lotto = getLottoFromNaver($selectedNo);
$latestNo = getLatestDrwNo();
?>
<style>
.lotto-wrapper { font-family: sans-serif; text-align: center; padding: 20px; }
/* 검색 영역 스타일 변경 */
.search-area { margin-bottom: 20px; }
.input-box { padding: 10px; border-radius: 5px; border: 1px solid #ccc; font-size: 16px; width: 150px; text-align: center; }
.search-btn { padding: 10px 20px; border-radius: 5px; border: none; background-color: #3498db; color: white; font-size: 16px; cursor: pointer; font-weight: bold; transition: background 0.2s; }
.search-btn:hover { background-color: #2980b9; }
.lotto-card { display: inline-block; padding: 25px; background: #fff; border: 1px solid #ddd; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.ball-list { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 15px; }
.ball { width: 38px; height: 38px; line-height: 38px; border-radius: 50%; color: #fff; font-weight: bold; font-size: 16px; text-shadow: 0 1px 1px rgba(0,0,0,0.3); box-shadow: inset -2px -2px 4px rgba(0,0,0,0.2); }
.ball-yellow { background: #fbc400; }
.ball-blue { background: #69c8f2; }
.ball-red { background: #ff7272; }
.ball-gray { background: #aaa; }
.ball-green { background: #b0d840; }
.plus-sign { font-size: 20px; font-weight: bold; color: #ccc; }
.error-msg { color: #e74c3c; font-weight: bold; }
</style>
<div class="lotto-wrapper">
<div class="search-area">
<form method="GET" id="lottoForm">
<input type="number" name="drwNo" class="input-box" value="<?= $selectedNo ?>" placeholder="회차 입력" min="1" max="<?= $latestNo ?>">
<button type="submit" class="search-btn">검색</button>
</form>
</div>
<div class="lotto-card">
<?php if ($lotto['status'] === 'success'): ?>
<h3 style="margin:0">제 <span style="color:#e74c3c"><?= $lotto['drwNo'] ?></span>회 당첨결과</h3>
<div class="ball-list">
<?php for($i=1; $i<=6; $i++): ?>
<div class="ball <?= getBallColorClass($lotto["drwtNo$i"]) ?>"><?= $lotto["drwtNo$i"] ?></div>
<?php endfor; ?>
<div class="plus-sign">+</div>
<div class="ball <?= getBallColorClass($lotto['bnusNo']) ?>"><?= $lotto['bnusNo'] ?></div>
</div>
<?php else: ?>
<p class="error-msg">데이터 파싱 실패 (없는 회차이거나 네이버 구조 변경 가능성)</p>
<?php endif; ?>
</div>
</div>
아래는 제가 만들어 본 게임입니다.
로또번호 마킹도 할수 있게 만들었습니다.
위에 링크 주소가 있습니다. https://lotto.ety.kr![]()
아래 코드는 막혀 있습니다.
주소창에
https://www.dhlottery.co.kr/common.do?method=getLottoNumber&drwNo=200
맨뒤에 200 이라고 입력하게 되면 200회의 로또 번호를 가지고 온다.
코드로 만들어서 웹사이트에서 서비스 하려는 경우에는 아래 처럼 가져다 쓰면 된다.
댓글목록
등록된 댓글이 없습니다.

