<!DOCTYPE html>
<html lang="en">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QT401FZZ2K"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-QT401FZZ2K');
</script>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>LINE Login</title>
    <style>
        #timeJump {
            display: none;
        }
    </style>
</head>

<body>
    <!-- <h1 id="timeJump">登錄成功,<span id="jTime">5</span>秒后返回App</h1> -->
    <script type="text/javascript" src="lib/jquery-3.1.1.min.js"></script>
    <script src="lib/default.js"></script>
    <script>
        var urlParam = url_get_params();
        $.ajax({
            url: 'https://api.line.me/oauth2/v2.1/token',
            data: {
                grant_type: 'authorization_code',
                code: urlParam.code,
                redirect_uri: 'https://www.footseen.xyz/lineBack.html',
                client_id: '1654468829',
                client_secret: 'd70325add488ea05fd25ba84c6d91b6c'
            },
            type: 'POST',
            success: function (res) {
                var mAutho = res;
                $.ajax({
                    url: 'https://api.line.me/oauth2/v2.1/verify',
                    type: 'POST',
                    data: {
                        client_id: '1654468829',
                        id_token: mAutho.id_token
                    },
                    success: function (res) {
                        //console.log('line',res)
                        $.ajax({
                            url:$ip+'third/login',
                            data:{
                                openid:res.sub,
                                opentype:8,
                                authToken:mAutho.id_token,
                                nickname:res.name,
                                facepath:res.picture,
                                pageID:localStorage.canvasCode
                            },
                            success:function(data){
                                //console.log('line',data)
                                if(data.code!=1){
                                    layer.msg(data.msg)
                                    return;
                                }
                                localStorage.token=data.token
                                localStorage.uid=data.uid
                                $.ajax({
                                    url:$ip+'activeLog/webActive',
                                    data:{
                                        activeType:7,
                                        pageID:localStorage.canvasCode,
                                        uid:localStorage.uid
                                    },
                                    success:function(data){
                                        var ua = window.navigator.userAgent.toLowerCase(); 
                                        if (/iphone|ipad|ipod/.test(ua)) {
                                            window.location.href='mTest/index.html'
                                        } else if (/android/.test(ua)) {
                                            window.location.href='mTest/index.html'
                                        }else{
                                            window.location.href='index.html'
                                        }
                                    
                                    }
                                })
                        
                            }
                        })
                        // window.location.href = "footseenlogin://" + encodeURIComponent("www.firefly.live?token=" + mAutho.id_token + "&name=" + res.name + "&profileImageUrl=" + res.iss + "&id=" + res.sub);
                    }
                })

            }
        })
  
        function url_get_params() {
            var url = location.href;
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(url.indexOf("?") + 1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
    </script>
</body>

</html>