카카오 로그인을 이용한 가입 테스트
This commit is contained in:
Vendored
+4
File diff suppressed because one or more lines are too long
@@ -107,3 +107,28 @@ function delExpiredInDir($dir, $t) {
|
||||
}
|
||||
|
||||
|
||||
function returnJson($value, $noCache = true, $pretty = false, $die = true){
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if($noCache){
|
||||
header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', FALSE);
|
||||
header('Pragma: no-cache');
|
||||
}
|
||||
|
||||
if($pretty){
|
||||
$flag = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;
|
||||
}
|
||||
else{
|
||||
$flag = JSON_UNESCAPED_UNICODE;
|
||||
}
|
||||
echo json_encode($value, $flag);
|
||||
if($die){
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
function hashPassword($salt, $password){
|
||||
return hash('sha512', $salt.$password.$salt);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
if(!defined('ROOT')){
|
||||
define('ROOT', '..');
|
||||
}
|
||||
require_once(ROOT.'/f_config/config.php');
|
||||
require_once(ROOT.'/f_config/app.php');
|
||||
require_once(ROOT.'/f_func/func.php');
|
||||
|
||||
CustomHeader();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
class KakaoKey{
|
||||
const REST_KEY = '_REST_API_KEY_';
|
||||
const ADMIN_KEY = '_ADMIN_KEY_';
|
||||
const REDIRECT_URI = '_REDIRECT_URI_';
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require('conf.php');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>카카오 로그인하기</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<a href="https://kauth.kakao.com/oauth/authorize?client_id=<?=KakaoKey::REST_KEY?>&redirect_uri=<?=KakaoKey::REDIRECT_URI?>&response_type=code"><img src="kakao_btn.png"></a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
require_once('_common.php');
|
||||
require('lib.join.php');
|
||||
|
||||
|
||||
use utilphp\util as util;
|
||||
|
||||
session_start();
|
||||
|
||||
$access_token = util::array_get($_SESSION['access_token']);
|
||||
if(!$access_token){
|
||||
returnJson('로그인 토큰 에러. 다시 로그인을 수행해주세요.');
|
||||
}
|
||||
|
||||
|
||||
$value = util::array_get($_POST['value']);
|
||||
switch(util::array_get($_POST['type'])){
|
||||
case 'nickname':
|
||||
returnJson(checkNicknameDup($value));
|
||||
case 'username':
|
||||
returnJson(checkUsernameDup($value));
|
||||
}
|
||||
|
||||
returnJson(false);
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
require_once('_common.php');
|
||||
require('lib.join.php');
|
||||
require(ROOT.'/f_func/class._Time.php');
|
||||
require('kakao.php');
|
||||
|
||||
use utilphp\util as util;
|
||||
|
||||
session_start();
|
||||
|
||||
$canJoin = getRootDB()->queryFirstField('SELECT REG FROM `SYSTEM` WHERE `NO` = 1');
|
||||
if($canJoin != 'Y'){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'현재는 가입이 금지되어있습니다!'
|
||||
]);
|
||||
}
|
||||
|
||||
$nowDate = _Time::DatetimeNow();
|
||||
|
||||
$access_token = util::array_get($_SESSION['access_token']);
|
||||
$expires = util::array_get($_SESSION['expires']);
|
||||
$refresh_token = util::array_get($_SESSION['refresh_token']);
|
||||
$refresh_token_expires = util::array_get($_SESSION['refresh_token_expires']);
|
||||
if(!$access_token){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'로그인 토큰 에러. 다시 카카오로그인을 수행해주세요.'
|
||||
]);
|
||||
}
|
||||
if($refresh_token_expires < $nowDate){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'로그인 토큰 만료.'.$refresh_token_expires.' 다시 카카오로그인을 수행해주세요.'
|
||||
]);
|
||||
}
|
||||
$secret_agree =util::array_get($_POST['secret_agree']);
|
||||
$username = util::array_get($_POST['username']);
|
||||
$password = util::array_get($_POST['password']);
|
||||
$nickname = util::array_get($_POST['nickname']);
|
||||
|
||||
if(!$username || !$password || !$nickname){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'입력값이 설정되지 않았습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
if(strlen($password)!=128){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'올바르지 않은 비밀번호 해시 포맷입니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!$secret_agree){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'약관에 동의해야 가입하실 수 있습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
$usernameChk = checkUsernameDup($username);
|
||||
if($usernameChk !== true){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>$usernameChk
|
||||
]);
|
||||
}
|
||||
|
||||
$nicknameChk = checkNicknameDup($nickname);
|
||||
if($nicknameChk !== true){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>$nicknameChk
|
||||
]);
|
||||
}
|
||||
|
||||
$userSalt = bin2hex(random_bytes(8));
|
||||
$finalPassword = hashPassword($userSalt, $password);
|
||||
|
||||
//클라이언트 단에서 보내준 데이터 준비가 끝났다.
|
||||
$restAPI = new Kakao_REST_API_Helper($access_token);
|
||||
|
||||
if($expires < $nowDate){
|
||||
$result = $restAPI->refresh_access_token($refresh_token);
|
||||
if(!isset($refresh_token)){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'카카오 로그인 과정 중 추가 갱신 절차를 실패했습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
$access_token = $result['access_token'];
|
||||
$expires = _Time::DatetimeFromNowSecond($nowDate, $result['expires_in']);
|
||||
if(isset($result['refresh_token'])){
|
||||
$refresh_token = util::array_get($result['refresh_token']);
|
||||
$refresh_token_expires = _Time::DatetimeFromNowSecond($nowDate, $result['refresh_token_expires_in']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$signupResult = $restAPI->signup();
|
||||
$kakaoID = util::array_get($signupResult['id']);
|
||||
|
||||
if(!$kakaoID && util::array_get($signupResult['msg'])!='already registered'){
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'카카오 로그인 과정 중 앱 연결 절차를 실패했습니다'.json_encode($signupResult)
|
||||
]);
|
||||
}
|
||||
|
||||
$me = $restAPI->meWithEmail();
|
||||
if(!util::array_get($me['kaccount_email_verified'],false)){
|
||||
$restAPI->unlink();
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>'카카오 계정 이메일이 아직 인증되지 않았습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
$email = $me['kaccount_email'];
|
||||
$emailChk = checkEmailDup($email);
|
||||
if($emailChk !== true){
|
||||
$restAPI->unlink();
|
||||
returnJson([
|
||||
'result'=>false,
|
||||
'reason'=>$emailChk
|
||||
]);
|
||||
}
|
||||
|
||||
//모든 절차 종료. 등록.
|
||||
|
||||
|
||||
getRootDB()->insert('auth_kakao',[
|
||||
'id'=>$kakaoID,
|
||||
'access_token'=>$access_token,
|
||||
'refresh_token'=>$refresh_token,
|
||||
'expires'=>$expires,
|
||||
'refresh_token_expires'=>$refresh_token_expires,
|
||||
'datetime'=>$nowDate,
|
||||
'email'=>$email
|
||||
]);
|
||||
|
||||
getRootDB()->insert('member',[
|
||||
'oauth_id' => $kakaoID,
|
||||
'oauth_type' => 'KAKAO',
|
||||
'id' => $username,
|
||||
'email' => $email,
|
||||
'pw' => $finalPassword,
|
||||
'salt' => $userSalt,
|
||||
'name'=>$nickname,
|
||||
'reg_date'=>$nowDate
|
||||
]);
|
||||
|
||||
returnJson([
|
||||
'result'=>true,
|
||||
'reason'=>'success'
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
/* Created by Filipe Pina
|
||||
* Specific styles of signin, register, component
|
||||
*/
|
||||
/*
|
||||
* General styles
|
||||
*/
|
||||
|
||||
body, html{
|
||||
height: 100%;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.main{
|
||||
margin-top: 70px;
|
||||
}
|
||||
|
||||
h1.title {
|
||||
font-size: 50px;
|
||||
font-family: 'Passion One', cursive;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
hr{
|
||||
width: 10%;
|
||||
/*color: #fff;*/
|
||||
}
|
||||
|
||||
.form-group{
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
label{
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
input,
|
||||
input::-webkit-input-placeholder {
|
||||
font-size: 11px;
|
||||
padding-top: 3px;
|
||||
}
|
||||
|
||||
.main-login{
|
||||
/*background-color: #fff;*/
|
||||
/* shadows and rounded borders */
|
||||
-moz-border-radius: 2px;
|
||||
-webkit-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
-moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
|
||||
-webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
|
||||
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
|
||||
|
||||
}
|
||||
|
||||
.main-center{
|
||||
margin-top: 30px;
|
||||
margin: 0 auto;
|
||||
max-width: 330px;
|
||||
padding: 40px 40px;
|
||||
|
||||
}
|
||||
|
||||
.login-button{
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.login-register{
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
.terms{
|
||||
max-height: 200px; overflow: auto;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
$(document).ready( function () {
|
||||
$( "#main_form" ).validate( {
|
||||
rules: {
|
||||
username: {
|
||||
required: true,
|
||||
minlength: 4,
|
||||
maxlength: 64,
|
||||
remote: {
|
||||
url: "j_check_dup.php",
|
||||
type: "post",
|
||||
data: {
|
||||
type:'username',
|
||||
'value':function(){
|
||||
return $('#username').val();
|
||||
}
|
||||
},
|
||||
dataType: 'json'
|
||||
}
|
||||
},
|
||||
password: {
|
||||
required: true,
|
||||
minlength: 6
|
||||
},
|
||||
confirm_password: {
|
||||
required: true,
|
||||
minlength: 6,
|
||||
equalTo: "#password"
|
||||
},
|
||||
nickname:{
|
||||
required: true,
|
||||
maxlength: 6,
|
||||
remote: {
|
||||
url: "j_check_dup.php",
|
||||
type: "post",
|
||||
data: {
|
||||
type:'nickname',
|
||||
'value':function(){
|
||||
return $('#nickname').val();
|
||||
}
|
||||
},
|
||||
dataType: 'json'
|
||||
}
|
||||
},
|
||||
secret_agree: "required"
|
||||
},
|
||||
messages: {
|
||||
username: {
|
||||
required: "유저명을 입력해주세요",
|
||||
minlength: "{0}글자 이상 입력하셔야 합니다",
|
||||
maxlength: '{0}자를 넘을 수 없습니다'
|
||||
},
|
||||
password: {
|
||||
required: "비밀번호를 입력해주세요",
|
||||
minlength: "비밀번호는 적어도 {0}글자 이상이어야 합니다"
|
||||
},
|
||||
confirm_password: {
|
||||
required: "비밀번호를 입력해주세요",
|
||||
minlength: "비밀번호는 적어도 {0}글자 이상이어야 합니다",
|
||||
equalTo: "비밀번호가 일치하지 않습니다"
|
||||
},
|
||||
nickname: {
|
||||
required: "닉네임을 입력해주세요",
|
||||
maxlength: '닉네임은 {0}자를 넘을 수 없습니다'
|
||||
},
|
||||
secret_agree: "동의해야만 가입하실 수 있습니다."
|
||||
},
|
||||
errorElement: "div",
|
||||
errorPlacement: function ( error, element ) {
|
||||
// Add the `help-block` class to the error element
|
||||
error.addClass( "invalid-feedback" );
|
||||
|
||||
if ( element.prop( "type" ) === "checkbox" ) {
|
||||
error.insertAfter( element.parent( "label" ) );
|
||||
} else {
|
||||
error.insertAfter( element );
|
||||
}
|
||||
},
|
||||
highlight: function ( element, errorClass, validClass ) {
|
||||
$( element ).addClass( "is-invalid" ).removeClass( "is-valid" );
|
||||
},
|
||||
unhighlight: function (element, errorClass, validClass) {
|
||||
$( element ).addClass( "is-valid" ).removeClass( "is-invalid" );
|
||||
}
|
||||
} );
|
||||
|
||||
$( "#main_form" ).submit(function(){
|
||||
var raw_password = $('#password').val();
|
||||
var salt = $('#global_salt').val();
|
||||
var hash_pw = sha512(salt + raw_password + salt);
|
||||
|
||||
$.post({
|
||||
url:'j_join_process.php',
|
||||
dataType:'json',
|
||||
data:{
|
||||
'secret_agree':$('#secret_agree').val(),
|
||||
'username':$('#username').val(),
|
||||
'password':hash_pw,
|
||||
'nickname':$('#nickname').val(),
|
||||
|
||||
}
|
||||
}).then(function(obj){
|
||||
if(!obj.result){
|
||||
alert(obj.reason);
|
||||
}
|
||||
else{
|
||||
alert('정상적으로 가입되었습니다.');
|
||||
}
|
||||
|
||||
window.location.href = '../';
|
||||
|
||||
});
|
||||
console.log('Yes!');
|
||||
return false;
|
||||
});
|
||||
} );
|
||||
|
||||
|
||||
$(function($){
|
||||
$.get('terms.html').then(function(txt){
|
||||
$('#terms').html(txt);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
require('_common.php');
|
||||
require(ROOT.'/f_func/class._Time.php');
|
||||
require_once(__dir__.'/../d_setting/conf.php');
|
||||
|
||||
use utilphp\util as util;
|
||||
|
||||
session_start();
|
||||
|
||||
$access_token = util::array_get($_SESSION['access_token']);
|
||||
if(!$access_token){
|
||||
header('Location:oauth_fail.html');
|
||||
}
|
||||
|
||||
$canJoin = getRootDB()->queryFirstField('SELECT REG FROM `SYSTEM` WHERE `NO` = 1');
|
||||
if($canJoin != 'Y'){
|
||||
die('현재는 가입이 금지되어있습니다!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
//session_write_close();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>회원가입</title>
|
||||
<script src="../e_lib/jquery-3.2.1.min.js"></script>
|
||||
<script src="../e_lib/bootstrap.bundle.min.js"></script>
|
||||
<script src="../e_lib/jquery.validate.min.js"></script>
|
||||
<script src="../e_lib/sha512.min.js"></script>
|
||||
<script src="join.js"></script>
|
||||
<link type="text/css" rel="stylesheet" href="../e_lib/bootstrap.min.css">
|
||||
<link type="text/css" rel="stylesheet" href="join.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="row justify-content-md-center">삼국지 모의전투 HiD</h1>
|
||||
<div class="row justify-content-md-center">
|
||||
<div class="col col-12 col-md-10 col-lg-7">
|
||||
<div class="card">
|
||||
<h3 class="card-header">
|
||||
회원가입
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
|
||||
<form id="main_form" method="post" action="#">
|
||||
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<label for="username" class="col-sm-3 col-form-label">계정명</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" name="username" id="username" placeholder="계정명"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<label for="password" class="col-sm-3 col-form-label">비밀번호</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="password" class="form-control" name="password" id="password" placeholder="비밀번호"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label for="confirm_password" class="col-sm-3 col-form-label">비밀번호 확인</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="password" class="form-control" name="confirm_password" id="confirm_password" placeholder="비밀번호 확인"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label for="nickname" class="col-sm-3 col-form-label">닉네임</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" name="nickname" id="nickname" placeholder="닉네임"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label for="username" class="col-sm-3 col-form-label">약관</label>
|
||||
<div class="col-sm-9">
|
||||
<div class="card">
|
||||
<div class="card-body terms" id="terms">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input type="checkbox" class="custom-control-input" id="secret_agree" name="secret_agree">
|
||||
<label class="custom-control-label" for="secret_agree">동의합니다.</label>
|
||||
<div class="invalid-feedback">
|
||||
동의해야만 가입하실 수 있습니다.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" id="input_hash_salt1" name="global_salt" value="<?=getGlobalSalt()?>">
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-3"></div>
|
||||
<div class="col-sm-9">
|
||||
<button type="submit" class="btn btn-primary btn-lg btn-block login-button">가입</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?=_Time::DatetimeNow()?>
|
||||
<?=util::array_get($_SESSION['access_token'])?><br>
|
||||
<?=util::array_get($_SESSION['expires'])?><br>
|
||||
<?=util::array_get($_SESSION['refresh_token'])?><br>
|
||||
<?=util::array_get($_SESSION['refresh_token_expires'])?><br>
|
||||
<?=$_SESSION['tmpx']?>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,464 @@
|
||||
<?php
|
||||
require(__DIR__.'/conf.php');
|
||||
//https://devtalk.kakao.com/t/php-rest-api/14602/3
|
||||
//header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
define('GET', 'GET');
|
||||
define('POST', 'POST');
|
||||
define('DELETE', 'DELETE');
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class User_Management_Path
|
||||
{
|
||||
public static $TOKEN = "/oauth/token";
|
||||
public static $SIGNUP = "/v1/user/signup";
|
||||
public static $UNLINK = "/v1/user/unlink";
|
||||
public static $LOGOUT = "/v1/user/logout";
|
||||
public static $ME = "/v1/user/me";
|
||||
public static $UPDATE_PROFILE = "/v1/user/update_profile";
|
||||
public static $USER_IDS = "/v1/user/ids";
|
||||
}
|
||||
|
||||
class Story_Path
|
||||
{
|
||||
public static $PROFILE = "/v1/api/story/profile";
|
||||
public static $ISSTORYUSER = "/v1/api/story/isstoryuser";
|
||||
public static $MYSTORIES = "/v1/api/story/mystories";
|
||||
public static $MYSTORY = "/v1/api/story/mystory";
|
||||
public static $DELETE_MYSTORY = "/v1/api/story/delete/mystory";
|
||||
public static $POST_NOTE = "/v1/api/story/post/note";
|
||||
public static $UPLOAD_MULTI = "/v1/api/story/upload/multi";
|
||||
public static $POST_PHOTO = "/v1/api/story/post/photo";
|
||||
public static $LINKINFO = "/v1/api/story/linkinfo";
|
||||
public static $POST_LINK = "/v1/api/story/post/link";
|
||||
}
|
||||
|
||||
class Talk_Path
|
||||
{
|
||||
public static $TALK_PROFILE= "/v1/api/talk/profile";
|
||||
public static $TALK_TO_ME = "/v2/api/talk/memo/send";
|
||||
}
|
||||
|
||||
class Push_Notification_Path
|
||||
{
|
||||
public static $REGISTER = "/v1/push/register";
|
||||
public static $TOKENS = "/v1/push/tokens";
|
||||
public static $DEREGISTER = "/v1/push/deregister";
|
||||
public static $SEND = "/v1/push/send";
|
||||
}
|
||||
|
||||
|
||||
class Kakao_REST_API_Helper
|
||||
{
|
||||
public static $OAUTH_HOST = "https://kauth.kakao.com";
|
||||
public static $API_HOST = "https://kapi.kakao.com";
|
||||
|
||||
private static $admin_apis;
|
||||
|
||||
private $access_token;
|
||||
private $admin_key;
|
||||
|
||||
public function __construct($access_token = '') {
|
||||
|
||||
if ($access_token) {
|
||||
$this->access_token = $access_token;
|
||||
}
|
||||
|
||||
self::$admin_apis = array(
|
||||
User_Management_Path::$USER_IDS,
|
||||
Push_Notification_Path::$REGISTER,
|
||||
Push_Notification_Path::$TOKENS,
|
||||
Push_Notification_Path::$DEREGISTER,
|
||||
Push_Notification_Path::$SEND
|
||||
);
|
||||
}
|
||||
|
||||
public function request($api_path, $params = '', $http_method = GET)
|
||||
{
|
||||
if ($api_path != Story_Path::$UPLOAD_MULTI && is_array($params)) { // except for uploading
|
||||
$params = http_build_query($params);
|
||||
}
|
||||
|
||||
$requestUrl = ($api_path == '/oauth/token' ? self::$OAUTH_HOST : self::$API_HOST) . $api_path;
|
||||
|
||||
if (($http_method == GET || $http_method == DELETE) && !empty($params)) {
|
||||
$requestUrl .= '?'.$params;
|
||||
}
|
||||
|
||||
$opts = array(
|
||||
CURLOPT_URL => $requestUrl,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSLVERSION => 1,
|
||||
);
|
||||
|
||||
if ($api_path != '/oauth/token')
|
||||
{
|
||||
if (in_array($api_path, self::$admin_apis)) {
|
||||
|
||||
if (!$this->admin_key) {
|
||||
throw new Exception('admin key should not be null or empty.');
|
||||
}
|
||||
$headers = array('Authorization: KakaoAK ' . $this->admin_key);
|
||||
|
||||
} else {
|
||||
|
||||
if (!$this->access_token) {
|
||||
throw new Exception('access token should not be null or empty.');
|
||||
}
|
||||
$headers = array('Authorization: Bearer ' . $this->access_token);
|
||||
}
|
||||
|
||||
$opts[CURLOPT_HEADER] = false;
|
||||
$opts[CURLOPT_HTTPHEADER] = $headers;
|
||||
}
|
||||
|
||||
if ($http_method == POST) {
|
||||
$opts[CURLOPT_POST] = true;
|
||||
if ($params) {
|
||||
$opts[CURLOPT_POSTFIELDS] = $params;
|
||||
}
|
||||
} else if ($http_method == DELETE) {
|
||||
$opts[CURLOPT_CUSTOMREQUEST] = DELETE;
|
||||
}
|
||||
|
||||
$curl_session = curl_init();
|
||||
curl_setopt_array($curl_session, $opts);
|
||||
$return_data = curl_exec($curl_session);
|
||||
|
||||
if (curl_errno($curl_session)) {
|
||||
throw new Exception(curl_error($curl_session));
|
||||
} else {
|
||||
// 디버깅 시에 주석을 풀고 응답 내용 확인할 때
|
||||
//print_r(curl_getinfo($curl_session));
|
||||
curl_close($curl_session);
|
||||
return json_decode($return_data, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function set_access_token($access_token) {
|
||||
$this->access_token = $access_token;
|
||||
}
|
||||
|
||||
public function set_admin_key($admin_key) {
|
||||
$this->admin_key = $admin_key;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// User Management
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
private function _create_or_refresh_access_token($params) {
|
||||
return $this->request(User_Management_Path::$TOKEN, $params, POST);
|
||||
}
|
||||
|
||||
public function create_access_token($authorization_code){
|
||||
$this->AUTHORIZATION_CODE = $authorization_code;
|
||||
$params = [
|
||||
'grant_type'=>'authorization_code',
|
||||
'client_id'=>$this->REST_KEY,
|
||||
'redirect_uri'=>$this->REDIRECT_URI,
|
||||
'code'=>$this->AUTHORIZATION_CODE
|
||||
];
|
||||
$result = $this->_create_or_refresh_access_token($params);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function refresh_access_token($refresh_token){
|
||||
$params = [
|
||||
'grant_type'=>'refresh_token',
|
||||
'client_id'=>$this->REST_KEY,
|
||||
'redirect_uri'=>$this->REDIRECT_URI,
|
||||
'code'=>$refresh_token
|
||||
];
|
||||
$result = $this->_create_or_refresh_access_token($params);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function signup() {
|
||||
return $this->request(User_Management_Path::$SIGNUP);
|
||||
}
|
||||
|
||||
public function unlink() {
|
||||
return $this->request(User_Management_Path::$UNLINK);
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
return $this->request(User_Management_Path::$UNLINK);
|
||||
}
|
||||
|
||||
public function me() {
|
||||
return $this->request(User_Management_Path::$ME);
|
||||
}
|
||||
|
||||
public function meWithEmail(){
|
||||
$params = [
|
||||
'propertyKeys'=>'["id","kaacount_email","kaccount_email_verified"]'
|
||||
];
|
||||
return $this->request(User_Management_Path::$ME);
|
||||
}
|
||||
|
||||
public function update_profile($params) {
|
||||
return $this->request(User_Management_Path::$UPDATE_PROFILE, $params, POST);
|
||||
}
|
||||
|
||||
public function user_ids() {
|
||||
return $this->request(User_Management_Path::$USER_IDS);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Kakao Story
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
public function isstoryuser() {
|
||||
return $this->request(Story_Path::$ISSTORYUSER);
|
||||
}
|
||||
|
||||
public function story_profile() {
|
||||
return $this->request(Story_Path::$PROFILE);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Kakao Talk
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
public function talk_profile() {
|
||||
return $this->request(Talk_Path::$TALK_PROFILE);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// API Test
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
private $REST_KEY = KakaoKey::REST_KEY; // 디벨로퍼스의 앱 설정에서 확인할 수 있습니다.
|
||||
private $REDIRECT_URI = KakaoKey::REDIRECT_URI; // 설정에 등록한 사이트 도메인 + redirect uri
|
||||
private $AUTHORIZATION_CODE = ''; // 동의를 한 후 발급되는 code
|
||||
private $REFRESH_TOKEN = '';
|
||||
|
||||
/*
|
||||
* 유저 관리 API 테스트
|
||||
*/
|
||||
public function test_user_management_api()
|
||||
{
|
||||
|
||||
/*
|
||||
// authorization code로 access token 얻기
|
||||
$params = array();
|
||||
$params['grant_type'] = 'authorization_code';
|
||||
$params['client_id'] = $this->REST_KEY;
|
||||
$params['redirect_uri'] = $this->REDIRECT_URI;
|
||||
$params['code'] = $this->AUTHORIZATION_CODE;
|
||||
$this->create_or_refresh_access_token($params);
|
||||
*/
|
||||
|
||||
/*
|
||||
// refresh token으로 access token 얻기
|
||||
$params = array();
|
||||
$params['grant_type'] = 'refresh_token';
|
||||
$params['client_id'] = $this->REST_KEY;
|
||||
$params['refresh_token'] = $this->REFRESH_TOKEN;
|
||||
echo $this->create_or_refresh_access_token($params);
|
||||
*/
|
||||
|
||||
/*
|
||||
// 앱 사용자 정보 요청 (signup 후에 사용 가능)
|
||||
echo $this->me();
|
||||
*/
|
||||
|
||||
/*
|
||||
// 앱 연결
|
||||
echo $this->signup();
|
||||
*/
|
||||
|
||||
/*
|
||||
// 앱 탈퇴 (unlink를 하면 access/refresh token이 삭제됩니다.)
|
||||
//echo $this->unlink();
|
||||
*/
|
||||
|
||||
/*
|
||||
// 앱 로그아웃 (로그아웃을 하면 access/refresh token이 삭제됩니다.)
|
||||
echo $this->logout();
|
||||
*/
|
||||
|
||||
/*
|
||||
// 앱 사용자 정보 업데이트
|
||||
$params = array();
|
||||
$params['properties'] = '{"nickname":"test11"}';
|
||||
echo $this->updateProfile($params);
|
||||
echo $this->me();
|
||||
*/
|
||||
|
||||
/*
|
||||
// 앱 사용자 리스트 요청 (파라미터)
|
||||
// 테스트하시려면 admin key 지정해야 합니다.
|
||||
echo $this->user_ids();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 카카오스토리 API 테스트
|
||||
*/
|
||||
public function test_story_api()
|
||||
{
|
||||
|
||||
/*
|
||||
// 스토리 프로파일 요청
|
||||
echo $this->story_profile();
|
||||
*/
|
||||
|
||||
/*
|
||||
// 스토리 유저인지 확인
|
||||
//echo $this->isstoryuser();
|
||||
*/
|
||||
|
||||
/*
|
||||
$story_common_params = array();
|
||||
|
||||
// 글 포스팅이면 필수
|
||||
$story_common_params['content'] = '더 나은 세상을 꿈꾸고 그것을 현실로 만드는 이를 위하여 카카오에서 앱 개발 플랫폼 서비스를 시작합니다.';
|
||||
|
||||
// 스토리 포스팅 공통 파라미터. 필요한 것만 선택하여 사용.
|
||||
//$story_common_params['permission'] = 'A'; // A : 전체공개, F: 친구에게만 공개, M: 나만보기
|
||||
//$story_common_params['enable_share'] = 'true'; // 공개 기능 허용 여부
|
||||
//$story_common_params['android_exec_param'] = 'cafe_id=1234'; // 앱 이동시 추가 파라미터
|
||||
//$story_common_params['ios_exec_param'] = 'cafe_id=1234';
|
||||
//$story_common_params['android_market_param'] = 'cafe_id=1234';
|
||||
//$story_common_params['ios_market_param'] = 'cafe_id=1234';
|
||||
|
||||
//$res = $helper->post_note($story_common_params);
|
||||
//echo $res;
|
||||
//$obj = json_decode($res);
|
||||
//this->delete_mystory($obj->id); // 포스팅된 스토리 삭제.
|
||||
*/
|
||||
|
||||
/*
|
||||
// 스토리 포스팅 공통 파라미터. 필요한 것만 선택하여 사용.
|
||||
$story_common_params = array();
|
||||
//$story_common_params['content'] = '더 나은 세상을 꿈꾸고 그것을 현실로 만드는 이를 위하여 카카오에서 앱 개발 플랫폼 서비스를 시작합니다.';
|
||||
//$story_common_params['permission'] = 'A'; // A : 전체공개, F: 친구에게만 공개, M: 나만보기
|
||||
//$story_common_params['enable_share'] = 'true'; // 공개 기능 허용 여부
|
||||
//$story_common_params['android_exec_param'] = 'cafe_id=1234'; // 앱 이동시 추가 파라미터
|
||||
//$story_common_params['ios_exec_param'] = 'cafe_id=1234';
|
||||
//$story_common_params['android_market_param'] = 'cafe_id=1234';
|
||||
//$story_common_params['ios_market_param'] = 'cafe_id=1234';
|
||||
|
||||
// 링크 포스팅
|
||||
$test_site_url = 'https://developers.kakao.com';
|
||||
$res = $this->post_link($test_site_url, $story_common_params);
|
||||
echo $res;
|
||||
$obj = json_decode($res);
|
||||
//$this->delete_mystory($obj->id); // 포스팅된 테스트 스토리 삭제.
|
||||
*/
|
||||
|
||||
/*
|
||||
// 스토리 포스팅 공통 파라미터. 필요한 것만 선택하여 사용.
|
||||
$story_common_params = array();
|
||||
$story_common_params['content'] = '더 나은 세상을 꿈꾸고 그것을 현실로 만드는 이를 위하여 카카오에서 앱 개발 플랫폼 서비스를 시작합니다.';
|
||||
//$story_common_params['permission'] = 'A'; // A : 전체공개, F: 친구에게만 공개, M: 나만보기
|
||||
//$story_common_params['enable_share'] = 'true'; // 공개 기능 허용 여부
|
||||
//$story_common_params['android_exec_param'] = 'cafe_id=1234'; // 앱 이동시 추가 파라미터
|
||||
//$story_common_params['ios_exec_param'] = 'cafe_id=1234';
|
||||
//$story_common_params['android_market_param'] = 'cafe_id=1234';
|
||||
//$story_common_params['ios_market_param'] = 'cafe_id=1234';
|
||||
|
||||
// 사진 포스팅 (최대 10개까지 가능)
|
||||
$file_params = array(
|
||||
'file[0]'=>"@/Users/tom/sample1.png",
|
||||
'file[1]'=>"@/Users/tom/sample2.png"
|
||||
);
|
||||
|
||||
// PHP 5 >= 5.5.0
|
||||
$file_params = array(
|
||||
'file[0]'=>new CurlFile('/Users/tom/sample1.png','image/png','sample1'),
|
||||
'file[1]'=>new CurlFile('/Users/tom/sample2.png','image/png','sample2')
|
||||
);
|
||||
|
||||
$res = $this->post_photo($file_params, $story_common_params);
|
||||
echo $res;
|
||||
$obj = json_decode($res);
|
||||
$this->delete_mystory($obj->id); // 포스팅된 테스트 스토리 삭제.
|
||||
*/
|
||||
|
||||
/*
|
||||
$test_mystory_id = '_cDLHO.GBNzGysmIZ9';
|
||||
|
||||
// 복수개의 내스토리 정보 요청
|
||||
echo $this->get_mystories();
|
||||
|
||||
// 복수개의 내스토리 정보 요청 (특정 아이디 부터)
|
||||
echo $this->get_mystories($test_mystory_id);
|
||||
|
||||
// 내스토리 정보 요청
|
||||
echo $this->get_mystory($test_mystory_id); // 포스팅된 테스트 스토리 삭제.
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 카카오톡 API 테스트
|
||||
*/
|
||||
public function test_talk_api()
|
||||
{
|
||||
// 카카오톡 프로필 요청
|
||||
//echo $this->talk_profile();
|
||||
}
|
||||
|
||||
/*
|
||||
* 푸시 알림 API 테스트
|
||||
*/
|
||||
public function test_push_notification_api()
|
||||
{
|
||||
// 파라미터 설명
|
||||
// @param uuid 사용자의 고유 ID. 1~(2^63 -1), 숫자만 가능
|
||||
// @param push_type gcm or apns
|
||||
// @param push_token apns(64자) or GCM으로부터 발급받은 push token
|
||||
// @param uuids 기기의 고유한 ID 리스트 (최대 100개까지 가능)
|
||||
|
||||
// 푸시 알림 관련 API를 테스트하시려면 admin key 지정해야 합니다.
|
||||
|
||||
/*
|
||||
// 푸시 등록
|
||||
$params = array(
|
||||
"uuid" => "10000",
|
||||
"push_type" => "gcm",
|
||||
"push_token" => "xxxxxxxxxx",
|
||||
"device_id" => ""
|
||||
);
|
||||
$this->register_push($params);
|
||||
*/
|
||||
|
||||
/*
|
||||
// 푸시 토큰 조회
|
||||
$param = array("uuid" => "10000");
|
||||
$this->get_push_tokens($param);
|
||||
*/
|
||||
|
||||
/*
|
||||
// 푸시 해제
|
||||
$params = array(
|
||||
"uuid" => "10000",
|
||||
"push_type" => "gcm",
|
||||
"push_token" => "xxxxxxxxxx"
|
||||
);
|
||||
$this->deregister_push($params);
|
||||
*/
|
||||
|
||||
/*
|
||||
// 푸시 보내기
|
||||
$param = array("uuids" => "[\"1\",\"2\", \"3\"]");
|
||||
$this->sendPush($param);
|
||||
*/
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
require_once('_common.php');
|
||||
require_once(__dir__.'/../d_setting/conf.php');
|
||||
require_once(__dir__.'/../f_func/func.php');
|
||||
|
||||
function checkUsernameDup($username){
|
||||
if(!$username){
|
||||
return '계정명을 입력해주세요';
|
||||
}
|
||||
|
||||
$length = strlen($username);
|
||||
if($length < 4 || $length > 64){
|
||||
return '적절하지 않은 길이입니다.';
|
||||
}
|
||||
|
||||
$cnt = getRootDB()->queryFirstField('SELECT count(no) FROM member WHERE `id` = %s LIMIT 1', $username);
|
||||
if($cnt != 0){
|
||||
return '이미 사용중인 계정명입니다';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkNicknameDup($nickname){
|
||||
if(!$nickname){
|
||||
return '닉네임을 입력해주세요';
|
||||
}
|
||||
|
||||
$length = strlen($nickname);
|
||||
if($length < 1 || $length > 6){
|
||||
return '적절하지 않은 길이입니다.';
|
||||
}
|
||||
|
||||
$cnt = getRootDB()->queryFirstField('SELECT count(no) FROM member WHERE `name` = %s LIMIT 1', $nickname);
|
||||
if($cnt != 0){
|
||||
return '이미 사용중인 닉네임입니다';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function checkEmailDup($email){
|
||||
if(!$email){
|
||||
return '이메일을 입력해주세요';
|
||||
}
|
||||
|
||||
$length = strlen($email);
|
||||
if($length < 1 || $length > 64){
|
||||
return '적절하지 않은 길이입니다.';
|
||||
}
|
||||
|
||||
$cnt = getRootDB()->queryFirstField('SELECT count(no) FROM member WHERE `email` = %s LIMIT 1', $email);
|
||||
if($cnt != 0){
|
||||
return '이미 사용중인 이메일입니다';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
require('_common.php');
|
||||
require(ROOT.'/f_config/DB.php');
|
||||
require(ROOT.'/f_func/class._Time.php');
|
||||
require('kakao.php');
|
||||
use utilphp\util as util;
|
||||
|
||||
$auth_code = util::array_get($_GET['code']);
|
||||
if(!$auth_code){
|
||||
|
||||
header('Location:oauth_fail.html');
|
||||
}
|
||||
|
||||
|
||||
//TODO: /oauth/token
|
||||
|
||||
$restAPI = new Kakao_REST_API_Helper();
|
||||
$result = $restAPI->create_access_token($auth_code);
|
||||
|
||||
//항상 scope = account_email profile임
|
||||
//항상 token_type = bearer임
|
||||
|
||||
//토큰을 받아옴.
|
||||
|
||||
|
||||
|
||||
if(util::array_get($result['expires_in'], -1) > 0){
|
||||
session_start();
|
||||
$restAPI->set_access_token($result['access_token']);
|
||||
$now = _Time::DatetimeNow();
|
||||
$_SESSION['access_token'] = $result['access_token'];
|
||||
$_SESSION['expires'] = _Time::DatetimeFromSecond($now, $result['expires_in']);
|
||||
$_SESSION['refresh_token'] = util::array_get($result['refresh_token']);
|
||||
$_SESSION['refresh_token_expires'] = _Time::DatetimeFromSecond($now, $result['refresh_token_expires_in']);
|
||||
}
|
||||
else{
|
||||
die('알 수 없는 에러:'.$me['msg']);
|
||||
}
|
||||
|
||||
$_SESSION['tmpx'] = json_encode($result,JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//echo "<br>\n";
|
||||
$me = $restAPI->meWithEmail();
|
||||
|
||||
var_dump($me);
|
||||
|
||||
$me['code'] = util::array_get($me['code'], 0);
|
||||
if($me['code']< 0){
|
||||
switch($me['msg']){
|
||||
case 'NotRegisteredUserException':
|
||||
header('Location:join.php', true, 303);
|
||||
die();
|
||||
default:
|
||||
die('알 수 없는 에러:'.$me['msg']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//이메일 주소를 받아옴
|
||||
|
||||
//
|
||||
//$db = getRootDB();
|
||||
//TODO: 로그인된 유저인지 확인해야함.
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">>
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>OAuth 로그인 실패</title>
|
||||
</head>
|
||||
<body>
|
||||
로그인에 실패하였습니다.
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
YES
|
||||
@@ -0,0 +1,5 @@
|
||||
<p>개인정보로써 <strong>이메일, 계정명, 닉네임</strong>을 수집하며, 유저 로그인 및 다중 접속 탐지를 위해 사용함. 이메일은 필요에 따라 공지사항 등 본 사이트의 정보를 전파하는데 사용될 수 있음. 위의 언급한 내용 이외의 용도로 개인정보를 사용하지 않음.</p>
|
||||
<p>수집된 개인정보는 탈퇴 후 1개월간 보관됨.</p>
|
||||
<p>게임 시스템을 오용하거나, 서버에 해킹시도하거나, 분란을 야기하는 경우 경고 처리 후 차단될 수 있으며, 경중에 따라 경고 처리 없이 바로 차단될 수 있음.</p>
|
||||
<p>개인정보 관리자 : Hide_D</p>
|
||||
<p>문의는 hided62@gmail.com 으로.</p>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
require('_common.php');
|
||||
require('kakao.php');
|
||||
|
||||
|
||||
|
||||
|
||||
// test code
|
||||
|
||||
$helper = new Kakao_REST_API_Helper('');
|
||||
$helper->set_admin_key('');
|
||||
|
||||
$helper->test_user_management_api();
|
||||
//$helper->test_story_api();
|
||||
//$helper->test_talk_api();
|
||||
//$helper->test_push_notification_api();
|
||||
Reference in New Issue
Block a user