icepage / AutoUpdateJdCookie

自用青龙面板辅助工具,用于自动登录JD获取许可更新青龙面板
235 stars 106 forks source link

钉钉未成功推送消息 #12

Closed deluo closed 4 months ago

deluo commented 4 months ago

is_send_msg = True

is_send_success_msg = True

is_send_fail_msg = True

send_info = { "send_wecom": [ ], "send_webhook": [ ], "send_dingtalk": [ "https://oapi.dingtalk.com/robot/send?access_token=xxxxxx" ], "send_feishu": [ ] }

已配置钉钉机器人,加签,在docker中运行正常,main.log日志也正常。 期望可以正常向钉钉推送消息,谢谢

icepage commented 4 months ago

https://github.com/icepage/AutoUpdateJdCookie/commit/cfb07e439038b2a0589077d69d5f8da556d9579d 我将发送消息后的响应内容打印出来了,希望能帮助到你

deluo commented 4 months ago

utils.tools:send_msg:318 - 发送消息到 https://oapi.dingtalk.com/robot/send?access_token=xxxxx, 响应:{'errcode': 310000, 'errmsg': 'description:机器人发送签名不匹配;solution:请确认签名和生成签名的时间戳必须都放在调用的网址中,请确认机器人的密钥加密和填写正确;link:请参考本接口对应文档获得具体要求,或者在https://open.dingtalk.com/document/ 搜索相关文档;'}

@staticmethod
    async def send_dingtalk(url: str, msg: str) -> Dict[str, Any]:
        """
        钉钉
        """
        data = {
            "msgtype": "text",
            "text": {
                "content": msg
            }
        } 
        def generate_sign(secret):
            timestamp = str(round(time.time() * 1000))
            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))
            return timestamp, sign

        secret = url.split("&")[1].split("=")[1]
        timestamp, sign = generate_sign(secret)
        url = f"{url}&timestamp={timestamp}&sign={sign}"
        return await send_message(url, data)

从chatGPT上面得出这个解决方案,测试可以接收消息