<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <title>钉钉授权</title>

        <script type="text/javascript" src="https://g.alicdn.com/dingding/open-develop/1.6.9/dingtalk.js"></script>
        <script type="text/javascript" src="https://g.alicdn.com/dingding/dingtalk-pc-api/2.7.0/index.js"></script>
        <script src="/js/jquery.min.js"></script>
        <script type="text/javascript">
            var _config = <?php echo $auth_config; ?>;
			var ding;
		function echo(){
                        ding.runtime.permission.requestAuthCode({
                            corpId: _config.corpId, //企业ID
                            onSuccess: function (info) {
								console.log('auth success ');
                                window.location.href = "/info.php/apps/dingding_auth/index/authOnSuccess/" +_config.agentId+'/'+_config.accessToken+'/'+ info.code;
                            },
                            onFail: function (err) {
                                console.log(JSON.stringify(err));
                            }

                        });
		}
            var DingTalk = DingTalk || {};
            (function (dt) {
                var self = dt;
                

                dt.init = function () {
                    dt.isMobileClient = self.util.isMobileClient();
                    ding = self.isMobileClient ? dd : DingTalkPC;
                };

                dt.auth = function () {
                    ding.config({
                        agentId: _config.agentId,
                        corpId: _config.corpId,
                        timeStamp: _config.timeStamp,
                        nonceStr: _config.nonceStr,
                        signature: _config.signature,
                        jsApiList: [
                            'runtime.permission.requestAuthCode',
                            'device.notification.alert',
                            'device.notification.confirm',
                            'biz.contact.choose',
                            'device.notification.prompt',
                            'biz.ding.post'
                        ] // 必填，需要使用的jsapi列表
                    });

                    ding.userid = 0;

                    ding.ready(echo());

                    ding.error(function (error) {
                        console.log('dd error: ' + JSON.stringify(error));
                    });
                };

                dt.util = {
                    isMobileClient: function () {
                        return /(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i.test(navigator.userAgent);
                    }
                };
                window.DingTalk = dt;
            })(DingTalk);
            DingTalk.init();

            DingTalk.auth();

        </script>
    </head>
    <body>
        <div>
            <p class="text-center">授权登录中，请稍候...</p>
        </div>
    </body>
</html>
