Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

发送二维码不显示的解决方案 #129

Open
mudapi opened this issue Jun 5, 2021 · 5 comments
Open

发送二维码不显示的解决方案 #129

mudapi opened this issue Jun 5, 2021 · 5 comments

Comments

@mudapi
Copy link

mudapi commented Jun 5, 2021

dingding.py的开头加上
import re
import base64
from io import BytesIO

from pyzbar.pyzbar import decode
from PIL import Image

def base64_to_image(base64_str, image_path=None):
base64_data = re.sub('^data:image/.+;base64,', '', base64_str)
byte_data = base64.b64decode(base64_data)
image_data = BytesIO(byte_data)
img = Image.open(image_data)
if image_path:
img.save(image_path)
return img

后面的def改成
def ddmsgsend(self, msgurl):
import requests, json # 导入依赖库
img=base64_to_image(msgurl)
barcodes = decode(img)
for barcode in barcodes:
url = barcode.data.decode("utf-8")
headers = {"Content-Type": "application/json ; charset=utf-8"} # 定义数据类型
data = {
"text": {
"content": url,
},
"msgtype": "text"
}
res = requests.post(self.get_url(), data=json.dumps(data), headers=headers)
#发送post请求
print(res.text)

最后收到的链接就是登陆链接,复制到学习强国里面发给自己,然后打开链接就行

@shikik
Copy link

shikik commented Jun 5, 2021

还是报错,下面是报错信息

DevTools listening on ws://127.0.0.1:51000/devtools/browser/003161e3-0381-44c0-8f89-18fa6ffd3188
正在打开二维码登陆界面,请稍后
二维码将发往钉钉机器人...

钉钉机器人url: https://oapi.dingtalk.com/robot/send?access_token=1xxxxxxx打码xxxxxxxxxxxxxxxef723ff&timestamp=16xxxxxx85&sign=xxxxxxxxxxxxxMQG484n0%3D
{"errcode":310000,"errmsg":"keywords not in content, more: [https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq]"}

@mudapi
Copy link
Author

mudapi commented Jun 5, 2021

还是报错,下面是报错信息

DevTools listening on ws://127.0.0.1:51000/devtools/browser/003161e3-0381-44c0-8f89-18fa6ffd3188

正在打开二维码登陆界面,请稍后
二维码将发往钉钉机器人...
钉钉机器人url: https://oapi.dingtalk.com/robot/send?access_token=1xxxxxxx打码xxxxxxxxxxxxxxxef723ff&timestamp=16xxxxxx85&sign=xxxxxxxxxxxxxMQG484n0%3D
{"errcode":310000,"errmsg":"keywords not in content, more: [https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq]"}

这是因为你没获取到二维码图片,所以没法解析二维码,发送信息就是空的,自己排查一下为啥没获取到二维码信息吧

@shikik
Copy link

shikik commented Jun 5, 2021

还是报错,下面是报错信息

DevTools listening on ws://127.0.0.1:51000/devtools/browser/003161e3-0381-44c0-8f89-18fa6ffd3188

正在打开二维码登陆界面,请稍后
二维码将发往钉钉机器人...
钉钉机器人url: https://oapi.dingtalk.com/robot/send?access_token=1xxxxxxx打码xxxxxxxxxxxxxxxef723ff&timestamp=16xxxxxx85&sign=xxxxxxxxxxxxxMQG484n0%3D
{"errcode":310000,"errmsg":"keywords not in content, more: [https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq]"}

这是因为你没获取到二维码图片,所以没法解析二维码,发送信息就是空的,自己排查一下为啥没获取到二维码信息吧
谢谢回复,已经弄好了。是关键词的问题;机器人关键词添加url之后能收到

@dvdrm
Copy link

dvdrm commented Jun 13, 2021

请问大佬,docker版去哪儿修改dingding.py……

@wx5223
Copy link

wx5223 commented Jun 17, 2021

@dvdrm docker版请参考TechXueXi/TechXueXi#143

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants