钉钉H5微应用--免登

用到VUE与钉钉H5微应用实现免登陆:

引入钉钉与接口:

import * as dd from 'dingtalk-jsapi'
import { login as loginUrl } from '../api/login'

新建方法:

export function login() {
  return new Promise((resolve, reject) => {
    dd.ready(function () {
      dd.runtime.permission.requestAuthCode({
        corpId: 'dingdbcd84596436b4d535c2f4657eb6378f',
        onSuccess: function (result) {
          /* {
              code: 'hYLK98jkf0m' //string authCode
          } */
          // console.log(result)
          loginUrl(result.code).then(val => {
            if (val.code === 200) {
              resolve(val.data)
            }
          })
        },
        onFail: function (_err) {
          resolve('164636245023643942')
        }

      })
    })
  })
}

你可能感兴趣的:(随笔)