first
This commit is contained in:
29
modules/connect/action/a.config.php
Normal file
29
modules/connect/action/a.config.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
if(!defined('__KIMS__')) exit;
|
||||
|
||||
checkAdmin(0);
|
||||
|
||||
$snsSet = array('n','k','g','f','t','i');
|
||||
|
||||
$_tmpdfile = $g['path_var'].'site/'.$r.'/'.$m.'.var.php';
|
||||
|
||||
$fp = fopen($_tmpdfile,'w');
|
||||
fwrite($fp, "<?php\n");
|
||||
|
||||
foreach ($snsSet as $val)
|
||||
{
|
||||
fwrite($fp, "\$d['connect']['key_".$val."'] = \"".${'key_'.$val}."\";\n");
|
||||
fwrite($fp, "\$d['connect']['secret_".$val."'] = \"".${'secret_'.$val}."\";\n");
|
||||
fwrite($fp, "\$d['connect']['use_".$val."'] = \"".${'use_'.$val}."\";\n");
|
||||
}
|
||||
|
||||
fwrite($fp, "\$d['connect']['jskey_k'] = \"".${'jskey_k'}."\";\n"); // 카카오 JavaScript 키
|
||||
fwrite($fp, "\$d['connect']['apikey_g'] = \"".${'apikey_g'}."\";\n"); // 구글 API 키
|
||||
|
||||
fwrite($fp, "?>");
|
||||
fclose($fp);
|
||||
@chmod($_tmpdfile,0707);
|
||||
|
||||
setrawcookie('connect_config_result', rawurlencode('저장 되었습니다.|success')); // 처리여부 cookie 저장
|
||||
getLink('reload','parent.','','');
|
||||
?>
|
||||
280
modules/connect/action/a.connect.php
Normal file
280
modules/connect/action/a.connect.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
if(!defined('__KIMS__')) exit;
|
||||
|
||||
// 외부연결시 referer
|
||||
$connect_referer = $_SESSION['connect_referer'];
|
||||
|
||||
include $g['path_var'].'site/'.$r.'/connect.var.php';
|
||||
|
||||
$_SESSION['SL'] = array();
|
||||
|
||||
if ($_POST['returnofgoogle'] == 'Y') {
|
||||
$result = array();
|
||||
$result['token'] = $_POST['token'];
|
||||
$result['uid'] = $_POST['uid'];
|
||||
$result['email'] = $_POST['email'];
|
||||
$result['name'] = $_POST['name'];
|
||||
$result['photo'] = $_POST['photo'];
|
||||
$result['link'] = $_POST['link'];
|
||||
$result['sex'] = $_POST['sex'] == 'male' ? 1 : 2;
|
||||
|
||||
$_SESSION['SL']['google']['userinfo'] = $result;
|
||||
header('Location: '.$connect_referer);
|
||||
}
|
||||
|
||||
// 콜백 URL에 code값과 state 값이 URL 문자열로 전송됩니다. code 값은 접근 토큰 발급 요청에 사용합니다.
|
||||
function socialLogin($s,$id,$secret,$callBack,$type) {
|
||||
// 소셜로그인시 referer
|
||||
$connect_referer = $_SESSION['connect_referer'];
|
||||
|
||||
if(!$_SESSION['SL']['state'.$s]) $_SESSION['SL']['state'.$s] = md5(microtime().mt_rand());
|
||||
|
||||
$g['connect']['client_id'] = $id;
|
||||
$g['connect']['client_secret'] = $secret;
|
||||
$g['connect']['redirect_uri'] = urlencode($callBack);
|
||||
$g['connect']['state'] = $_SESSION['SL']['state'.$s];
|
||||
$g['connect']['code'] = $_REQUEST['code'];
|
||||
|
||||
// 네이버 ******************************************************************************************************************************************/
|
||||
if ($s == 'naver')
|
||||
{
|
||||
$g['connect']['callurl'] = 'https://nid.naver.com/oauth2.0/token?client_id='.$g['connect']['client_id'].'&client_secret='.$g['connect']['client_secret'];
|
||||
$g['connect']['callurl'].= '&grant_type=authorization_code&code='.$g['connect']['code'].'&state='.$g['connect']['state'];
|
||||
|
||||
if($type == 'token') {
|
||||
|
||||
// if ($g['connect']['state'] != $_REQUEST['state']) getLink(RW(0),'','인증에 실패했습니다. 다시 시도해 주세요.','');
|
||||
|
||||
// 접근 토큰 발급 요청
|
||||
if ($_SESSION['SL'][$s]['userinfo']['access_token']) $dat['access_token'] = $_SESSION['SL'][$s]['userinfo']['access_token'];
|
||||
else $dat = json_decode(getCURLData($g['connect']['callurl'],''), true);
|
||||
|
||||
// 접근 토큰을 이용하여 프로필 API 호출하기
|
||||
$dat1 = json_decode(getCURLData('https://openapi.naver.com/v1/nid/me',array("Authorization: Bearer ".$dat['access_token'])), true);
|
||||
|
||||
// 프로필 정보 배열처리 후, 세션저장
|
||||
$result = array();
|
||||
$result['provider'] = $s;
|
||||
$result['access_token'] = $dat['access_token'];
|
||||
$result['refresh_token'] = $dat['refresh_token'];
|
||||
$result['expires_in'] = $dat['expires_in'];
|
||||
$result['uid'] = $dat1['response']['id'];
|
||||
$result['name'] = $dat1['response']['nickname'];
|
||||
$result['email'] = $dat1['response']['email'];
|
||||
$result['photo'] = $dat1['response']['profile_image'];
|
||||
$result['age'] = $dat1['response']['age'];
|
||||
$result['sex'] = $dat1['response']['gender'];
|
||||
$result['sex'] = $result['sex'] == 'M' ? 1 : 2;
|
||||
$result['birthday'] = str_replace('-','',$dat1['response']['birthday']);
|
||||
$_SESSION['SL'][$s]['userinfo'] = $result;
|
||||
|
||||
// 원래페이지 이동
|
||||
header('Location: '.$connect_referer);
|
||||
}
|
||||
}
|
||||
|
||||
// 카카오 ******************************************************************************************************************************************/
|
||||
if ($s == 'kakao') {
|
||||
$g['connect']['callurl'] = 'https://kauth.kakao.com/oauth/token?client_id='.$g['connect']['client_id'].'&grant_type=authorization_code&code='.$g['connect']['code'].'&redirect_uri='.$g['connect']['redirect_uri'].'&client_secret='.$g['connect']['client_secret'];
|
||||
|
||||
if ($type == 'token')
|
||||
{
|
||||
|
||||
if($_GET['error'] == 'access_denied') getLink('','','인증에 실패했습니다. 다시 시도해 주세요.','');
|
||||
|
||||
if ($_SESSION['SL'][$s]['userinfo']['access_token']) {
|
||||
$dat1['access_token'] = $_SESSION['SL'][$s]['userinfo']['access_token'];
|
||||
} else {
|
||||
$dat1 = json_decode(getCURLData($g['connect']['callurl'],''), true);
|
||||
}
|
||||
|
||||
$dat2 = json_decode(getCURLData('https://kapi.kakao.com/v2/user/me',array("Authorization: Bearer ".$dat1['access_token'])), true);
|
||||
$isksuser = json_decode(getCURLData('https://kapi.kakao.com/v1/api/story/isstoryuser',array("Authorization: Bearer ".$dat1['access_token'])), true);
|
||||
if ($isksuser['isStoryUser'])
|
||||
{
|
||||
$dat3 = json_decode(getCURLData('https://kapi.kakao.com/v1/api/story/profile',array("Authorization: Bearer ".$dat1['access_token'])), true);
|
||||
/*
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "https://kapi.kakao.com/v1/api/story/post/note?permission=M&content=".urlencode('REST API로 카카오 스토리에 노트를 올려봅니다. - '.date('Y/m/d H:i:s')));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
"Authorization: Bearer ".$dat1['access_token']
|
||||
));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
$result_post_note = json_decode(curl_exec($ch),true);
|
||||
curl_close($ch);
|
||||
*/
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result['access_token'] = $dat1['access_token'];
|
||||
$result['refresh_token'] = $dat1['refresh_token'];
|
||||
$result['expires_in'] = $dat1['expires_in'];
|
||||
$result['uid'] = $dat2['id'];
|
||||
$result['email'] = $dat2['kaccount_email'];
|
||||
$result['name'] = $dat2['properties']['nickname'];
|
||||
$result['photo'] = $dat2['properties']['profile_image'];
|
||||
$result['photo_thumb'] = $dat2['properties']['thumbnail_image'];
|
||||
$result['link'] = $dat3['permalink'];
|
||||
$result['birthday'] = $dat3['birthday'];
|
||||
$result['birthday_type'] = $dat3['birthdayType'] == 'SOLAR' ? 0 : 1;
|
||||
$result['ks_img_profile'] = $dat3['profileImageURL'];
|
||||
$result['ks_img_profile_thumb'] = $dat3['thumbnailURL'];
|
||||
$result['ks_img_bg'] = $dat3['bgImageURL'];
|
||||
|
||||
$_SESSION['SL'][$s]['userinfo'] = $result;
|
||||
|
||||
header('Location: '.$connect_referer);
|
||||
}
|
||||
}
|
||||
|
||||
// 페이스북 ******************************************************************************************************************************************/
|
||||
if ($s == 'facebook')
|
||||
{
|
||||
$g['connect']['callurl'] = 'https://graph.facebook.com/v3.0/oauth/access_token?client_id='.$g['connect']['client_id'].'&client_secret='.$g['connect']['client_secret'].'&code='.$g['connect']['code'].'&redirect_uri='.$g['connect']['redirect_uri'];
|
||||
|
||||
if ($type == 'token')
|
||||
{
|
||||
if($_GET['error'] == 'access_denied') getLink('','','인증에 실패했습니다. 다시 시도해 주세요.','close');
|
||||
|
||||
// 접근 토큰 발급 요청
|
||||
if ($_SESSION['SL'][$s]['userinfo']['token']) $dat['access_token'] = $_SESSION['SL'][$s]['userinfo']['token'];
|
||||
else $dat = json_decode(getCURLData($g['connect']['callurl'],''), true);
|
||||
|
||||
// 접근 토큰을 이용하여 프로필 API 호출하기
|
||||
$dat1 = json_decode(getCURLData('https://graph.facebook.com/v3.0/me?fields=id,email,first_name,last_name,name&access_token='.$dat['access_token'],''), true);
|
||||
|
||||
// 프로필 정보 배열처리 후, 세션저장
|
||||
$result = array();
|
||||
$result['token'] = $dat['access_token'];
|
||||
$result['uid'] = $dat1['id'];
|
||||
$result['name'] = $dat1['last_name'].$dat1['first_name']; // $dat['name']
|
||||
$result['email'] = $dat1['email'];
|
||||
$result['photo'] = 'https://graph.facebook.com/'.$dat1['id'].'/picture?type=large';
|
||||
// $result['link'] = $dat1['link'];
|
||||
// $result['sex'] = $dat1['gender'] == 'male' ? 1 : 2;
|
||||
// $_birthday = explode('/',$dat1['birthday']);
|
||||
// $result['birthday'] = $_birthday[2].$_birthday[1].$_birthday[0];
|
||||
$_SESSION['SL'][$s]['userinfo'] = $result;
|
||||
header('Location: '.$connect_referer);
|
||||
}
|
||||
}
|
||||
|
||||
// 구글 && 유투브 ******************************************************************************************************************************************/
|
||||
if ($s == 'google')
|
||||
{
|
||||
$g['connect']['callapi'] = 'https://accounts.google.com/o/oauth2/auth?client_id='.$g['connect']['client_id'].'&redirect_uri='.$g['connect']['redirect_uri'].'&response_type=code&scope=email%20profile&state=%2Fprofile&approval_prompt=auto';
|
||||
$g['connect']['callapi_youtube'] = 'https://accounts.google.com/o/oauth2/auth?client_id='.$g['connect']['client_id'].'&redirect_uri='.$g['connect']['redirect_uri'];
|
||||
$g['connect']['callapi_youtube'].= '&response_type=code&scope=https://www.googleapis.com/auth/youtube%20email%20profile&access_type=offline';
|
||||
|
||||
if ($type == 'token')
|
||||
{
|
||||
if($_GET['error'] == 'access_denied') getLink('','','인증에 실패했습니다. 다시 시도해 주세요.','close');
|
||||
|
||||
$_nowToken = $_REQUEST['state']=='/profile' ? 'token' : 'token_youtube';
|
||||
|
||||
if ($_SESSION['SL'][$s]['userinfo'][$_nowToken])
|
||||
{
|
||||
$dat1['access_token'] = $_SESSION['SL'][$s]['userinfo'][$_nowToken];
|
||||
}
|
||||
else
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/token");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
|
||||
'code' => $g['connect']['code'],
|
||||
'client_id' => $g['connect']['client_id'],
|
||||
'client_secret' => $g['connect']['client_secret'],
|
||||
'redirect_uri' => urldecode($g['connect']['redirect_uri']),
|
||||
'grant_type' => 'authorization_code'
|
||||
));
|
||||
|
||||
$dat1 = (array)json_decode(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
}
|
||||
$dat2 = json_decode(getCURLData('https://www.googleapis.com/oauth2/v2/userinfo',array("Authorization: Bearer ".$dat1['access_token'])), true);
|
||||
|
||||
$result = array();
|
||||
if($_nowToken == 'token')
|
||||
{
|
||||
$result['token'] = $dat1['access_token'];
|
||||
$result['token_youtube'] = $_SESSION['SL'][$s]['userinfo']['token_youtube'];
|
||||
}
|
||||
else {
|
||||
$result['token'] = $_SESSION['SL'][$s]['userinfo']['token'];
|
||||
$result['token_youtube'] = $dat1['access_token'];
|
||||
}
|
||||
$result['uid'] = $dat2['id'];
|
||||
$result['email'] = $dat2['email'];
|
||||
$result['name'] = $dat2['name'];
|
||||
$result['photo'] = $dat2['picture'];
|
||||
$result['link'] = $dat2['link'];
|
||||
$result['sex'] = $dat2['gender'] == 'male' ? 1 : 2;
|
||||
|
||||
$_SESSION['SL'][$s]['userinfo'] = $result;
|
||||
header('Location: '.$connect_referer);
|
||||
//getLink($_SERVER['HTTP_REFERER'],'','','');
|
||||
}
|
||||
}
|
||||
|
||||
// 인스타그램 ******************************************************************************************************************************************/
|
||||
if ($s == 'instagram')
|
||||
{
|
||||
$g['connect']['callapi'] = 'https://api.instagram.com/oauth/authorize/?client_id='.$g['connect']['client_id'].'&redirect_uri='.$g['connect']['redirect_uri'].'&response_type=code';
|
||||
|
||||
if ($type == 'token')
|
||||
{
|
||||
if($_GET['error'] == 'access_denied') getLink('','','인증에 실패했습니다. 다시 시도해 주세요.','close');
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "https://api.instagram.com/oauth/access_token");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
|
||||
'code' => $g['connect']['code'],
|
||||
'client_id' => $g['connect']['client_id'],
|
||||
'client_secret' => $g['connect']['client_secret'],
|
||||
'redirect_uri' => urldecode($g['connect']['redirect_uri']),
|
||||
'grant_type' => 'authorization_code'
|
||||
));
|
||||
|
||||
$dat1 = (array)json_decode(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
$access_token = $dat1['access_token'];
|
||||
$dat2 = (array)$dat1['user'];
|
||||
|
||||
$result = array();
|
||||
$result['access_token'] = $access_token;
|
||||
$result['uid'] = $dat2['id'];
|
||||
$result['name'] = $dat2['full_name'];
|
||||
$result['photo'] = $dat2['profile_picture'];
|
||||
$result['link'] = $dat2['website'];
|
||||
$_SESSION['SL'][$s]['userinfo'] = $result;
|
||||
header('Location: '.$connect_referer);
|
||||
}
|
||||
}
|
||||
|
||||
return $g['connect'];
|
||||
}
|
||||
|
||||
if ($_GET['connectReturn'] == 'naver') {
|
||||
socialLogin($_GET['connectReturn'],$d['connect']['key_n'],$d['connect']['secret_n'],$g['url_root'].'/'.$r.'/oauth/naver','token');
|
||||
}
|
||||
if ($_GET['connectReturn'] == 'kakao') {
|
||||
socialLogin($_GET['connectReturn'],$d['connect']['key_k'],$d['connect']['secret_k'],$g['url_root'].'/'.$r.'/oauth/kakao','token');
|
||||
}
|
||||
if ($_GET['connectReturn'] == 'google') {
|
||||
socialLogin($_GET['connectReturn'],$d['connect']['key_g'],$d['connect']['secret_g'],$g['url_root'].'/'.$r.'/oauth/google','token');
|
||||
}
|
||||
if ($_GET['connectReturn'] == 'facebook') {
|
||||
socialLogin($_GET['connectReturn'],$d['connect']['key_f'],$d['connect']['secret_f'],$g['url_root'].'/'.$r.'/oauth/facebook','token');
|
||||
}
|
||||
if ($_GET['connectReturn'] == 'instagram') {
|
||||
socialLogin($_GET['connectReturn'],$d['connect']['key_i'],$d['connect']['secret_i'],$g['url_root'].'/'.$r.'/oauth/instagram','token');
|
||||
}
|
||||
?>
|
||||
55
modules/connect/action/a.kakao_sendMeTalk.php
Normal file
55
modules/connect/action/a.kakao_sendMeTalk.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
if(!defined('__KIMS__')) exit;
|
||||
|
||||
// if (!$my['uid']) getLink('','','정상적인 접근이 아닙니다.','');
|
||||
|
||||
$MS = getDbData($table['s_mbrsns'],"mbruid='".$my['uid']."' and sns='kakao'",'*');
|
||||
|
||||
//getLink('','',$MS['access_token'].' 토근입니다..','');
|
||||
|
||||
$msg = 'template_object= {
|
||||
"object_type": "feed",
|
||||
"content": {
|
||||
"title": "디저트 사진",
|
||||
"description": "아메리카노, 빵, 케익",
|
||||
"image_url": "http://mud-kage.kakao.co.kr/dn/NTmhS/btqfEUdFAUf/FjKzkZsnoeE4o19klTOVI1/openlink_640x640s.jpg",
|
||||
"image_width": 640,
|
||||
"image_height": 640,
|
||||
"link": {
|
||||
"web_url": "http://www.daum.net",
|
||||
"mobile_web_url": "http://m.daum.net",
|
||||
"android_execution_params": "contentId=100",
|
||||
"ios_execution_params": "contentId=100"
|
||||
}
|
||||
},
|
||||
"social": {
|
||||
"like_count": 100,
|
||||
"comment_count": 200,
|
||||
"shared_count": 300,
|
||||
"view_count": 400,
|
||||
"subscriber_count": 500
|
||||
},
|
||||
"buttons": [
|
||||
{
|
||||
"title": "웹으로 이동",
|
||||
"link": {
|
||||
"web_url": "http://www.daum.net",
|
||||
"mobile_web_url": "http://m.daum.net"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "앱으로 이동",
|
||||
"link": {
|
||||
"android_execution_params": "contentId=100",
|
||||
"ios_execution_params": "contentId=100"
|
||||
}
|
||||
}
|
||||
]
|
||||
}';
|
||||
|
||||
$dat = json_decode(getCURLData2('https://kapi.kakao.com/v2/api/talk/memo/default/send',array("Authorization: Bearer ".$MS['access_token']),array($msg)), true);
|
||||
|
||||
|
||||
getLink('','',$dat['result_code'].' 결과입니다.','-1');
|
||||
|
||||
?>
|
||||
5
modules/connect/action/a.save_referer.php
Normal file
5
modules/connect/action/a.save_referer.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
if(!defined('__KIMS__')) exit;
|
||||
$_SESSION['connect_referer'] = $_POST['referer'];
|
||||
exit;
|
||||
?>
|
||||
Reference in New Issue
Block a user