티스토리 뷰
카페24 쇼핑몰 솔루션에서 이름이나 휴대폰 번호를 통해 고객 ID를 가져오는 로직을 추가하려면, 카페24 API에서 고객 정보를 조회할 수 있는 기능을 활용해야 합니다. 다음은 구현 가이드입니다.
1. 고객 정보 조회 API 확인
카페24 API 문서에 따르면 고객 정보를 검색하려면 GET /v2/admin/customers 엔드포인트를 사용합니다. 이 API는 이름, 이메일, 휴대폰 번호 등의 파라미터를 통해 고객 목록을 검색할 수 있습니다.
- API 엔드포인트:
GET /v2/admin/customers - 주요 쿼리 파라미터:
- name: 고객 이름
- cellphone: 휴대폰 번호
- 기타: 이메일 등
2. 서비스 코드 작성
services/cafe24Service.js에 고객 정보를 조회하는 함수 추가:
const axios = require('axios');
const { cafe24 } = require('../config/config');
// 이름 또는 휴대폰 번호로 고객 조회
async function getCustomerByNameOrPhone(name, phone, token) {
const url = `${cafe24.baseUrl}/v2/admin/customers`;
const headers = { Authorization: `Bearer ${token}` };
// 파라미터 구성
const params = {};
if (name) params.name = name;
if (phone) params.cellphone = phone;
try {
const response = await axios.get(url, { headers, params });
return response.data.customers; // 고객 목록 반환
} catch (error) {
throw new Error(`Failed to fetch customer: ${error.message}`);
}
}
module.exports = { getCustomerByNameOrPhone };
3. 컨트롤러 추가
controllers/pointsController.js에 고객 검색 로직 추가:
const { getCustomerByNameOrPhone } = require('../services/cafe24Service');
async function findCustomer(req, res) {
const { name, phone } = req.query; // 요청에서 이름과 휴대폰 번호 가져오기
try {
const customers = await getCustomerByNameOrPhone(name, phone, req.accessToken);
if (customers.length === 0) {
return res.status(404).json({ message: 'No customer found' });
}
res.status(200).json(customers);
} catch (error) {
res.status(500).json({ error: `Failed to find customer: ${error.message}` });
}
}
module.exports = { findCustomer };
4. 라우트 추가
routes/points.js에 고객 조회 라우트 추가:
const express = require('express');
const { getAccessToken } = require('../middleware/auth');
const { findCustomer } = require('../controllers/pointsController');
const router = express.Router();
// 이름 또는 휴대폰 번호로 고객 조회
router.get('/search', getAccessToken, findCustomer);
module.exports = router;
5. 앱에 통합
app.js에 새 라우트 통합:
const express = require('express');
const pointsRoutes = require('./routes/points');
const app = express();
app.use(express.json());
app.use('/points', pointsRoutes);
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
6. 요청 테스트
- 이름으로 검색:
GET /points/search?name=홍길동 - 휴대폰 번호로 검색:
GET /points/search?phone=01012345678 - 결과 예시:
[
{
"customer_id": "12345",
"name": "홍길동",
"cellphone": "01012345678",
"email": "hong@example.com"
}
]
7. 주의사항
- 카페24 API 사용 시, API rate limit를 확인하고 이에 맞게 요청을 최적화하세요.
- 고객 정보는 민감한 데이터이므로 API 호출 및 응답 처리를 보안에 유의하여 구현하세요.
- phone 필드의 형식을 카페24와 동일하게 유지하세요 (예: +821012345678 형태).
위 방법을 통해 이름이나 휴대폰 번호로 고객 ID를 가져올 수 있습니다!
'IT 이야기 > Node.js' 카테고리의 다른 글
[express.js] 카페24 쇼핑몰의 적립급을 조회/지급/차감 - 1편 (0) | 2025.01.21 |
---|---|
Express.js와 EJS를 사용하여 다국어 지원 관리자 페이지를 작성하려면 (0) | 2025.01.14 |
express.js와 mariaDB 연결 문제 (0) | 2025.01.10 |
express.js 로그인 시스템 구현 시 보안 (0) | 2025.01.05 |
[SERVER] ubuntu, nginx, node.js mariaDB로 서버 세팅하기 (1) | 2024.09.26 |
[express.js] express.js와 mariaDB를 이용하는 기본 설정 (0) | 2024.09.24 |
Hostinger 사용기1 - 설치 (0) | 2024.06.13 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
- W3Schools Online Web Tutorials
- 구차니의 잡동사니 모음
- [IT]블로거팁닷컴
- 비앤아이님의 블로그
- Blog Suspect
- 즐거운하루 blog
- zinicap의 검색엔진 마케팅(SEM)
- 머니야머니야님의 블로그
- [Friend] AtinStory
- [기타배우기]해브원 박스
- [웹표준] SINDB.com
- 해커 C 이야기
- [애드센스] 길라잡이
- 정순봉의 IT SCHOOL
- 씨디맨의 컴퓨터이야기
- 2proo Life Story
- 못된준코의 세상리뷰
- [IT강좌] 정보문화사
- IN 대전
- 에우르트는 나쁜남자 -_-
- 씬의 싱크탱크
- 엔돌슨의 IT이야기
- 진이늘이
- 'Cooltime'의 블로그
- 후이의 Tistory
- Soulstorage
- 앤드&엔드의 블로그
- June Blog
- 노지의 소박한 이야기
- gbWorld
- 인터넷 속 나의 생각
- HarshNix
- ART of WEB
- 녹두장군 - 상상을 현실로
TAG
- C
- 안드로이드 어플 추천
- MBTI 검사
- 프로그래밍 문제
- 강의
- MBTI 테스트
- MBTI 강좌
- php
- HTML
- 리뷰
- 모토로이
- C언어 소스
- 프로그래밍
- 예제 소스
- 강좌
- 소스코드
- JavaScript
- 안드로이드 어플
- It
- C언어
- C언어 문제
- MBTI
- MBTI 자료
- 성공
- 안드로이드
- 인터넷
- 인터넷 익스플로러
- 소스
- 효과음
- 스마트폰
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함