import requests
import json
import time

url = "https://api.acedata.cloud/openai/images/generations"

headers = {
    "accept": "application/json",
    "authorization": "Bearer 3a3b982990c44fc5ba5428320d72330e",
    "content-type": "application/json"
}

# 16:9 海报 - 使用 1536x1024 尺寸
prompt = """A professional 16:9 infographic poster in English titled 'China Telecom Operators' Token Business Strategy: A Comprehensive Analysis'.

Design style: Futuristic, tech-savvy, corporate business infographic with deep blue and cyan gradient background, glowing data streams, neural network patterns, and 5G tower silhouettes. Clean modern typography, structured layout with 4 main sections connected by flowing data lines.

Content layout (left to right, top to bottom):

HEADER: Large bold title 'CHINA TELECOM OPERATORS' TOKEN BUSINESS STRATEGY' with subtitle 'A Comprehensive Analysis of Byte + Token Dual-Driven Transformation'.

SECTION 1 (Top-left): '1. END-NETWORK-CLOUD INTEGRATION' - The Physical Foundation
- Terminal (端): 'Phone Number = AI Identity', AI-eSIM, AI smartphones, cloud PCs
- Network (网): '5G-A + Computing-Network Brain', Token-aware routing, low-latency
- Cloud (云): 'Centralized Production & Elastic Scheduling', PD-disaggregated inference, KV Cache distribution

SECTION 2 (Top-right): '2. TOKEN OPERATIONS PLATFORM' - The Universal Currency Hub
- Unified Authentication: Mobile number as IDaaS core
- Unified Metering: Cross-model token conversion standard
- Unified Billing: Phone bill payment, transparent revenue sharing

SECTION 3 (Bottom-left): '3. TOKEN SERVICES: 2C / 2H / 2B' - Multi-Dimensional Value Models
- 2C Personal: 'Users × AI Devices × Token Price' revenue model, Token add-on packs
- 2H Home: Family AI core entry (smart screens, cameras), home broadband binding
- 2B Enterprise: Tiered services - SME standard packages, large enterprise customization, government dedicated solutions

SECTION 4 (Bottom-right): '4. CONCLUSION: BYTE + TOKEN DUAL-DRIVEN ERA'
- Transformation from traditional 'Byte (Traffic)' to 'Byte + Token (AI Compute)' dual-driven
- Token doesn't replace traffic, but adds intelligent service value on top
- Operators leverage network advantages, massive users, and channel capabilities for AI-era value growth

Visual elements: Glowing blockchain-like token icons floating, hexagonal grid pattern, network topology visualizations, neural network nodes connecting sections, Chinese telecom tower silhouettes in background, holographic data flow effects.

Color palette: Deep navy blue (#0A1F3D), electric cyan (#00D4FF), vibrant purple (#7B2FF7), white text, accent gold (#FFD700) for highlights.

Style: High-end corporate consulting infographic, McKinsey/BCG quality, suitable for executive presentation, ultra-detailed, sharp focus, 8K quality rendering."""

payload = {
    "model": "gpt-image-2",
    "prompt": prompt,
    "size": "1536x1024"
}

print("正在调用 gpt-image-2 API 生成海报...")
print(f"Prompt 长度: {len(prompt)} 字符")

response = requests.post(url, json=payload, headers=headers)
result = response.json()
print(f"\n响应状态: {response.status_code}")
print(f"响应内容: {json.dumps(result, indent=2, ensure_ascii=False)[:2000]}")

# 保存结果
if response.status_code == 200:
    with open('/var/www/html/share/temp/poster_result.json', 'w', encoding='utf-8') as f:
        json.dump(result, f, indent=2, ensure_ascii=False)

    # 如果有图片URL，下载图片
    if 'data' in result and len(result['data']) > 0:
        img_url = result['data'][0].get('url')
        if img_url:
            print(f"\n图片URL: {img_url}")
            img_response = requests.get(img_url)
            if img_response.status_code == 200:
                filename = f"china-operator-token-strategy-en-{int(time.time())}.png"
                filepath = f"/var/www/html/share/{filename}"
                with open(filepath, 'wb') as f:
                    f.write(img_response.content)
                print(f"图片已保存: {filepath}")
                print(f"访问地址: http://43.156.179.74/share/{filename}")