<!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> 
 |