로그인한 회원의 이메일 값을 불러오고 싶습니다.
CMS/프레임워크 | Rhymix 2.1 |
---|---|
개발 언어 | PHP 7.3 |
스티비 api 를 활용해 특정페이지에 접속하면 회원에게 메일을 보내려고 합니다.
그래서 그 페이지에 아래와 같은 코드를 넣었고 "subscriber" 에 입력한 이메일로 메일 발송하는 것까지는 성공했는데
로그인한 회원 정보의 이메일 값으로 요청하는 법을 모르겠습니다.
아래 코드는 chatGPT 한테 내용 설명하고 코드 만들어 달라니까 만들어줬어요 ㄷㄷ
<script>
window.onload = function() {
var data = {
"subscriber": "로그인한 회원의 이메일"
};
console.log(data);
fetch('https://stibee.com/api/v1.0/auto/룰룰룰', {
method: 'POST',
headers: {
'AccessToken': '룰룰룰',
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then(response => {
if (response.headers.get('content-type').includes('application/json')) {
return response.json(); // 응답이 JSON이면 JSON으로 파싱
} else {
return response.text(); // JSON이 아니면 텍스트로 처리
}
})
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
};
</script>
window.onload = function() {
var data = {
"subscriber": "로그인한 회원의 이메일"
};
console.log(data);
fetch('https://stibee.com/api/v1.0/auto/룰룰룰', {
method: 'POST',
headers: {
'AccessToken': '룰룰룰',
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then(response => {
if (response.headers.get('content-type').includes('application/json')) {
return response.json(); // 응답이 JSON이면 JSON으로 파싱
} else {
return response.text(); // JSON이 아니면 텍스트로 처리
}
})
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
};
</script>
스코스코
Lv. 5
댓글 8
정답은 바로바로 "subscriber": "{$logged_info->email_address}" 입니다~
덕분에 오늘 하루 웃으면서 시작합니다 :D
php에서 api쓰게 만드셔야될듯
$email_address = 로그인한회원 이메일
<?php
$email_address = $logged_info->email_address; // 이 부분을 실제 이메일 주소 변수로 대체하세요.
$data = [
"subscriber" => $email_address
];
$url = 'https://stibee.com/api/v1.0/auto/룰루룰'
$accessToken = '룰루룰';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'AccessToken: ' . $accessToken,
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode == 200) {
// 성공적인 응답 처리
$responseData = json_decode($response, true);
// 응답 데이터 처리
} else {
// 오류 처리
echo "Error: " . $response;
}
curl_close($ch);
?>
ChatGPT 한테 JS 내용 PHP로 바꿔달라니까 잘해줬는데 $email_address = $logged_info->email_address; 이 부분을 어떻게 고쳐줘야할지 모르겠습니다!!
$logged_info = Context::get('logged_info');
$email_address = $logged_info->email_address;
이렇게 고치니까 되네요