钉钉机器人

2017-12-02  本文已影响0人  我的那份执着

                                                                                    python钉钉机器人

#https://oapi.dingtalk.com/robot/send?access_token=44bc5ff528efef7c16cbafc45cfa32cfe990ff62315f34da2d3f335d1c4218e7

#conding:utf-8

import json

import urllib2

# 1.构建urls

url = "https://oapi.dingtalk.com/robot/send?access_token=44bc5ff528efef7c16cbafc45cfa32cfe990ff62315f34da2d3f335d1c4218e7"

# 2.构建查一下请求的头部

header = {

"Content-Type":"application/json",#

"Charset":"utf-8"

}

#3.构建我们请求的数据

data = {

"msgtype":"text",

"text":{

"content":"hello world"# hello world 可以换成任意消息

},

"at":{

"atMobiles":[17355451057]# (at我自己)

#"isAtAll":True#(at所有人)

}

}

#4.对请求的数据进行json封装

sendData = json.dumps(data)#讲字典类型的数据转换为json格式

#5.发送请求

request = urllib2.Request(url,data = sendData,headers = header)#我们发起请求

#6.将请求返回的数据构建成为文件格式

opener = urllib2.urlopen(request)

#7.打印我们返回的结果

print(opener.read())

上一篇下一篇

猜你喜欢

热点阅读