# -*- coding: utf-8 -*- """백제약품 주문 원장 API 분석""" import json import requests from datetime import datetime, timedelta import calendar # 저장된 토큰 로드 TOKEN_FILE = r'c:\Users\청춘약국\source\pharmacy-wholesale-api\.baekje_token.json' with open(TOKEN_FILE, 'r', encoding='utf-8') as f: token_data = json.load(f) token = token_data['token'] cust_cd = token_data['cust_cd'] print(f"Token expires: {datetime.fromtimestamp(token_data['expires'])}") print(f"Customer code: {cust_cd}") # API 세션 설정 session = requests.Session() session.headers.update({ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7', 'Origin': 'https://ibjp.co.kr', 'Referer': 'https://ibjp.co.kr/', 'Authorization': f'Bearer {token}' }) API_URL = "https://www.ibjp.co.kr" # 1. 주문 원장 API 시도 - 다양한 엔드포인트 endpoints = [ '/ordLedger/listSearch', '/ordLedger/list', '/ord/ledgerList', '/ord/ledgerSearch', '/cust/ordLedger', '/custOrd/ledgerList', '/ordHist/listSearch', '/ordHist/list', ] # 날짜 설정 (이번 달) today = datetime.now() year = today.year month = today.month _, last_day = calendar.monthrange(year, month) from_date = f"{year}{month:02d}01" to_date = f"{year}{month:02d}{last_day:02d}" print(f"\n조회 기간: {from_date} ~ {to_date}") print("\n=== API 엔드포인트 탐색 ===\n") params = { 'custCd': cust_cd, 'startDt': from_date, 'endDt': to_date, 'stDate': from_date, 'edDate': to_date, 'year': str(year), 'month': f"{month:02d}", } for endpoint in endpoints: try: # GET 시도 resp = session.get(f"{API_URL}{endpoint}", params=params, timeout=10) print(f"GET {endpoint}: {resp.status_code}") if resp.status_code == 200: try: data = resp.json() print(f" -> JSON Response (first 500 chars): {str(data)[:500]}") except: print(f" -> Text (first 200 chars): {resp.text[:200]}") except Exception as e: print(f"GET {endpoint}: Error - {e}") try: # POST 시도 resp = session.post(f"{API_URL}{endpoint}", json=params, timeout=10) print(f"POST {endpoint}: {resp.status_code}") if resp.status_code == 200: try: data = resp.json() print(f" -> JSON Response (first 500 chars): {str(data)[:500]}") except: print(f" -> Text (first 200 chars): {resp.text[:200]}") except Exception as e: print(f"POST {endpoint}: Error - {e}") # 2. 이미 알려진 API로 데이터 확인 print("\n=== 알려진 API 테스트 ===\n") # 월간 잔고 조회 (이미 있는 함수에서 사용) resp = session.get(f"{API_URL}/custMonth/listSearch", params={'custCd': cust_cd, 'year': str(year), 'endDt': to_date}, timeout=10) print(f"custMonth/listSearch: {resp.status_code}") if resp.status_code == 200: data = resp.json() print(f" -> {json.dumps(data, ensure_ascii=False, indent=2)[:1500]}")