Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SlieFamily
Copy link

@SlieFamily SlieFamily commented Aug 2, 2024

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

@SlieFamily SlieFamily changed the title 实现群聊本地图片【ba'se】上传 实现群聊本地图片【base64编码】上传及其发送 Aug 2, 2024
@axiangcoding
Copy link
Contributor

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

@axiangcoding
Copy link
Contributor

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

@liyihao1110
Copy link

这是我的部分代码:
# 读取本地图片文件并进行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'}

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

Successfully merging this pull request may close these issues.

4 participants