钉钉自定义机器人开发

前言 

关于钉钉自定义机器人的开发流程,其官网有全面的解释,就不作赘述,我仅说明一下我发信的问题。章节地址如下:

https://ding-doc.dingtalk.com/document#/org-dev-guide/qf2nxq

测试机器人发送消息

其官网中介绍了三种测试发送消息的方法。分别是curl 、Java程序、PHP程序、Python程序、.NET程序。前面三种有详细的说明,后面两种在SDK环境配置章节的 SDK请求示例 中有简要的说明。

不过其curl的访问方式似乎并没有用,我尝试过修改但都没有成功,希望有请求成功的大佬发表一下看法。

其他方式都需要添加对应的依赖,添加依赖的说明(SDK环境配置章节)地址如下:

https://ding-doc.dingtalk.com/doc#/faquestions/vzbp02

AJAX测试发送消息

在此,补充一下通过JQuery 的 ajax()发送机器人消息的方法。需要说明,该方法需要浏览器是跨域的,不然会报错。完整的HTML页面代码如下。

<!DOCTYPE html>
<html>
<head>
    <title>ajax发送钉钉消息</title>
	<script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
	<script>
		$(function(){
			console.log("=== start ===");
			$.ajax({
				url:'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx',
				type:"POST",
				beforeSend:function (xhr){
					xhr.setRequestHeader('Content-Type', 'application/json');
				},
				data:JSON.stringify({"msgtype": "text","text": {"content": "Hello World! ---大话家"}}), 
				success:function (res){
					console.log("=== success ===");
					console.log(res); 
				},
				error:function (err){
					console.log("=== error ===");
					console.log(err); 
				}
			});
		});
		console.log("=== end ===");
</script>
</head>
<body>
<h1>钉钉机器人消息发送中。。。</h1>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_41057885/article/details/109214804