|
|
@@ -13,20 +13,21 @@
|
|
|
"""
|
|
|
import aiohttp
|
|
|
import asyncio
|
|
|
+import base64
|
|
|
from nonebot import logger
|
|
|
|
|
|
Headers = {
|
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
|
|
|
}
|
|
|
|
|
|
-URL = "https://api.emoao.com/api/60s?type=json"
|
|
|
+URL = "https://v.api.aa1.cn/api/60s-v3/?cc=国内要闻"
|
|
|
|
|
|
|
|
|
async def fetch_final_url(url: str) -> str:
|
|
|
"""获取直到不再跳转的url链接"""
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
while True:
|
|
|
- async with session.get(url, allow_redirects=False) as response:
|
|
|
+ async with session.get(url, headers=Headers, timeout=5, allow_redirects=False) as response:
|
|
|
if response.status == 200:
|
|
|
return response.url.human_repr()
|
|
|
elif response.status in [301, 302, 303, 307, 308]:
|
|
|
@@ -40,11 +41,10 @@ async def fetch_final_url(url: str) -> str:
|
|
|
async def get_60sNews() -> str:
|
|
|
try:
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
- async with session.get(url=URL, headers=Headers, timeout=5) as response:
|
|
|
- res = await response.json(content_type=None)
|
|
|
- data = res["data"]
|
|
|
- img_url = await fetch_final_url(data["image"])
|
|
|
- msg = f'[CQ:image,file={img_url},subType=0,cache=0]'
|
|
|
+ async with session.get(url=URL, headers=Headers, timeout=5, verify_ssl=False) as response:
|
|
|
+ data = await response.read()
|
|
|
+ data = base64.b64encode(data).decode("ascii")
|
|
|
+ msg = f'[CQ:image,file=base64://{data},subType=0]'
|
|
|
logger.debug(msg)
|
|
|
return msg
|
|
|
except:
|