Files

39 lines
985 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
"""将生成的卡片发送到企微"""
import asyncio
import sys
sys.path.insert(0, '/app')
from app.services.wecom_service import WecomService
async def main():
"""发送卡片图片"""
wecom = WecomService()
try:
# 上传图片
print("📤 上传卡片图片...")
with open('/tmp/it_reminder_card.png', 'rb') as f:
image_data = f.read()
media_id = await wecom.upload_temp_media("image", image_data, "it_reminder_card.png")
print(f" media_id: {media_id}")
# 发送图片
print("📨 发送图片消息...")
result = await wecom.send_image_message("sxn", media_id)
if result.get("errcode") == 0:
print(f"✅ 发送成功! msgid: {result.get('msgid')}")
else:
print(f"❌ 发送失败: {result}")
finally:
await wecom.close()
if __name__ == "__main__":
asyncio.run(main())