当前位置:   article > 正文

专有钉钉H5小程序开发- 使用jsapi_dd.authconfig

dd.authconfig

开发浙政钉小程序步骤:

开发单位申请专有钉钉账户,前后端工程运行在自建服务器。 登录专有钉钉管理后台,创建一条小程序信息, 将登录连接配置到改配置列表中。

关于api:

H5移动端,使用的方法分两种,一种是H5的方法,一种是专有钉的官方提供api。 使用官方的jsapi, 又分为是否需要授权。 例如读取相册 不需要鉴权。 读取当前地理位置,需要鉴权。
鉴权方式:
专有钉开放平台
在这里插入图片描述
举例: 使用需要鉴权的获取地理位置api
对于一些政务钉钉业务相关、安全相关的 JSAPI 的调用,需要先进行鉴权然后再调用。
在这里插入图片描述
示例代码

dd.authConfig({
    ticket: "jsApi_***********e2943c71",
    jsApiList:["alert","showOnMap","需要鉴权的jsapi方法名等"]
}).then(res =>{
    console.log(res)
}).
catch(err =>{})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

获取地理位置
中文名:获取地理位置

接口名:getGeolocation

所在目录:设备

使用说明
在这里插入图片描述
用法DEMO

dd.getGeolocation({
    targetAccuracy : 100,
    coordinate : 0,
    withReGeocode : false,
    useCache:true, //默认是true,如果需要频繁获取地理位置,请设置false
}).then(res => {
    console.log(res)
}).catch(err => {})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

返回示例

{
“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);
        });
    },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/247967
推荐阅读
相关标签
  

闽ICP备14008679号