<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>同城急送-授权登录</title>
</head>
<body>
</body>
<script src = "https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js"> </script>
<script>
    window.onload = function(){
        test();
        if(isZfb()){
            ap.getAuthCode ({
                appId :  '2021001104656498' ,
                scopes : ['auth_user'],
            },function(res){
                if ((!res.authCode)||res.authCode.length<1){
                    alert("您没有授权！");
                    let id=getQueryVariable("id");
                    let type=getQueryVariable("type");
                    let uri=getQueryVariable("redirect_uri");
                    window.location.href=decodeURIComponent(uri)+"?id="+id+"&type="+type+"&authCode="+res.authCode;
                }

            });
        }else{
            alert("请使用支付宝APP打开！");
        }

    }
    function test(){
        let id=getQueryVariable("id");
        let type=getQueryVariable("type");
        let uri=getQueryVariable("redirect_uri");
        alert(id+","+type);
        alert(uri);
        window.location.href=decodeURIComponent(uri)+"?id="+id+"&type="+type+"&authCode=sss";
    }

    /**
     * 检查是否未支付宝浏览器
     */
    function isZfb(){
        //return /AlipayClient/.test(window.navigator.userAgent);
    }

    /**
     * 获取地址栏参数
     * @param pramsName
     * @returns {string|boolean}
     */
    function getQueryVariable(pramsName)
    {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        for (let i=0;i<vars.length;i++) {
            let pair = vars[i].split("=");
            if(pair[0] === pramsName){return pair[1];}
        }
        return false;
    }
</script>
</html>