MrShi
2025-09-29 7bc9c5f7432a9533a0b552c40fb63fc07de5b5fe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import * as dd from 'dingtalk-jsapi';
export function getCode(callback) {
    let corpId = 'dingb14b7554444efe0a';
    console.log(dd.env.platform)
    if (dd.env.platform !== "notInDingTalk") {
        dd.ready(() => {
            //使用SDK 获取免登授权码
            dd.runtime.permission.requestAuthCode({
                corpId: corpId,
                onSuccess: (info) => {
                    // 根据钉钉提供的api 获得code后,再次调用这个callback方法
                    // 由于是钉钉获取code是异步操作,不知道什么时候执行完毕
                    // callback 函数会等他执行完毕后在自己调用自己
                    callback(info.code)
                },
                onFail: (err) => {
                    alert('fail');
                    alert(JSON.stringify(err));
                },
            });
        });
    }
}