开发者社区> 问答> 正文

钉钉企业第三方应用,JSAPI鉴权无效的agentid

开发第三方企业应用,需要调用 选人和部门 的JSAPI,发现报错

{
  errorCode : "7",
  errorMessage: "API not authed"
}

然后我就想到了没鉴权,然后开始做鉴权,但dd.config一直不通过

前端控制台报错信息如下

{
  errorCode : "9",
  errorMessage : "无效的agentid"
}

####因为不是企业内部应用,所以没有agentId,我使用了suiteId来替代agentId(使用过了appId suiteKey仍然报无效的agentid)

后台接口的主要实现逻辑(/ding-service/jsapi-auth/{corpId})
        //获取Ticket
        TimeoutDataVo jsApiTicketData = getJsApiTicket(corpId);
        if (jsApiTicketData==null) { return null; }
        String ticket = jsApiTicketData.getData().toString();
        long curDate = System.currentTimeMillis();
        // 获取签名,随机串暂时采用corpId
        String sign = DingTalkUtils.sign(ticket, corpId, curDate, currentUrl);
        // 返回鉴权所需信息
        return new JsApiAuthInfoVo()
                .setCorpId(corpId)
                .setAgentId(suiteId)
                .setNonceStr(corpId)
                .setSignature(sign)
                .setType(0)
                .setJsApiList(new ArrayUtils.MyList<String>()
                        .chainAdd("runtime.info",
                                /* PC端选择企业内部的人 Android iOS PC */
                                "biz.contact.choose",
                                /* confirm 框 Android iOS PC */
                                "device.notification.confirm",
                                /* alert 框 Android iOS PC */
                                "device.notification.alert",
                                /* prompt 框 Android iOS PC */
                                "device.notification.prompt",
                                /* DING 1.0发钉 PC */
                                "biz.ding.post",
                                /* 在新窗口上打开链接 Android iOS PC */
                                "biz.util.openLink",
                                /* 选人和部门 */
                                "biz.contact.complexPicker"
                                        ))
                .setTimeStamp(curDate);

前端VueJs代码
// ======== JSAPI 鉴权 ======
export const authJsApi = corpId => {
    return new Promise((resolve, reject) => {
        axios.request({
            url: `/ding-service/jsapi-auth/${corpId}`,
            method: 'get',
        }).then(res=> {
            let { agentId, timeStamp, nonceStr, signature, type, jsApiList } = res.data;
            console.log(agentId)

            dd.config({ agentId, corpId, timeStamp, nonceStr, signature, jsApiList, type, });

            resolve()
        }).catch(err=> reject(err) );
    });
}

展开
收起
游客r2qczggrmv2qs 2020-09-10 16:43:58 4916 0
1 条回答
写回答
取消 提交回答
  • 已解决, 钉钉第三方企业内部微应用,鉴权方式agentId换成appId, 官方文档中并没有说明,有点坑。

    // ======== JSAPI 鉴权 ======
    export const authJsApi = corpId => {
    
        return new Promise((resolve, reject) => {
            axios.request({
                url: `/ding-service/jsapi-auth/${corpId}`,
                method: 'get',
            }).then(res=> {
                let { agentId, timeStamp, nonceStr, signature, type, jsApiList } = res.data;
                console.log(agentId)
                dd.ready(()=>{
                    dd.config({ appId:agentId, corpId, timeStamp, nonceStr, signature, jsApiList:['biz.contact.complexPicker'], type: 0, });
                })
                
                resolve()
            }).catch(err=> reject(err) );
        });
    }
    
    
    2020-09-11 17:03:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
钉钉小程序——为工作方式插上翅膀 立即下载
钉钉客户端自动化的应用 立即下载
使命必达 —— 钉钉企业级 消息服务的机遇与挑战 立即下载