ding 模块
dingding 模块概述
本模块封装了钉钉的分享功能
android签名 下载签名工具并安装,打开然后输入应用的包名,即可生成该应用的签名
模块使用攻略
使用之前须从钉钉开放平台申请开发者账号并创建应用,获取 appid
钉钉平台接入流程参考钉钉平台接入文档
- 配置示例:
<feature name="dingding"> <param name="appID" value="bf1acab2de4925b9cd624819" /> <param name="urlScheme" value="bf1acab2de4925b9cd624819" /> <param name="urlScheme" value="dingoak5hqhuvmpfhpnjvt" /></feature>
注意:
1, iOS 平台上必须添加白名单,如下:
<preference name="querySchemes" value="dingtalk,dingtalk-open,dingtalk-sso" />
步骤:使用前需要下载你的应用 ,安装 签名工具 输入你得应用的 包名 会生成签名
然后进入钉钉开放平台创建项目 ,注意登陆的钉钉账号需创建群组才可以。
在开放平台创建项目,注意检查签名以及ios的包名
运行截图
主要代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/> <title>title</title> <link rel="stylesheet" type="text/css" href="../css/api.css"/> <style> body{ } header{ 100%; height: 400px; text-align: center; margin-top: 100px; } button{ margin-left: 10px; margin-top: 10px; 90px; height: 50px; background-color: green; color: #fff; border-radius: 5px; } </style> </head> <body> <header> <button type="button" name="button" onclick="isInstalledD()">检测</button> <button type="button" name="button" onclick="isSupportShareD()">分享支持</button> <button type="button" name="button" onclick="shareTextD()">分享文本</button> <button type="button" name="button" onclick="shareImageD()">分享图片</button> <button type="button" name="button" onclick="shareWebpageD()">分享网页</button> <button type="button" name="button" onclick="isSupportAuthD()">支持登陆</button> <button type="button" name="button" onclick="authD()">登陆</button> <button type="button" name="button" onclick="getPic()">获取图片</button> </header> </body> <script type="text/javascript" src="../script/api.js"></script> <script type="text/javascript" src="../script/sha1.js"></script> <script type="text/javascript"> var dingding = ''; var dingID = 'dingoatdfazc4egtwuuztb'; apiready = function(){ dingding = api.require('dingding'); }; function isInstalledD() { dingding.isInstalled(function(ret) { if (ret.installed) { alert("当前设备已安装钉钉客户端"); } else { alert('当前设备未安装钉钉客户端'); } }); } //是否支持分享 注意只适用Android function isSupportShareD() { var systemType = api.systemType; if (systemType == 'ios') { alert('此接口只支持Android'); }else { dingding.isSupportShare(function(ret) { if (ret.isSupport) { alert("支持钉钉分享"); } else { alert('不支持钉钉分享'); } }); } } //文本分享 function shareTextD() { console.log('-----'); dingding.shareText({ appId: dingID, text: '我分享的文本' }, function(ret, err) { if (ret.status) { alert('分享成功'); } else { alert(err.code); } }); } //图片分享 function shareImageD() { var dingding = api.require('dingding'); dingding.shareImage({ appId: dingID, contentUrl : '/storage/emulated/0/UZMap/wgt/A6026288634380/image/dog.png' //contentUrl: '/var/mobile/Containers/Data/Application/0D597BDB-D08F-4EF2-B759-D911A173A667/Documents/uzfs/wgt/A6026288634380/image/dog.png' //contentUrl: 'https://community.apicloud.com/bbs/data/attachment/block/a1/a1b8a8774d396335571edd80f1efb728.jpg' }, function(ret, err) { if (ret.status) { alert('分享成功'); } else { alert(err.code); } }); } //分享网页 function shareWebpageD() { dingding.shareWebpage({ appId: dingID, title: '测试标题', description: '分享内容的描述', thumurl: '/var/mobile/Containers/Data/Application/0D597BDB-D08F-4EF2-B759-D911A173A667/Documents/uzfs/wgt/A6026288634380/image/dog.png', //thumurl: '/storage/emulated/0/UZMap/wgt/A6026288634380/image/dog.png', //thumurl: 'https://community.apicloud.com/bbs/data/attachment/block/a1/a1b8a8774d396335571edd80f1efb728.jpg', url: 'http://apicloud.com' }, function(ret, err) { if (ret.status) { alert('分享成功'); } else { alert(err.code); } }); } //支持登陆 function isSupportAuthD() { dingding.isSupportAuth({ }, function(ret, err) { alert(JSON.stringify(ret)); }); } //登陆 function authD() { dingding.auth({ appId:dingID, state:'', }, function(ret, err) { alert(JSON.stringify(ret)); }); } //获取fs 图片 function getPic() { var fileBrowser = api.require('fileBrowser'); fileBrowser.open(function(ret) { if (ret) { console.log(JSON.stringify(ret)); alert(JSON.stringify(ret)); var str = (JSON.stringify(ret)); console.log(str); } }); } </script> </html> 复制代码