รบกวนช่วยดู code ให้ทีครับ ขอบคุณครับ
index.php <script type="text/javascript">
function loginLine(){
var win = window.open("https://access.line.me/dialog/oauth/weblogin?response_type=code&client_id=xxxxxxxx&redirect_uri=http://xxxxx/line/check.php&state=reftest001",'Popup','height=500,width=480');
win.window.focus();
}
function loginCallback(token,displayName,mid,pictureUrl,statusMessage){
var _html = '';
_html = '<img src="' pictureUrl '"><br>';
_html = 'Name : ' displayName '<br>';
_html = 'statusMessage : ' statusMessage '<br>';
_html = 'token : ' token '<br>';
_html = 'mid : ' mid '<br>';
$("#result").html(_html);
$("#login_div").hide();
}
</script>
</head>
<body>
<a onclick="loginLine()"><img src="btn_login_base.png">กด</a>
check.php$client_id = "xxx";
$client_secret = "xxxxxxxxxxx";
$redirect_uri = "http://xxx/line/check.php";
$token = "";
function getToken($code){
global $client_id, $client_secret,$redirect_uri;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.line.me/v1/oauth/accessToken",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=authorization_code&code=".$code."&client_id=".$client_id."&client_secret=".$client_secret."&redirect_uri=".$redirect_uri,
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
function getProfile(){
global $token;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.line.me/v1/profile",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer ".$token,
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$obj = json_decode(getToken($_GET['code']),true);
$token = $obj['access_token'];
$obj_profile = json_decode(getProfile(),true);