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

[提问]私聊消息无法正常到达 #828

Open
tianyu365 opened this issue Oct 16, 2024 · 4 comments
Open

[提问]私聊消息无法正常到达 #828

tianyu365 opened this issue Oct 16, 2024 · 4 comments
Labels
question 这啥呀这是,我不到啊

Comments

@tianyu365
Copy link

**Python 版本:3.13

**模块版本:16.3.0

**运行环境: MacOS


发送消息请求是正常的 再本地浏览器上也可以看到消息发出去了 但是别人收不到 看了相关文档
先调用fetch_session_msgs 还是无法正常让别人收到消息
浏览器手动发送别人可以正常收到

@tianyu365 tianyu365 added the question 这啥呀这是,我不到啊 label Oct 16, 2024
@tianyu365
Copy link
Author

WeChatff19dc9e9fa8531aa17598a6cb49af35

@ecfxs
Copy link

ecfxs commented Oct 16, 2024

有一种可能是你的消息包含敏感词。

@tianyu365
Copy link
Author

有一个可能是你的消息包含敏感词。

不会 就回复你好都没用 手动发正常

@tianyu365 tianyu365 changed the title 私聊消息无法正常到达 [提问]私聊消息无法正常到达 Oct 16, 2024
@Drelf2018
Copy link
Collaborator

Drelf2018 commented Nov 20, 2024

async def send_msg(
credential: Credential,
receiver_id: int,
msg_type: EventType,
content: Union[str, Picture],
) -> dict:
"""
给用户发送私聊信息。目前仅支持纯文本。
Args:
credential (Credential) : 凭证
receiver_id (int) : 接收者 UID
msg_type (EventType) : 信息类型,参考 Event 类的事件类型。
content (str | Picture): 信息内容。支持文字和图片。
Returns:
dict: 调用 API 返回结果
"""
credential.raise_for_no_sessdata()
credential.raise_for_no_bili_jct()
api = API["operate"]["send_msg"]
self_info = await get_self_info(credential)
sender_uid = self_info["mid"]
if msg_type == EventType.TEXT:
real_content = json.dumps({"content": content})
elif msg_type == EventType.WITHDRAW:
real_content = str(content)
elif msg_type == EventType.PICTURE or msg_type == EventType.GROUPS_PICTURE:
raise_for_statement(isinstance(content, Picture), "TypeError")
await content.upload_file(credential=credential, data={"biz": "im"})
real_content = json.dumps(
{
"url": content.url,
"height": content.height,
"width": content.width,
"imageType": content.imageType,
"original": 1,
"size": content.size,
}
)
else:
raise ApiException("信息类型不支持。")
data = {
"msg[sender_uid]": sender_uid,
"msg[receiver_id]": receiver_id,
"msg[receiver_type]": 1,
"msg[msg_type]": msg_type.value,
"msg[msg_status]": 0,
"msg[content]": real_content,
"msg[dev_id]": "A6716E9A-7CE3-47AF-994B-F0B34178D28D",
"msg[new_face_version]": 0,
"msg[timestamp]": int(time.time()),
"from_filework": 0,
"build": 0,
"mobi_app": "web",
}
return await Api(**api, credential=credential).update_data(**data).result

尝试修改你本地的库里的这部分代码,再试试问题是否再次出现。

async def send_msg(
    credential: Credential,
    receiver_id: int,
    msg_type: EventType,
    content: Union[str, Picture],
) -> dict:

    ...

    data = {
        ...
    }
+   query = {
+       "w_sender_uid": sender_uid,
+       "w_receiver_id": receiver_id,
+   }
-   return await Api(**api, credential=credential).update_data(**data).result
+   return await Api(**api, credential=credential, wbi=True).update_data(**data).update_params(**query).result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question 这啥呀这是,我不到啊
Projects
None yet
Development

No branches or pull requests

3 participants