This commit is contained in:
kf_wuhao 2021-01-13 16:41:26 +08:00
parent 4eede17edd
commit 1b3127331e

View File

@ -6,10 +6,18 @@ import base64
import requests import requests
from db import get_local_db
__all__ = ('ddsend_msg',)
local_db = get_local_db('admin_game')
dd_conf = local_db['game'].find_one() or {}
def get_sign(): def get_sign():
timestamp = str(round(time.time() * 1000)) timestamp = str(round(time.time() * 1000))
secret = 'SEC8de0abcb83a3c387fb168995be58913f6e5fcc3612a02686fcc9107d25809930' secret = dd_conf.get('dd_secret') or 'SEC8de0abcb83a3c387fb168995be58913f6e5fcc3612a02686fcc9107d25809930'
secret_enc = secret.encode('utf-8') secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret) string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8') string_to_sign_enc = string_to_sign.encode('utf-8')
@ -26,7 +34,9 @@ def ddsend_msg(msg):
} }
} }
timestamp, sign = get_sign() timestamp, sign = get_sign()
url = f'https://oapi.dingtalk.com/robot/send?access_token=9d620df1653de39f28bf6b059e0fff9978ede3185645e4917c52d754a050b458&timestamp={timestamp}&sign={sign}' webhook = dd_conf.get('dd_webhook') or 'https://oapi.dingtalk.com/robot/send?access_token' \
'=9d620df1653de39f28bf6b059e0fff9978ede3185645e4917c52d754a050b458 '
url = f'{webhook}&timestamp={timestamp}&sign={sign}'
resp = requests.post(url, json=data) resp = requests.post(url, json=data)