| Server IP : 158.247.231.215 / Your IP : 216.73.216.32 Web Server : Apache/2.4.41 (Ubuntu) System : Linux CTMS 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /mnt/blockstorage/ctms/api/custom-api/ |
Upload File : |
# Custom API Documentation
이 폴더에는 WordPress에서 독립적으로 작동하는 사용자 정의 API들이 포함되어 있습니다.
## 📁 파일 구조
### 사용자 API (User APIs)
- `auth-helper.php` - JWT 인증 헬퍼 함수
- `user-course-stats.php` - 사용자 코스 통계 조회
- `user-register.php` - 사용자 등록
- `user-me.php` - 현재 사용자 정보 조회
- `user-password-change.php` - 비밀번호 변경
- `user-membership.php` - 멤버십 정보 조회
- `user-invoices.php` - 인보이스 목록 조회
- `user-social-profiles-get.php` - 소셜 프로필 조회
- `user-social-profiles-update.php` - 소셜 프로필 업데이트
- `user-quiz-attempts.php` - 퀴즈 시도 내역 조회
### VR 콘텐츠 API (VR Content APIs)
- `vr-content-create.php` - VR 콘텐츠 생성
- `vr-content-list.php` - VR 콘텐츠 목록
- `vr-content-detail.php` - VR 콘텐츠 상세
- `vr-content-update.php` - VR 콘텐츠 수정
- `vr-content-delete.php` - VR 콘텐츠 삭제
- `vr-version-create.php` - VR 버전 생성
- `vr-version-list.php` - VR 버전 목록
- `vr-version-update.php` - VR 버전 수정
- `vr-version-delete.php` - VR 버전 삭제
- `vr-download-request.php` - VR 다운로드 요청
- `vr-download-status.php` - VR 다운로드 상태
- `vr-download-execute.php` - VR 다운로드 실행
- `vr-download-requests-admin.php` - VR 다운로드 요청 관리
- `vr-download-approve.php` - VR 다운로드 승인
- `vr-download-reject.php` - VR 다운로드 거부
### 기존 파일
- `custom-course-stats-api.php` - 원본 WordPress 플러그인 (백업용)
---
## 🔐 인증 방식
### JWT 인증 필요 없음
- `user-course-stats.php`
- `user-register.php`
### JWT 인증 필요
나머지 모든 사용자 API는 JWT 토큰이 필요합니다.
**인증 헤더 예시:**
```
Authorization: Bearer YOUR_JWT_TOKEN_HERE
```
---
## 📖 API 엔드포인트
### 1. 사용자 코스 통계 조회
**Endpoint:** `GET /api/custom-api/user-course-stats.php?user_id={id}`
**파라미터:**
- `user_id` (required) - 사용자 ID
**응답 예시:**
```json
{
"success": true,
"user_id": 1,
"user_name": "John Doe",
"statistics": {
"enrolled_courses": 10,
"active_courses": 5,
"completed_courses": 3
}
}
```
---
### 2. 사용자 등록
**Endpoint:** `POST /api/custom-api/user-register.php`
**요청 본문:**
```json
{
"username": "johndoe",
"email": "john@example.com",
"password": "password123"
}
```
**응답 예시:**
```json
{
"success": true,
"message": "User created and logged in successfully",
"user_id": 123,
"username": "johndoe",
"email": "john@example.com",
"token": "eyJ0eXAiOiJKV1QiLCJhbGc..."
}
```
---
### 3. 현재 사용자 정보 조회
**Endpoint:** `GET /api/custom-api/user-me.php`
**인증:** JWT 토큰 필요
**응답 예시:**
```json
{
"success": true,
"id": 1,
"username": "johndoe",
"email": "john@example.com",
"name": "John Doe",
"first_name": "John",
"last_name": "Doe",
"nickname": "johndoe",
"description": "",
"avatar_url": "https://...",
"roles": ["subscriber"]
}
```
---
### 4. 비밀번호 변경
**Endpoint:** `POST /api/custom-api/user-password-change.php`
**인증:** JWT 토큰 필요
**요청 본문:**
```json
{
"current_password": "oldpass123",
"new_password": "newpass123",
"confirm_password": "newpass123"
}
```
**응답 예시:**
```json
{
"success": true,
"message": "Password changed successfully"
}
```
---
### 5. 멤버십 정보 조회
**Endpoint:** `GET /api/custom-api/user-membership.php`
**인증:** JWT 토큰 필요
**응답 예시:**
```json
{
"success": true,
"current_membership": {
"id": 1,
"name": "Premium",
"description": "Premium membership",
"start_date": "2024-01-01 00:00:00",
"end_date": null,
"initial_payment": 100.00,
"billing_amount": 100.00,
"cycle_number": 1,
"cycle_period": "Month",
"billing_limit": 0,
"trial_amount": 0.00,
"trial_limit": 0,
"status": "active"
},
"membership_history": [...],
"currency": "USD"
}
```
---
### 6. 인보이스 목록 조회
**Endpoint:** `GET /api/custom-api/user-invoices.php`
**인증:** JWT 토큰 필요
**응답 예시:**
```json
{
"success": true,
"invoices": [
{
"id": 1,
"code": "INV-001",
"membership_id": 1,
"membership_name": "Premium",
"amount": 100.00,
"subtotal": 100.00,
"tax": 0.00,
"discount": 0.00,
"currency": "USD",
"payment_type": "Credit Card",
"card_type": "Visa",
"status": "success",
"gateway": "stripe",
"date": "2024-01-01 00:00:00"
}
],
"total_count": 1
}
```
---
### 7. 소셜 프로필 조회
**Endpoint:** `GET /api/custom-api/user-social-profiles-get.php`
**인증:** JWT 토큰 필요
**응답 예시:**
```json
{
"success": true,
"social_profiles": {
"facebook": "https://facebook.com/johndoe",
"twitter": "https://twitter.com/johndoe",
"linkedin": "https://linkedin.com/in/johndoe",
"website": "https://johndoe.com",
"github": "https://github.com/johndoe"
}
}
```
---
### 8. 소셜 프로필 업데이트
**Endpoint:** `POST /api/custom-api/user-social-profiles-update.php`
**인증:** JWT 토큰 필요
**요청 본문:**
```json
{
"facebook": "https://facebook.com/johndoe",
"twitter": "https://twitter.com/johndoe",
"linkedin": "https://linkedin.com/in/johndoe",
"website": "https://johndoe.com",
"github": "https://github.com/johndoe"
}
```
**응답 예시:**
```json
{
"success": true,
"message": "Social profiles updated successfully",
"social_profiles": {...}
}
```
---
### 9. 퀴즈 시도 내역 조회
**Endpoint:** `GET /api/custom-api/user-quiz-attempts.php`
**인증:** JWT 토큰 필요
**응답 예시:**
```json
{
"success": true,
"quiz_attempts": [
{
"attempt_id": 1,
"name": "John Doe",
"class": "Math 101",
"quiz_title": "Chapter 1 Quiz",
"score": "85",
"date": "2024-01-01 10:00:00",
"percentage": 85.00,
"correct_answers": 17,
"total_questions": 20,
"details": [...]
}
],
"total_count": 1
}
```
---
## 🚀 사용 예시
### cURL로 테스트
```bash
# 1. 사용자 등록
curl -X POST https://training.contentsda.kr/api/custom-api/user-register.php \
-H "Content-Type: application/json" \
-d '{"username":"testuser","email":"test@example.com","password":"test123"}'
# 2. 코스 통계 조회
curl "https://training.contentsda.kr/api/custom-api/user-course-stats.php?user_id=1"
# 3. 내 정보 조회 (JWT 토큰 필요)
curl https://training.contentsda.kr/api/custom-api/user-me.php \
-H "Authorization: Bearer YOUR_TOKEN_HERE"
```
---
## 📝 주의사항
1. **기존 파일 보존**
- `custom-course-stats-api.php`는 원본 WordPress 플러그인으로 백업용으로 보관됩니다.
- 삭제하지 마세요.
2. **URL 경로 변경**
- 기존: `/api/vr-content-list.php`
- 변경: `/api/custom-api/vr-content-list.php`
- 외부 앱/프론트엔드에서 URL을 업데이트해야 합니다.
3. **WordPress 의존성**
- 사용자 API들은 여전히 WordPress 데이터베이스와 함수를 사용합니다.
- WordPress가 설치되어 있어야 작동합니다.
- 향후 WordPress를 완전히 제거하려면 추가 마이그레이션이 필요합니다.
4. **VR API 경로**
- VR API 파일들은 `../database.php`를 참조합니다.
- `database.php`는 `/api/` 폴더에 있어야 합니다.
---
## 🔄 마이그레이션 가이드
기존 WordPress REST API에서 새로운 독립 API로 마이그레이션:
| 기존 WordPress REST API | 새로운 독립 API |
|------------------------|----------------|
| `/wp-json/custom/v1/user/{id}/course-stats` | `/api/custom-api/user-course-stats.php?user_id={id}` |
| `/wp-json/custom/v1/register` | `/api/custom-api/user-register.php` |
| `/wp-json/custom/v1/me` | `/api/custom-api/user-me.php` |
| `/wp-json/custom/v1/password/change` | `/api/custom-api/user-password-change.php` |
| `/wp-json/custom/v1/me/membership` | `/api/custom-api/user-membership.php` |
| `/wp-json/custom/v1/me/invoices` | `/api/custom-api/user-invoices.php` |
| `/wp-json/custom/v1/me/social-profiles` (GET) | `/api/custom-api/user-social-profiles-get.php` |
| `/wp-json/custom/v1/me/social-profiles` (POST) | `/api/custom-api/user-social-profiles-update.php` |
| `/wp-json/custom/v1/me/quiz-attempts` | `/api/custom-api/user-quiz-attempts.php` |
---
## 🛠️ 유지보수
파일을 수정할 때:
1. `auth-helper.php`의 JWT 검증 로직은 모든 인증 API에서 공통으로 사용됩니다.
2. CORS 헤더는 각 파일에 개별적으로 설정되어 있습니다.
3. WordPress 함수 의존성을 제거하려면 각 API 파일을 개별적으로 수정해야 합니다.