当前位置:网站首页>钉钉企业内部-H5微应用开发
钉钉企业内部-H5微应用开发
2022-07-31 05:17:00 【Forevermoremo】
前言
公司需利用钉钉相关API完成公司内部报销平台。
项目搭建
- 创建H5微应用
登入钉钉开放平台(https://open-dev.dingtalk.com/#/index),进入“应用开发”->企业内部开发H5微应用->创建应用,并填写基本信息和配置开发信息

注意:应用首页链接:vscode需安装Liver Server插件,将首页以该方式打开,将获得的地址的IP地址替换为本机IP地址,得到应用首页链接。
2.JSAPI鉴权API开发
(1)JSAPI鉴权服务端API的开发:
①通过appKey 、appSecret 获取调用接口凭证AccessToken(https://oapi.dingtalk.com/gettoken? appkey=appKey&appsecret=appSecret)
②通过AccessToken 获取用于JSAPI的临时票据Ticket(https://oapi.dingtalk.com/get_jsapi_ticket?access_token=ACCESS_TOKEN)
后端详细的就不写了,感兴趣可以看看钉钉服务端API开发文档
(2)JSAPI鉴权前端API的开发:
前端通过发送请求获取服务端的JSAPI 鉴权配置信息。
if (!localStorage.getItem('sessionId')) {
console.log("鉴权开始");
//应用首页链接
var datas = { "url": "http://192.168.0.66:5500/html/index.html" };
apiRequest('post', 'ding_talk/config', datas, function (data) {
_config = data.row;
dd.config({
agentId: _config.agentId, // 必填,微应用ID
corpId: _config.corpId,//必填,企业ID
timeStamp: _config.timeStamp, // 必填,生成签名的时间戳
nonceStr: _config.nonceStr, // 必填,生成签名的随机串
signature: _config.signature, // 必填,签名
type: 0, //选填。0表示微应用的jsapi,1表示服务窗的jsapi;不填默认为0。
该参数从dingtalk.js的0.8.3版本开始支持
jsApiList: []
});
dd.ready(function () {
console.log('鉴权成功');
//登录
});
dd.error(function (err) {
window.localStorage.setItem("sessionId", '');
console.log('dd error: ' + JSON.stringify(err));
});
}, function (res) {
dd.error(function (err) {
console.log('dd error: ' + JSON.stringify(err));
});
console.log(res);
});
}(3)H5微应用免登(用户自动登录应用)
后端得到免登授权码后,通过服务端API(/user/getuserinfo)获取用户信息后返回。
dd.runtime.permission.requestAuthCode({
corpId: _config.corpId, // 企业id
onSuccess: function (info) {
code = info.code; // 通过该免登授权码可以获取用户身份信息
//登录
apiRequest('post', 'ding_talk/login', { "code": code }, function (data) {
window.localStorage.setItem("sessionId", data.row.sessionId);
window.localStorage.setItem("userId", data.row.userId);
}, function (res) {
console.log(res);
})
},
onFail: function (res) {
window.localStorage.setItem("sessionId", '');
}
});前端详细可看看前端API开发文档
边栏推荐
- wangeditor富文本编辑器上传图片以及跨域问题解决
- 我的训练函数模板(动态修改学习率、参数初始化、优化器选择)
- Cholesterol-PEG-DBCO 胆固醇-聚乙二醇-二苯基环辛炔化学试剂
- Pytorch学习笔记7——处理多维特征的输入
- DSPE-PEG-COOH CAS: 1403744-37-5 Phospholipid-polyethylene glycol-carboxy lipid PEG conjugate
- 2021年软件测试面试题大全
- 自然语言处理相关list
- Software Testing Interview Questions 2021
- Tensorflow related list
- crontab的定时操作
猜你喜欢

化学试剂磷脂-聚乙二醇-氨基,DSPE-PEG-amine,CAS:474922-26-4

多元线性回归方程原理及其推导

Introduction to CLS-PEG-FITC Fluorescein-PEG-CLS Cholesterol-PEG-Fluorescein

Research reagents Cholesterol-PEG-Maleimide, CLS-PEG-MAL, Cholesterol-PEG-Maleimide

机器学习和深度学习概述

After unicloud is released, the applet prompts that the connection to the local debugging service failed. Please check whether the client and the host are under the same local area network.

Nmap的下载与安装

Embedding前沿了解

Cholesterol-PEG-Azide CLS-PEG-N3 胆固醇-聚乙二醇-叠氮 MW:3400

Cholesterol-PEG-Thiol CLS-PEG-SH 胆固醇-聚乙二醇-巯基
随机推荐
Software Testing Interview Questions 2021
Cholesterol-PEG-Azide CLS-PEG-N3 胆固醇-聚乙二醇-叠氮 MW:3400
Markdown help documentation
Natural language processing related list
Cholesterol-PEG-Amine CLS-PEG-NH2 Cholesterol-Polyethylene Glycol-Amino Research Use
MW: 3400 4-Arm PEG-DSPE four-arm-polyethylene glycol-phospholipid a saturated 18-carbon phospholipid
Tencent Cloud GPU Desktop Server Driver Installation
Understanding of objects and functions in js
CAS:1403744-37-5 DSPE-PEG-FA 科研实验用磷脂-聚乙二醇-叶酸
为数学而歌之伯努利家族
SSH automatic reconnection script
人脸识别AdaFace学习笔记
2021-09-30
Tensorflow——demo
Data Preprocessing, Feature Engineering, and Feature Learning - Excerpt
Navicat从本地文件中导入sql文件
sql add default constraint
MySQL 出现 The table is full 的解决方法
Cholesterol-PEG-NHS NHS-PEG-CLS 胆固醇-聚乙二醇-活性酯可修饰小分子材料
PyTorch学习笔记08——加载数据集