ShowEmessage.js 4.55 KB
$(document).ready(function () {
    checkE4Ready(function (htmlstr) {
        $(htmlstr).prependTo($('body'));
    });

});

function checkE4Ready(cb) {

    if (!window.ecCom) {
        console && console.log('no ecCom found')
        $.post("/social/im/SocialIMInclude.jsp", function (ret) {
            ret = $.trim(ret);
            if (ret == '') {
                console.error("!!license为空或不是e4版本!!");
                return;
            }
            if (ret.indexOf('/social/im/SocialIMMain.jsp') > -1 && typeof cb === 'function') {
                cb(ret);
            }
        });
    } else {
        window.em_checkJoin().then(function (res) {
            if (res.status &&
                res.joinStatus
            ) {
                if (res.webSwitch !== "0") {
                    var WeaTools = ecCom.WeaTools;

                    WeaTools.callApi('/api/ec/dev/app/getUserInfo', 'GET', {})
                        .then(function (res) {
                            if (!res.isAdmin) {

                                var loadjs = ecCom.WeaTools.loadjs;
                                var ec_id = ''
                                var timestamp = 0;
                                var emUrl = '';
                                var langType = 'zh';
                                var lang = localStorage['languageidweaver'];
                                var langTypeList = JSON.parse(localStorage['languageIdentify'])
                                for (var index = 0; index < langTypeList.length; index++) {
                                    var element = langTypeList[index];
                                    if (element[lang] !== undefined) {
                                        langType = element[lang];
                                    }
                                }

                                WeaTools.callApi('/api/ec/dev/app/test', 'GET', {})
                                    .then(function (res) {
                                        if (!res.status) {
                                            console.log('verify failed')
                                        }
                                        ec_id = res.ec_id
                                        timestamp = new Date().getTime();
                                        emUrl = res.em_url_open + '/open/js/client.js?_key=' + timestamp;
                                        function initEmClient(ec_id) {

                                            WeaTools.callApi('/api/ec/dev/app/getSSOCode', 'GET', {})
                                                .then(function (ssoRes) {
                                                    if (!ssoRes.status) {
                                                        console.log('get code failed');
                                                    }
                                                    emClient.ready(function () {
                                                        emClient.ecLogin({
                                                            ec_id: ec_id, //必填,EC接入EM时,在EM中的唯一标识
                                                            // ec_auth_code: JSON.parse(window.localStorage.login).loginCache.id, // 读取当前用户id测试
                                                            ec_auth_code: ssoRes.keycode, //必填,实时生成的身份认证code
                                                            lang_type: langType,
                                                        });
                                                    });
                                                }.bind(this));
                                        }
                                        loadjs.isDefined('emClient')
                                            ? loadjs.ready('emClient', initEmClient.bind(this, ec_id))
                                            : loadjs(emUrl, 'emClient', initEmClient.bind(this, ec_id));
                                    }.bind(this));
                            }
                        }.bind(this))

                }
            } else {
                $.post("/social/im/SocialIMInclude.jsp", function (ret) {
                    ret = $.trim(ret);
                    if (ret == '') {
                        console.error("!!license为空或不是e4版本!!");
                        return;
                    }
                    if (ret.indexOf('/social/im/SocialIMMain.jsp') > -1 && typeof cb === 'function') {
                        cb(ret);
                    }
                });
            }
        })
    }
}