开发者社区> 问答> 正文

获取 code失败,免登无法实现

$.ajax({
    url : '/dingdingConsumer/dingTalkCommon/getUserInfo',
    type : 'GET',
    success : function(data, status, xhr) {
        var info = JSON.parse(data);
    },
    error : function(xhr, errorType, error) {
        logger.e("yinyien:" + _config.corpId);
        alert(errorType + ', ' + error);
    }
});
dd.config({
            agentId : _config.agentid,
            corpId : _config.corpId,
            timeStamp : _config.timeStamp,
            nonceStr : _config.nonceStr,
            signature : _config.signature,
            jsApiList : [ 'runtime.info', 'biz.contact.choose',
                    'device.notification.confirm', 'device.notification.alert',
                    'device.notification.prompt', 'biz.ding.post',
                    'biz.util.openLink' ]
        });

dd.ready(function() {    
    dd.biz.navigation.setTitle({
        title: '钉钉demo',
        onSuccess: function(data) {
            alert('dd.ready rocks!');
        },
        onFail: function(err) {
            log.e(JSON.stringify(err));
        }
    });
     alert('dd.ready rocks!');
    
    dd.runtime.info({
        onSuccess : function(info) {
            logger.e('runtime info: ' + JSON.stringify(info));
        },
        onFail : function(err) {
            logger.e('fail: ' + JSON.stringify(err));
        }
    });
    dd.runtime.permission.requestAuthCode({
        corpId : _config.corpId,
        onSuccess : function(info) {
            alert('authcode: ' + info.code);
            $.ajax({
                url : '/dingdingConsumer/dingTalkCommon/getAccessToken',
                type : 'GET',
                success : function(data, status, xhr) {
                    alert("accessToken"+data);
                    $.ajax({
                        url : 'https://oapi.dingtalk.com/user/getuserinfo?access_token='+data+'&code=' + info.code,
                        type : 'GET',
                        success : function(data, status, xhr) {
                            var info = JSON.parse(data);
        
                            document.getElementById("userInfo").innerHTML = info;
                            document.getElementById("userName").innerHTML = info.name;
                            document.getElementById("userId").innerHTML = info.userid;
                            
                            // 图片
        //                    if(info.avatar.length != 0){
        //                        var img = document.getElementById("userImg");
        //                        img.src = info.avatar;
        //                                  img.height = '100';
        //                                  img.width = '100';
        //                      }
        
                        },
                        error : function(xhr, errorType, error) {
                            logger.e("yinyien:" + _config.corpId);
                            alert(errorType + ', ' + error);
                        }
                    });
                }
                ,
                error : function(xhr, errorType, error) {
                    logger.e("yinyien:" + _config.corpId);
                    alert(errorType + ', ' + error);
                }
            });
        },
        onFail : function(err) {
            alert('fail: ' + JSON.stringify(err));
        }
    });
    dd.ui.pullToRefresh.enable({
        onSuccess: function() {
        },
        onFail: function() {
        }
    })

    dd.biz.navigation.setMenu({
        backgroundColor : "#ADD8E6",
        items : [
            {
                id:"此处可以设置帮助",//字符串
            // "iconId":"file",//字符串,图标命名
              text:"帮助"
            }
            ,
            {
                "id":"2",
            "iconId":"photo",
              "text":"我们"
            }
            ,
            {
                "id":"3",
            "iconId":"file",
              "text":"你们"
            }
            ,
            {
                "id":"4",
            "iconId":"time",
              "text":"他们"
            }
        ],
        onSuccess: function(data) {
            alert(JSON.stringify(data));

        },
        onFail: function(err) {
            alert(JSON.stringify(err));
        }
    });


    
});

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

展开
收起
jerrysbest 2016-07-31 20:45:11 5299 0
3 条回答
写回答
取消 提交回答
  • 临时授权码只有一次有效,所以不能重用临时授权码,你重新请求,用新的临时授权码就能解决问题
    2016-08-01 20:12:01
    赞同 展开评论 打赏
  • 回 1楼jerrysbest的帖子
    我也遇到同样的问题,如果解决请分享解决方法,谢谢
    2016-08-01 15:26:30
    赞同 展开评论 打赏
  • Re获取 code失败,免登无法实现
    手机上报错信息: error:{message:权限效验失败 code:52013 -message:签名效验失败,errorCode:3}

    -------------------------

    Re获取 code失败,免登无法实现
    上面的问题是因为 前台和后台URL不一致所致.
    上面的问题解决了,又出现了新问题:返回{"errcode":40078,"errmsg":"不存在的临时授权码"}该怎么解决?
    2016-07-31 20:52:05
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

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