开发者社区> 问答> 正文

jsapi不走ready方法直接走error方法



以下是源码

var log = document.createElement('div');
    log.setAttribute('id', 'log');
    document.body.appendChild(log);


    var logger = {
        i: function(info) {
            add(info, 'i');
        },
        e: function(err) {
            add(err, 'e');
        }
    };


    function add(msg, level) {
        var row = document.createElement('div');
        row.setAttribute('class', 'log-row log-' + level);
        row.innerHTML = msg;


        document.querySelector('#log').appendChild(row);
    }
    var config = {"url":"http://saas.eduto.com/User/index.php/Home/Login/dingDingIsvLogin?corpid=ding3fd3e80d89b9034435c2f4657eb6378f","nonceStr":1460,"agentId":"50407135","timeStamp":1479533426,"corpId":"ding3fd3e80d89b9034435c2f4657eb6378f","suite_key":"suitezawadsugvy0xgkwq","signature":"7262d63f9a449577c7d417e0c29892d767f31b2c"};
    dd.config({
        agentId:config.agentId,
        corpId: config.corpId,
        timeStamp: config.timeStamp,
        nonceStr: config.nonceStr,
        signature: config.signature,
        jsApiList: [
            'runtime.info',
            'device.notification.prompt',
            'biz.chat.pickConversation',
            'device.notification.confirm',
            'device.notification.alert',
            'device.notification.prompt',
            'biz.chat.open',
            'biz.util.open',
            'biz.user.get',
            'biz.contact.choose',
            'biz.telephone.call',
            'biz.util.uploadImage',
            'biz.ding.post']
    });
    dd.userid=0;
    dd.ready(function() {
        logger.i('dd.ready rocks!');


        dd.runtime.info({
            onSuccess: function(info) {
                logger.i('runtime info: ' + JSON.stringify(info));
            },
            onFail: function(err) {
                logger.e('fail: ' + JSON.stringify(err));
            }
        });


        dd.runtime.permission.requestAuthCode({
            corpId: _config.corpId, //企业id
            onSuccess: function (info) {
                logger.i('authcode: ' + info.code);
                $.ajax({
                    url: '/sendMsg.php',
                    type:"POST",
                    data: {"event":"get_userinfo","code":info.code,"corpId":_config.corpId},
                    dataType:'json',
                    timeout: 900,
                    success: function (data, status, xhr) {
                        var info = JSON.parse(data);
                        if (info.errcode === 0) {
                            logger.i('user id: ' + info.userid);
                            dd.userid = info.userid;
                        }
                        else {
                            logger.e('auth error: ' + data);
                        }
                    },
                    error: function (xhr, errorType, error) {
                        logger.e(errorType + ', ' + error);
                    }
                });
            },
            onFail: function (err) {
                logger.e('requestAuthCode fail: ' + JSON.stringify(err));
            }
        });


        $('.chooseonebtn').on('click', function() {


            dd.biz.chat.pickConversation({
                corpId: _config.corpId, //企业id
                isConfirm:'false', //是否弹出确认窗口,默认为true
                onSuccess: function (data) {
                    var chatinfo = data;
                    if(chatinfo){
                    console.log(chatinfo.cid);
                        dd.device.notification.prompt({
                            message: "发送消息",
                            title: chatinfo.title,
                            buttonLabels: ['发送', '取消'],
                            onSuccess : function(result) {
                                var text = result.value;
                                if(text==''){
                                    return false;
                                }


                                $.ajax({
                                    url: '/sendMsg.php',
                                    type:"POST",
                                    data: {"event":"send_to_conversation","cid":chatinfo.cid,"sender":dd.userid,"content":text,"corpId":_config.corpId},
                                    dataType:'json',
                                    timeout: 900,
                                    success: function (data, status, xhr) {
                                        var info = data;
                                        logger.i('sendMsg: ' + JSON.stringify(data));
                                        if(info.errcode==0){
                                            logger.i('sendMsg: 发送成功');
                                            /**
                                             * 跳转到对话界面
                                             */
                                            dd.biz.chat.open({
                                                cid:chatinfo.cid,
                                                onSuccess : function(result) {
                                                },
                                                onFail : function(err) {}
                                            });
                                        }else{
                                            logger.e('sendMsg: 发送失败'+info.errmsg);
                                        }
                                    },
                                    error: function (xhr, errorType, error) {
                                        logger.e(errorType + ', ' + error);
                                    }
                                });
                            },
                            onFail : function(err) {}
                        });
                    }
                },
                onFail: function (err) {
                }
            });
        });


        $('.phonecall').on('click', function() {
            dd.biz.contact.choose({
                startWithDepartmentId: 0, //-1表示打开的通讯录从自己所在部门开始展示, 0表示从企业最上层开始,(其他数字表示从该部门开始:暂时不支持)
                multiple: false, //是否多选: true多选 false单选; 默认true
                users: [], //默认选中的用户列表,userid;成功回调中应包含该信息
                corpId: _config.corpId, //企业id
                max: 10, //人数限制,当multiple为true才生效,可选范围1-1500
                onSuccess: function(data) {
                    if(data&&data.length>0){
                        var selectUserId = data[0].emplId;
                        if(selectUserId>0){
                            dd.biz.telephone.call({
                                users: [selectUserId], //用户列表,工号
                                corpId: _config.corpId, //企业id
                                onSuccess : function(info) {
                                    logger.i('biz.telephone.call: info' + JSON.stringify(info));


                                },
                                onFail : function(err) {
                                    logger.e('biz.telephone.call: error' + JSON.stringify(err));
                                }
                            })
                        }else{
                            return false;
                        }
                    }else{
                        return false;
                    }
            },
            onFail : function(err) {}
        });
        });
    });


    dd.error(function(err) {
        logger.e('dd error: ' + JSON.stringify(err));
    });


直接走error报错:dd error:{"message":"权限校验失败 Code:0-Message:","errorCode":3}是在没找出原因

展开
收起
祥子的家 2016-11-19 13:38:40 3327 0
1 条回答
写回答
取消 提交回答
  • 请参考这个文档:https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.lBpkDZ&treeId=171&articleId=104910&docType=1

    dd.error(function(error){
           /**
            {
               message:"错误信息",//message信息会展示出钉钉服务端生成签名使用的参数,请和您生成签名的参数作对比,找出错误的参数
               errorCode:"错误码"
            }
           **/
           alert('dd error: ' + JSON.stringify(err));
    });
    2016-11-21 18:50:14
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载