测试音乐信息
This commit is contained in:
@@ -141,6 +141,16 @@ class MusicPlugin(MessagePluginInterface):
|
||||
self.LOG.error(f"搜索歌曲出错: {e}")
|
||||
return {}
|
||||
|
||||
|
||||
async def url_to_base64(url):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as resp:
|
||||
resp.raise_for_status()
|
||||
data = await resp.read()
|
||||
b64_str = base64.b64encode(data).decode('utf-8')
|
||||
return b64_str
|
||||
|
||||
|
||||
async def _send_music_message(self, bot: WechatAPIClient, song_info: Dict[str, Any], receiver: str) -> bool:
|
||||
"""发送音乐消息"""
|
||||
try:
|
||||
@@ -199,6 +209,9 @@ class MusicPlugin(MessagePluginInterface):
|
||||
self.LOG.info(f"发送音乐消息:{xml_message}")
|
||||
res = await bot.send_app_message(wxid=receiver, xml=xml_message, type=0)
|
||||
self.LOG.info(f"发送音乐消息 res:{res}")
|
||||
voice_base64 =url_to_base64(play_url)
|
||||
res = await bot.send_voice_message(wxid=receiver, voice=voice_base64)
|
||||
self.LOG.info(f"发送音乐消息 voice res:{res}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -280,7 +280,7 @@ class MessageMixin(WechatAPIClientBase):
|
||||
else:
|
||||
self.error_handler(json_resp)
|
||||
|
||||
async def send_voice_message(self, wxid: str, voice: Union[str, bytes, os.PathLike], format: str = "amr") -> \
|
||||
async def send_voice_message(self, wxid: str, voice: Union[str, bytes, os.PathLike], format: str = "AMR") -> \
|
||||
tuple[int, int, int]:
|
||||
"""发送语音消息。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user