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"
}

prompt = """A single luxurious 3D Token coin/currency symbol icon, isolated on pure transparent background (PNG alpha channel). The token symbol is a hexagonal golden coin with the letter 'T' in the center, surrounded by a glowing circular ring of binary code and neural network patterns. The coin has a metallic gold and cyan gradient, with subtle holographic shimmer effects, microchip circuit lines etched on the rim, and a soft glowing aura. Style: 3D rendered, ultra-detailed, photorealistic, premium fintech/AI icon design, no text labels, single object only, perfect for app icon or logo usage, isolated on transparent background."""

payload = {
    "model": "gpt-image-2",
    "prompt": prompt,
    "size": "1024x1024",
    "background": "transparent"
}

print("正在调用 gpt-image-2 API 生成 Token 货币符号...")
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/token_result.json', 'w', encoding='utf-8') as f:
        json.dump(result, f, indent=2, ensure_ascii=False)

    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"token-coin-transparent-{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}")
                print(f"文件大小: {len(img_response.content)} bytes")