开发浙政钉小程序步骤:
开发单位申请专有钉钉账户,前后端工程运行在自建服务器。 登录专有钉钉管理后台,创建一条小程序信息, 将登录连接配置到改配置列表中。
关于api:
H5移动端,使用的方法分两种,一种是H5的方法,一种是专有钉的官方提供api。 使用官方的jsapi, 又分为是否需要授权。 例如读取相册 不需要鉴权。 读取当前地理位置,需要鉴权。
鉴权方式:
专有钉开放平台
举例: 使用需要鉴权的获取地理位置api
对于一些政务钉钉业务相关、安全相关的 JSAPI 的调用,需要先进行鉴权然后再调用。
示例代码
dd.authConfig({
ticket: "jsApi_***********e2943c71",
jsApiList:["alert","showOnMap","需要鉴权的jsapi方法名等"]
}).then(res =>{
console.log(res)
}).
catch(err =>{})
获取地理位置
中文名:获取地理位置
接口名:getGeolocation
所在目录:设备
使用说明
用法DEMO
dd.getGeolocation({
targetAccuracy : 100,
coordinate : 0,
withReGeocode : false,
useCache:true, //默认是true,如果需要频繁获取地理位置,请设置false
}).then(res => {
console.log(res)
}).catch(err => {})
返回示例
{
“address”: “浙江省杭州市余杭区五常街道乐佳国际”,
“city”: “杭州市”,
“longitude”: 120.00881781684028,
“district”: “余杭区”,
“road”: “良睦路”,
“netType”: “WiFi”,
“operatorType”: “中国联通”,
“latitude”: 30.279671223958335,
“accuracy”: 65,
“province”: “浙江省”
}
最终使用代码
// 获取钉钉授权码
getTicket() {
let _this = this;
this.$axios
.get("/auth/ticket")
.then((res) => {
let code = res.data.code;
if (code === 200) {
this.test = res;
let ticket = res.data.data;
//01 获取鉴权码
// 02 鉴权
dd.authConfig({
ticket: "jsApi_************2943c71",
jsApiList: ["alert", "showOnMap", "需要鉴权的jsapi方法名等"],
})
.then((res) => {
console.log(res);
// 03 判断鉴权结果后,使用获取地理位置
dd.getGeolocation({
targetAccuracy: 100,
coordinate: 0,
withReGeocode: false,
useCache: true, //默认是true,如果需要频繁获取地理位置,请设置false
}).then((res) => {
console.log(res);
_this.dd = res;
})
.catch((err) => {});
})
.catch((err) => {});
console.log(res);
}
})
.catch((error) => {
console.log(error);
});
},