钉钉自建应用-下载excel(h5)

由于不同手机对于文件下载有不同的支持,而且文件路径也不一样,找起来十分的麻烦。所以,最好是找到一个都支持的方法。还好,钉钉官网提供了网盘,我们可把文件保存到钉钉自带的网盘,这样方便查找。

这里需要后端返回下载文件的url地址

TypeScript 复制代码
dd.saveFileToDingTalk({
  url: 'https://ringnerippca.files.wordpress.com/20.pdf',
  name: '文件名称.pdf',
  success: (res) => {
    const { data } = res;
    dd.previewFileInDingTalk({
      corpId: '应用的corpId',
      fileId: data[0].fileId,
      spaceId: data[0].spaceId,
      fileName: data[0].fileName,
      fileSize: data[0].fileSize,
      fileType: data[0].fileType,
      success: () => {},
      fail: () => {},
      complete: () => {},
    });
  },
  fail: () => {},
  complete: () => {},
});

不过需要注意的是使用这两个api之前需要先鉴权。

TypeScript 复制代码
// 当前网页的URL,不包含#及其后面部分。
ajax(url).then((res) => {
  if (res.data.success) {
      const { agentId, timeStamp, nonceStr, signature } = res.data.content;
      dd.config({
         agentId,
         corpId: '应用的corpId',
         timeStamp,
         nonceStr,
         signature,
         type: 0,
         jsApiList: [
           'saveFileToDingTalk',
           'previewFileInDingTalk'
         ]
      });

      dd.error((err) => {
        console.log('🚀 dd.error ~ err.errorMessage',err.errorMessage);
        console.log('🚀 dd.error ~ err.url', err.url);
      }); // 该方法必须带上,用来捕获鉴权出现的异常信息,否则不方便排查出现的问题
  }
});
相关推荐
陌陌6233 天前
Clawdbot接入钉钉 / Moltbot接入钉钉
钉钉·clawdbot
Yolanda944 天前
【项目经验】钉钉免密登录实现
前端·javascript·钉钉
Yolanda944 天前
【教程技巧】钉钉自定义机器人新建及url获取流程
机器人·钉钉
gjxDaniel7 天前
钉钉是什么?
钉钉·生活
AITOP1009 天前
钉钉8.2.5版本上线 “AI 差旅”,携手高德支付宝实现智能比价与免垫资
钉钉·钉钉ai差旅·aitop100
光锥智能10 天前
飞书钉钉AI硬件争夺战:录音背后的入口之争
人工智能·钉钉·飞书
kkoral10 天前
【FFmpeg 智慧园区场景应用】5.企业微信 / 钉钉告警一键切换脚本(含静默周期 + 恢复通知)
ffmpeg·钉钉·企业微信
kkoral10 天前
【FFmpeg 智慧园区场景应用】4.企业微信 / 钉钉机器人告警配置(替换邮件告警)
ffmpeg·钉钉·企业微信
季布,12 天前
本地Windows测试:钉钉群消息/文件传输到Python服务(完整教程)
windows·python·钉钉
右手 无名指14 天前
Github Actions工作流配置webhook推送到钉钉机器人
机器人·github·钉钉