botpy icon indicating copy to clipboard operation
botpy copied to clipboard

实现群聊本地图片【base64编码】上传及其发送

Open SlieFamily opened this issue 1 year ago • 3 comments

官方API目前已经支持通过对 file_data 参数传入二进制文件的base64编码(字符串)的方式实现在群聊中以富媒体的方式发送本地图片。 已简略的编写PythonSDK 的 api.py 实现此功能,并在 examples/demo_group_reply_file.py 中加入了使用方法。

SlieFamily avatar Aug 02 '24 14:08 SlieFamily

社区的支持很快,但是看起来这个仓库不是很经常处理MR和版本发布

axiangcoding avatar Aug 05 '24 06:08 axiangcoding

另外,我建议同个域名的请求和原先的函数 post_group_file 保持一致,仅通过参数来区分使用

axiangcoding avatar Aug 08 '24 03:08 axiangcoding

这是我的部分代码: # 读取本地图片文件并进行base64编码 with open(answer_2, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()).decode('utf-8') image_response = requests.post( url=f"https://api.sgroup.qq.com/v2/groups/{group_openid}/files", json={"file_type": 1,"file_data": encoded_string,"group_openid": group_openid}, headers={"Authorization": "QQBot " + get_access_token()} ) print(image_response.json()) file_info = image_response.json().get("file_info") image_response1 = requests.post( url=f"https://api.sgroup.qq.com/v2/groups/{group_openid}/messages", json={"content": "123","msg_type": 7,"media": file_info,"msg_id": message_id,"group_openid": group_openid}, headers={"Authorization": "QQBot " + get_access_token()} ) print(image_response1.json()) 始终报错:{'message': '请求数据异常', 'code': 40011000, 'err_code': 40011000, 'trace_id': '8658e78955df9e1bd2e79655e0ef301c'}

liyihao1110 avatar Sep 13 '24 14:09 liyihao1110