Files
wecom_it_smart_desk/deploy-server/generate_and_upload.py
Simon bea288e414 feat: 2026-07-11 全量更新 - 代办集成+会议室预定+知识迭代修复+UI统一+Bug修复
== 已部署上线 (9项) ==
- 代办事项真实数据源集成 (企微审批API 8bug修复链)
- H5/坐席端 Logo样式统一+绿色背景
- 视频引导页修复 (localStorage key v2)
- 坐席端 v9 Vue版本修复 (ElMessage._context)
- 截图按钮 v10 修复 (getDisplayMedia user gesture)
- 扫码样式恢复+H5扫码登录跳转修复
- H5截图快捷键提示

== 代码完成待部署 (3项) ==
- 知识迭代3Bug修复 (#8 POST端点/#7 MERGE幂等/#6 过期检查)
- 会议室预定-小鱼易联终端 (40文件, 40/40测试通过)
- IT资产升级审批推送 (asset_service.py)

== 需求文档 (2项) ==
- 坐席端AI辅助消息框-PRD (4项新功能确认)
- 坐席端布局优化建议 v2.0 (7天计划)

== 新增文档 ==
- 日报-2026-07-11.md
- 知识迭代Bug修复报告-20260711.md
- 会议室预定-部署指南.md
- CHANGELOG.md 更新

== 测试 ==
- test_todo_integration.py: 40/40
- test_meetingroom.py: 40/40
- test_bugfix_ki_suggestions.py: 21/21
2026-07-11 23:13:10 +08:00

105 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""在服务器上生成通知图片并上传到企微"""
import asyncio
import sys
sys.path.insert(0, '/app')
from PIL import Image, ImageDraw, ImageFont
from app.services.wecom_service import WecomService
async def generate_image():
"""生成通知图片"""
WIDTH, HEIGHT = 600, 300
img = Image.new('RGB', (WIDTH, HEIGHT))
draw = ImageDraw.Draw(img)
# 渐变背景
for y in range(HEIGHT):
ratio = y / HEIGHT
r = int(0 + (0 - 0) * ratio)
g = int(120 + (180 - 120) * ratio)
b = int(215 + (160 - 215) * ratio)
draw.line([(0, y), (WIDTH, y)], fill=(r, g, b))
# 字体
try:
title_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 32)
subtitle_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 20)
button_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 24)
except:
title_font = ImageFont.load_default()
subtitle_font = ImageFont.load_default()
button_font = ImageFont.load_default()
# 标题
draw.text((30, 30), "IT咨询即将关闭", fill=(255, 255, 255), font=title_font)
draw.text((30, 85), "请尽快回复坐席,否则将自动结束", fill=(220, 220, 220), font=subtitle_font)
# 3D按钮
btn_x, btn_y = 30, 150
btn_w, btn_h = 540, 60
# 阴影
draw.rounded_rectangle([btn_x+3, btn_y+3, btn_x+btn_w+3, btn_y+btn_h+3], radius=12, fill=(100, 100, 100))
# 按钮主体
for i in range(btn_h):
ratio = i / btn_h
r = int(20 + (100 - 20) * ratio)
g = int(150 + (200 - 150) * ratio)
b = int(220 + (255 - 220) * ratio)
draw.rectangle([btn_x, btn_y+i, btn_x+btn_w, btn_y+i+1], fill=(r, g, b))
# 高光
draw.rounded_rectangle([btn_x, btn_y, btn_x+btn_w, btn_y+btn_h//3], radius=12, fill=(255, 255, 255, 60))
# 按钮文字
draw.text((btn_x + btn_w//2 - 60, btn_y + 18), "立即回复", fill=(255, 255, 255), font=button_font)
# 保存到内存
from io import BytesIO
buffer = BytesIO()
img.save(buffer, format='PNG')
buffer.seek(0)
return buffer.getvalue()
async def upload_and_send():
"""上传图片并发送消息"""
print("🎨 正在生成通知图片...")
image_data = await generate_image()
print(f" 图片已生成, 大小: {len(image_data)} bytes")
# 创建企微服务
wecom = WecomService()
try:
print("📤 正在上传图片到企微...")
# 上传临时素材 - 传入二进制数据
media_id = await wecom.upload_temp_media("image", image_data, "reminder.png")
if not media_id or media_id.startswith("ERROR"):
print(f"❌ 上传失败: {media_id}")
return
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(upload_and_send())