欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長(zhǎng)資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          學(xué)習(xí)python使用自定義釘釘機(jī)器人的示例代碼

          學(xué)習(xí)python使用自定義釘釘機(jī)器人的示例代碼

          1.添加自定義機(jī)器人

          學(xué)習(xí)python使用自定義釘釘機(jī)器人的示例代碼

          學(xué)習(xí)python使用自定義釘釘機(jī)器人的示例代碼

          相關(guān)學(xué)習(xí)推薦:python視頻教程

          2.編寫python代碼請(qǐng)求釘釘機(jī)器人所給的webhook

          釘釘自定義機(jī)器人官方文檔

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

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

          參數(shù)

          說明

          timestamp

          當(dāng)前時(shí)間戳,單位是毫秒,與請(qǐng)求調(diào)用時(shí)間誤差不能超過1小時(shí)

          secret

          密鑰,機(jī)器人安全設(shè)置頁(yè)面,加簽一欄下面顯示的SEC開頭的字符串

          import requests     #python 3.8 import time import hmac import hashlib import base64 import urllib.parse   timestamp = str(round(time.time() * 1000)) secret = '加簽時(shí)生成的密鑰' 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中。

          參數(shù)

          說明

          timestamp

          第一步使用到的時(shí)間戳

          sign

          第一步得到的簽名值

          第三步,發(fā)送請(qǐng)求

          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)

          結(jié)果:

          學(xué)習(xí)python使用自定義釘釘機(jī)器人的示例代碼

          整體代碼:

          import requests     #python 3.8 import time import hmac import hashlib import base64 import urllib.parse   timestamp = str(round(time.time() * 1000)) secret = '加簽時(shí)生成的密鑰' 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": "測(cè)試"  } } resp=requests.post(url=url,headers=headers,json=json) print (resp.text)

          相關(guān)學(xué)習(xí)推薦:編程視頻

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)