import json
import requests
import random
def func():
name = input("输入你的大名:")
age = input("输入你的年龄:")
rdm = random.randint(18, 50)
if int(age) > rdm:
r='你好,{}。我比你小,我{}岁了。'.format(name,rdm)
elif int(age) < rdm:
r='你好,{}。我比你大,我{}岁了。'.format(name,rdm)
else:
r='你好,{}。我和你一样大,我也{}岁。'.format(name,rdm)
return r
def dingmessage():
webhook = "https://oapi.dingtalk.com/robot/send?access_token=fc36f1679e44ee1dceb4177956e61cea9cf1d8b7cb3192572efb0837ae71f67c"
header = {
"Content-Type":"application/json",
"Charset":"UTF-8"
}
tex=func()
message ={
"msgtype": "text",
"text": {
"content": tex
},
"at": {
"isAtALL": True
}
}
message_json =json.dumps(message)
info = requests.post(url=webhook,data=message_json,headers=header)
print(info.text)
if __name__=="__main__":
dingmessage()
Python调用钉钉机器人发消息
最新推荐文章于 2024-07-04 10:53:14 发布