File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 89
89
"url" : " https://api.vc.bilibili.com/web_im/v1/web_im/send_msg" ,
90
90
"method" : " POST" ,
91
91
"verify" : true ,
92
+ "wbi" : true ,
92
93
"data" : {
93
94
"msg[sender_uid]" : " int: 自己的 UID" ,
94
95
"msg[receiver_id]" : " int: 对方 UID" ,
97
98
"msg[msg_status]" : " const int: 0" ,
98
99
"msg[content]" : " str: 消息内容"
99
100
},
101
+ "params" : {
102
+ "sender_uid" : " int: 自己的 UID" ,
103
+ "receiver_id" : " int: 对方 UID"
104
+ },
100
105
"comment" : " 给用户发信息"
101
106
}
102
107
}
Original file line number Diff line number Diff line change @@ -363,6 +363,8 @@ async def send_msg(
363
363
"""
364
364
给用户发送私聊信息。目前仅支持纯文本。
365
365
366
+ 调用 API 需要发送者用户的 UID,可将此携带在凭据类的 DedeUserID 字段,不携带模块将自动获取对应 UID。
367
+
366
368
Args:
367
369
credential (Credential) : 凭证
368
370
@@ -379,8 +381,11 @@ async def send_msg(
379
381
credential .raise_for_no_bili_jct ()
380
382
381
383
api = API ["operate" ]["send_msg" ]
382
- self_info = await get_self_info (credential )
383
- sender_uid = self_info ["mid" ]
384
+ if credential .has_dedeuserid () and int (credential .dedeuserid ) != 0 :
385
+ sender_uid = int (credential .dedeuserid )
386
+ else :
387
+ self_info = await get_self_info (credential )
388
+ sender_uid = self_info ["mid" ]
384
389
385
390
if msg_type == EventType .TEXT :
386
391
real_content = json .dumps ({"content" : content })
@@ -416,7 +421,17 @@ async def send_msg(
416
421
"build" : 0 ,
417
422
"mobi_app" : "web" ,
418
423
}
419
- return await Api (** api , credential = credential ).update_data (** data ).result
424
+ query = {
425
+ "w_sender_uid" : sender_uid ,
426
+ "w_receiver_id" : receiver_id ,
427
+ }
428
+
429
+ return (
430
+ await Api (** api , credential = credential )
431
+ .update_params (** query )
432
+ .update_data (** data )
433
+ .result
434
+ )
420
435
421
436
422
437
class Session (AsyncEvent ):
Original file line number Diff line number Diff line change @@ -348,6 +348,8 @@ from bilibili_api import session
348
348
349
349
给用户发送私聊信息。目前仅支持纯文本。
350
350
351
+ 调用 API 需要发送者用户的 UID,可将此携带在凭据类的 DedeUserID 字段,不携带模块将自动获取对应 UID。
352
+
351
353
352
354
| name | type | description |
353
355
| - | - | - |
You can’t perform that action at this time.
0 commit comments