This commit is contained in:
2025-08-19 15:06:49 +08:00
parent a28d041a71
commit 670e9f1ec3
5 changed files with 300 additions and 13 deletions

View File

@@ -3,9 +3,6 @@ import os
import time
import base64
from JiMeng.Kit.JmCommon import JmCommon
from JiMeng.Kit.JmErrorCode import JmErrorCode
class JmTxt2Img:
action = "CVProcess"
@@ -61,13 +58,13 @@ class JmTxt2Img:
prompt += "5、宏大雄伟,颜色鲜明,不要灰色调的,不要有雾霾之类的"
prompt += "6、超高清画质"
# 保存图片路径
save_image_path = os.path.join(JmCommon.base_path, "Text2Img.jpg")
# 保存图片路径 - 使用绝对路径避免相对路径问题
save_image_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "..", "..", "Text2Img.jpg"))
print(f"保存图片路径:{save_image_path}")
# 添加重试逻辑处理API并发限制错误
retry_count = 0
max_retries = 1000 # 最大重试次数
max_retries = 5 # 减少重试次数以便更快排查问题
retry_interval = 5000 # 重试间隔(毫秒)
while True:

View File

@@ -17,7 +17,7 @@ class JmCommon:
schema = "https"
version = "2022-08-31"
# API访问凭证
# API访问凭证 - 请替换为您自己的凭证
ak = "AKLTZjVlOGU1NzA1YWZkNDExMzkzYzY5YTNlOTRmMTMxODg"
sk = "WkdabU9UTXdNVEJpTmpWbE5HVTJZVGxtTnpWbU5XSTBaRGN5TW1NMk5tRQ=="
@@ -68,12 +68,16 @@ class JmCommon:
@staticmethod
def gen_signing_secret_key_v4(date, region, service):
"""生成V4版本的签名密钥"""
# 注意这里sk需要解码因为Java代码中sk是Base64编码的
sk_bytes = base64.b64decode(JmCommon.sk)
k_date = JmCommon.hmac_sha256(sk_bytes, date)
k_region = JmCommon.hmac_sha256(k_date, region)
k_service = JmCommon.hmac_sha256(k_region, service)
return JmCommon.hmac_sha256(k_service, "request")
try:
# 解码SK (Base64)
sk_bytes = base64.b64decode(JmCommon.sk)
k_date = JmCommon.hmac_sha256(sk_bytes, date)
k_region = JmCommon.hmac_sha256(k_date, region)
k_service = JmCommon.hmac_sha256(k_region, service)
k_signing = JmCommon.hmac_sha256(k_service, "request")
return k_signing
except Exception as e:
raise Exception(f"生成签名密钥失败: {str(e)}")
@staticmethod
def do_request(method, query_list, body, action):
@@ -139,6 +143,8 @@ class JmCommon:
# 发送请求
try:
print(f"请求URL: {url}")
print(f"请求头: {headers}")
response = requests.request(
method=method,
url=url,
@@ -146,6 +152,8 @@ class JmCommon:
data=body,
timeout=(30, 30) # 连接超时和读取超时
)
print(f"响应状态码: {response.status_code}")
print(f"响应内容: {response.text}")
response.raise_for_status() # 如果状态码不是200抛出异常
return response.text
except requests.exceptions.RequestException as e: