init
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
class Auth
|
||||
{
|
||||
public $is_auth = false;
|
||||
public function __construct()
|
||||
{
|
||||
$bearer = Auth::getBearerToken();
|
||||
if ($bearer == 'a2d6a3468e8299effeed07f04070ffc3') { //주식회사 케어랩스 Admin 키
|
||||
$this->is_auth = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get header Authorization
|
||||
* */
|
||||
static private function getAuthorizationHeader()
|
||||
{
|
||||
$headers = null;
|
||||
if (isset($_SERVER['Authorization'])) {
|
||||
$headers = trim($_SERVER["Authorization"]);
|
||||
} else if (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI
|
||||
$headers = trim($_SERVER["HTTP_AUTHORIZATION"]);
|
||||
} elseif (function_exists('apache_request_headers')) {
|
||||
$requestHeaders = apache_request_headers();
|
||||
// Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization)
|
||||
$requestHeaders = array_combine(array_map('ucwords', array_keys($requestHeaders)), array_values($requestHeaders));
|
||||
//print_r($requestHeaders);
|
||||
if (isset($requestHeaders['Authorization'])) {
|
||||
$headers = trim($requestHeaders['Authorization']);
|
||||
}
|
||||
}
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* get access token from header
|
||||
* */
|
||||
static public function getBearerToken()
|
||||
{
|
||||
$headers = Auth::getAuthorizationHeader();
|
||||
// HEADER: Get the access token from the header
|
||||
if (!empty($headers)) {
|
||||
if (preg_match('/KakaoAK\s(\S+)/', $headers, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//암호화 함수
|
||||
private function aes_encrypt($data, $key = '++!CHAINSAW!++')
|
||||
{
|
||||
$key = substr(hex2bin(openssl_digest($key, 'sha512')), 0, 16);
|
||||
$enc = openssl_encrypt($data, "AES-128-ECB", $key, true);
|
||||
return strtoupper(bin2hex($enc));
|
||||
}
|
||||
|
||||
//복호화 함수
|
||||
public function aes_decrypt($data, $key = '++!CHAINSAW!++')
|
||||
{
|
||||
$data = @hex2bin($data);
|
||||
$key = substr(hex2bin(openssl_digest($key, 'sha512')), 0, 16);
|
||||
$dec = openssl_decrypt($data, "AES-128-ECB", $key, true);
|
||||
return $dec;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
$temp = ini_set('display_errors', 'On');
|
||||
include __DIR__."/auth.php";
|
||||
include __DIR__.'/../../dbinfo.php';
|
||||
$auth = new Auth();
|
||||
if(!$auth->is_auth) exit('Authentication Failed.');
|
||||
$db = mysqli_connect(MYSQL_RW_HOST, MYSQL_USER_ID, MYSQL_USER_PW, MYSQL_DB_NAME);
|
||||
/*
|
||||
CHAT_TYPE
|
||||
String 카카오톡 공유 메시지가 전달된 채팅방의 타입
|
||||
MemoChat: 나와의 채팅방
|
||||
DirectChat: 다른 사용자와의 1:1 채팅방
|
||||
MultiChat: 다른 사용자들과의 그룹 채팅방
|
||||
|
||||
HASH_CHAT_ID
|
||||
String 카카오톡 공유 메시지를 수신한 채팅방의 참고용 ID
|
||||
서비스별로 유일(Unique)한 해시(Hash) 값으로, 같은 채팅방이라도 서비스마다 다른 값 제공
|
||||
|
||||
TEMPLATE_ID
|
||||
Long 메시지 템플릿 ID를 사용해 카카오톡 공유 메시지를 보낸 경우 사용된 메시지 템플릿의 ID, 메시지 템플릿 ID를 사용해 요청하지 않은 경우 전달되지 않음
|
||||
|
||||
key
|
||||
*/
|
||||
$json = file_get_contents('php://input');
|
||||
//file_put_contents(__DIR__.'/../../uploads/shareCallBack_log_'.date("j.n.Y").'.txt', $json, FILE_APPEND);
|
||||
$data = json_decode($json,true);
|
||||
|
||||
$eid = $data['key'];
|
||||
$eid = $auth->aes_decrypt($eid);
|
||||
|
||||
$sql = "INSERT INTO event_kakao_share(event_eid, chat_type, hash_chat_id, template_id, reg_date) VALUES('{$eid}', '{$data['CHAT_TYPE']}', '{$data['HASH_CHAT_ID']}', '{$data['TEMPLATE_ID']}', NOW())";
|
||||
$result = $db->query($sql) or die($db->mysql_error);
|
||||
Reference in New Issue
Block a user