开发者社区> 问答> 正文

获取登录用户信息失败,提示不存在临时的授权码?


  我这样做有什么问题么?

    //获取免登授权码信息
    dd.runtime.permission.requestAuthCode({
        corpId: _config.corpId,
        onSuccess: function (info) {
            logger.i('authcode: ' + info.code);
            $.ajax({
                url: 'dingTalking/userinfo.do?code=' + info.code,
                type: 'POST',
                success: function (data, status, xhr) {
                    var info = JSON.parse(data);
                    logger.i('登录用户信息: ' + JSON.stringify(info));
                    if (info.errcode === 0) {
                        logger.i('登录用户信息: ' + JSON.stringify(info));
                    }
                    else {
                        logger.e('auth error: ' + data);
                    }
                },
                error: function (xhr, errorType, error) {
                    logger.e(errorType + ', ' + error);
                }
            });
            
        },
        onFail: function (err) {
            logger.e('fail: ' + JSON.stringify(err));
        }
    });

    /**
           后台调用的方法
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    public void doGet() throws ServletException, IOException {
        // TODO Auto-generated method stub
        String code = request.getParameter("code");
        System.out.println(code);

        try {
            String accessToken = AuthHelper.getAccessToken();
            System.out.println(UserHelper.getUserInfo(accessToken, code).toString());
            response.getWriter().append(UserHelper.getUserInfo(accessToken, code).toString());

        } catch (OApiException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            response.getWriter().append(e.getMessage());
        }
    }


展开
收起
x1ao 2016-02-18 10:07:35 9515 0
2 条回答
写回答
取消 提交回答
  • 2016-02-18 13:32:55
    赞同 展开评论 打赏
  • Re获取登录用户信息失败,提示不存在临时的授权码?
    问题已经解决。接口调用了2次导致临时授权码失效:  System.out.println(UserHelper.getUserInfo(accessToken, code).toString());
                response.getWriter().append(UserHelper.getUserInfo(accessToken, code).toString());
    2016-02-18 11:41:20
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

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