xiaoyong931011
2021-04-12 a13a93a493e7e94e28b2225c26e7e13b52d3288c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <!-- 启用360浏览器的极速模式(webkit) -->
    <meta name="renderer" content="webkit">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>钉钉授权</title>
    <h1>你的钉钉ID是:<span id="dd"></span></h1>
 
    <button  >发送测试消息</button>
 
</head>
 
<body>
 
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.10.3/dingtalk.open.js"></script>
 
<script>
 
 
        $("button").click(function(){
            $.get(basePath+"/dingding/sendOAMsg/"+ $("#dd").html(),function(data,status){
                alert(status);
            });
        });
 
 
 
    function getRootPath() {
        var curWwwPath = window.document.location.href;
        console.log(curWwwPath);
        var pathName = window.document.location.pathname;
        var url = curWwwPath.substring(0, curWwwPath.indexOf(pathName));
        return url;
    }
 
    /** 全局路径,代表当前网站的根URL */
    basePath = getRootPath();
    dd.ready(function () {
        $.post(basePath + "/dingding/getDingdingConfig", function (data, status) {
 
            var config = data.mapInfo;
 
 
            dd.config({
                agentId: config.agentId, // 必填,微应用ID
                corpId: config.corpId,//必填,企业ID
                timeStamp: config.timeStamp, // 必填,生成签名的时间戳
                nonceStr: config.nonceStr, // 必填,生成签名的随机串
                signature: config.signature, // 必填,签名
                type: 1,   //选填。0表示微应用的jsapi,1表示服务窗的jsapi;不填默认为0。该参数从dingtalk.js的0.8.3版本开始支持
                jsApiList: [
                    'runtime.info',
                    'biz.contact.choose',
                    'device.notification.confirm',
                    'device.notification.alert',
                    'device.notification.prompt',
                    'biz.ding.post',
                    'biz.util.openLink',
                ]
            });
 
 
            dd.runtime.permission.requestAuthCode({
                corpId: config.corpId, // 企业id
                onSuccess: function (info) {
                    code = info.code // 通过该免登授权码可以获取用户身份
                    $.post(basePath + "/dingding/getDdUserId/"+code, function (data, status) {
 
                        $("#dd").html(data.info);
                    });
 
 
                },
                onFail: function (info) {
                    alert(info);
                }
 
            });
        });
 
 
    });
 
 
</script>
 
 
</html>