激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - python使用自定義釘釘機器人的示例代碼

python使用自定義釘釘機器人的示例代碼

2020-06-24 10:55bibibabibobi k Python

這篇文章主要介紹了python使用自定義釘釘機器人,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1.添加自定義機器人

python使用自定義釘釘機器人的示例代碼

python使用自定義釘釘機器人的示例代碼

2.編寫python代碼請求釘釘機器人所給的webhook

釘釘自定義機器人官方文檔

安全方式使用加簽的方式:

第一步,把timestamp+"\n"+密鑰當做簽名字符串,使用HmacSHA256算法計算簽名,然后進行Base64 encode,最后再把簽名參數再進行urlEncode,得到最終的簽名(需要使用UTF-8字符集)。

 

參數

說明

timestamp

當前時間戳,單位是毫秒,與請求調用時間誤差不能超過1小時

secret

密鑰,機器人安全設置頁面,加簽一欄下面顯示的SEC開頭的字符串

 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import requests
 
 
#python 3.8
import time
import hmac
import hashlib
import base64
import urllib.parse
 
timestamp = str(round(time.time() * 1000))
secret = '加簽時生成的密鑰'
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
print(timestamp)
print(sign)

第二步,把 timestamp和第一步得到的簽名值拼接到URL中。

 

參數

說明

timestamp

第一步使用到的時間戳

sign

第一步得到的簽名值

 

https://oapi.dingtalk.com/robot/send?access_token=XXXXXX&timestamp=XXX&sign=XXX

第三步,發送請求

?
1
2
3
4
5
6
7
8
9
10
11
12
13
url='生成的Webhook&timestamp={}&sign={}'.format(timestamp, sign)
 
 
print (url)
headers={
  'Content-Type':'application/json'
}
json={"msgtype": "text",
  "text": {
    "content": "888"
  } }
resp=requests.post(url=url,headers=headers,json=json)
print (resp.text)

結果:

python使用自定義釘釘機器人的示例代碼

整體代碼:

?
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
import requests
 
 
#python 3.8
import time
import hmac
import hashlib
import base64
import urllib.parse
 
timestamp = str(round(time.time() * 1000))
secret = '加簽時生成的密鑰'
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
print(timestamp)
print(sign)
 
 
url='生成的Webhook&timestamp={}&sign={}'.format(timestamp, sign)
 
 
print (url)
headers={
  'Content-Type':'application/json'
}
json={"msgtype": "text",
  "text": {
    "content": "測試"
  } }
resp=requests.post(url=url,headers=headers,json=json)
print (resp.text)

到此這篇關于python使用自定義釘釘機器人的示例代碼的文章就介紹到這了,更多相關python 自定義釘釘機器人內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!

原文鏈接:https://blog.csdn.net/u011444756/article/details/106857863

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 99999久久久久久 | www日韩在线 | 91快色视频 | 久久手机在线视频 | 二区视频 | 国产在线观看91精品 | 欧美在线一级 | 日韩黄色一级视频 | 欧美成人高清视频 | 久久成人视屏 | 成人黄色小视频在线观看 | 91九色视频在线播放 | 视频一区二区三区在线播放 | 看一级毛片 | 国产91在线高潮白浆在线观看 | 黄色网址免费入口 | 日本aaaa片毛片免费观看视频 | 国产chinesehd精品91| 成人三级电影网站 | 高清视频91 | 亚洲国产精久久久久久久 | 91 在线观看| 色猫av| 国产91影院| 国产男女 爽爽爽爽视频 | 激情毛片 | 毛片毛片免费看 | 日韩精品一区二 | 羞羞视频免费网站日本动漫 | 亚洲一区二区三区在线免费观看 | 国产又粗又爽又深的免费视频 | 在线免费观看欧美 | 成人区一区二区三区 | 免费性爱视频 | 欧美成人一区免费视频 | hd欧美free性xxxx护土 | 毛片在线免费视频 | 九九精品在线观看视频 | 亚洲免费资源 | 黄色av一区二区三区 | 一本色道精品久久一区二区三区 |