当前位置:网站首页>钉钉企业内部-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开发文档
边栏推荐
- Embedding前沿了解
- Software Testing Interview Questions 2021
- crontab的定时操作
- mPEG-DSPE 178744-28-0 Methoxy-polyethylene glycol-phosphatidylethanolamine linear PEG phospholipids
- DC-CDN学习笔记
- Several forms of Attribute Changer
- JS写一段代码,判断一个字符串中出现次数最多的字符串,并统计出现的次数JS
- 词向量——demo
- 如何修改数据库密码
- Multi-Modal Face Anti-Spoofing Based on Central Difference Networks学习笔记
猜你喜欢

qt:cannot open C:\Users\某某某\AppData\Local\Temp\main.obj.15576.16.jom for write

为数学而歌之伯努利家族

Understanding of js arrays

Tencent Cloud GPU Desktop Server Driver Installation

Embedding cutting-edge understanding

VS2017 connects to MYSQL

JS写一段代码,判断一个字符串中出现次数最多的字符串,并统计出现的次数JS

Tensorflow steps on the pit while using it

Numpy常用函数

Navicat从本地文件中导入sql文件
随机推荐
qt:cannot open C:\Users\某某某\AppData\Local\Temp\main.obj.15576.16.jom for write
Embedding cutting-edge understanding
浏览器查找js绑定或者监听的事件
超参数优化-摘抄
This in js points to the prototype object
SSH automatic reconnection script
MW: 3400 4-Arm PEG-DSPE four-arm-polyethylene glycol-phospholipid a saturated 18-carbon phospholipid
Pytorch实现ResNet
Cholesterol-PEG-Thiol CLS-PEG-SH Cholesterol-Polyethylene Glycol-Sulfhydryl
pytorch模型微调finetuning训练image_dog(kaggle)
crontab的定时操作
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.
ERROR Error: No module factory availabl at Object.PROJECT_CONFIG_JSON_NOT_VALID_OR_NOT_EXIST ‘Error
The browser looks for events bound or listened to by js
TransactionTemplate transaction programmatic way
Pytorch每日一练——预测泰坦尼克号船上的生存乘客
unicloud 发布后小程序提示连接本地调试服务失败,请检查客户端是否和主机在同一局域网下
Tensorflow边用边踩坑
Redis-Hash
Podspec verification dependency error problem pod lib lint , need to specify the source