function kakao(){
$result = array();
try{
// 토큰 받기
$post = $this->postData['params'];
$url = 'https://kauth.kakao.com/oauth/token';
$curlHandle = curl_init($url);
$data = array(
"grant_type"=>"authorization_code",
"client_id"=>$clientId,
"redirect_uri"=>$post['redirect_uri'],
"code"=>$post['code'],
);
curl_setopt_array($curlHandle, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded;charset=utf-8'
),
CURLOPT_POSTFIELDS => http_build_query($data)
]);
$response = curl_exec($curlHandle);
$httpCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
if( $httpCode!="200" ) $this->result("104",$response);
$token = json_decode($response,true);
curl_close($curlHandle);
// 사용자 정보 가져오기
$url = 'https://kapi.kakao.com/v2/user/me';
$curlHandle = curl_init($url);
curl_setopt_array($curlHandle, [
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $token['access_token'],
'Content-Type: application/x-www-form-urlencoded;charset=utf-8'
),
]);
$response = curl_exec($curlHandle);
$httpCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
if( $httpCode!="200" ) $this->result("104",$response);
$user = json_decode($response,true);
curl_close($curlHandle);
$value = array();
$result['type'] = 'login';
$row = $this->member->select("mb_id,mb_stt,pt_id,mb_passwd,mb_login_cnt,count(mb_id) as cnt"," and mb_sns_id_1 = '{$user['id']}' and pt_id = '{$this->shopId}'");
if( $row['cnt'] < 1 ){ // 사용자 존재 여부 확인
$result['type'] = 'join';
$result['nick'] = $user['properties']['nickname'];
$arr = array();
$arr['id'] = uniqid();
$arr['passwd'] = uniqid();
$arr['snsid1'] = $user['id'];
$arr['shop'] = $this->shopId;
$arr['name'] = $user['properties']['nickname'];
$arr['gender'] = $user['kakao_account']['gender'];
if(!empty($user['properties']['profile_image'])){
$rawImg = file_get_contents($user['properties']['profile_image']);
$img = 'data:image/jpg;base64,'.base64_encode($rawImg);
$arr['img'] = $img;
}
$res = $this->member->add($arr);
$row = $this->member->get($arr['id'],"mb_id,mb_stt,pt_id,mb_passwd,mb_login_cnt,count(mb_id) as cnt");
}
if ( $row['mb_stt'] != 2 ) $this->result("100");
$value['mb_last_login_dt'] = _DATE_YMDHIS;
$value['mb_last_login_ip'] = $_SERVER['REMOTE_ADDR'];
$value['mb_login_cnt'] = $row['mb_login_cnt']+1;
$res = $this->member->set($value,$row['mb_id'],"value");
$result['token'] = array(
'access' => $this->jwt->hashing(array("index" => $row['mb_id'], "exp" => time()+($this->expiration))),
'refresh' => $this->jwt->hashing(array("index" => $row['mb_id'], "exp" => time()+2*($this->expiration)))
);
$result['res'] = "SUCCESS";
}catch(Exception $e){
$result['res'] = "FAILED";
}
echo json_encode($result);
}