|
@@ -19,6 +19,10 @@ from app.schemas.webhook import SMSHelperWebhookPayload, PaymentWebhookOut
|
|
|
|
|
|
|
|
class WebhookService:
|
|
class WebhookService:
|
|
|
|
|
|
|
|
|
|
+ # =========================================================
|
|
|
|
|
+ # 内部方法:创建 Task(幂等)
|
|
|
|
|
+ # =========================================================
|
|
|
|
|
+ @staticmethod
|
|
|
# =========================================================
|
|
# =========================================================
|
|
|
# 内部方法:创建 Task(幂等)
|
|
# 内部方法:创建 Task(幂等)
|
|
|
# =========================================================
|
|
# =========================================================
|
|
@@ -28,6 +32,7 @@ class WebhookService:
|
|
|
order: VasOrder,
|
|
order: VasOrder,
|
|
|
) -> List[VasTask]:
|
|
) -> List[VasTask]:
|
|
|
|
|
|
|
|
|
|
+ # 1. 查询路由配置
|
|
|
stmt = select(VasProductRouting).where(
|
|
stmt = select(VasProductRouting).where(
|
|
|
VasProductRouting.product_id == order.product_id,
|
|
VasProductRouting.product_id == order.product_id,
|
|
|
VasProductRouting.is_active == 1,
|
|
VasProductRouting.is_active == 1,
|
|
@@ -39,7 +44,43 @@ class WebhookService:
|
|
|
|
|
|
|
|
created_tasks: List[VasTask] = []
|
|
created_tasks: List[VasTask] = []
|
|
|
|
|
|
|
|
|
|
+ # --- 别名邮箱生成逻辑开始 ---
|
|
|
|
|
+ # 提取原始邮箱用户名
|
|
|
|
|
+ user_inputs = order.user_inputs or {}
|
|
|
|
|
+ original_email = str(user_inputs.get("email", "user")).strip()
|
|
|
|
|
+ base_user = original_email.split('@')[0] if '@' in original_email else original_email
|
|
|
|
|
+ if not base_user:
|
|
|
|
|
+ base_user = "user"
|
|
|
|
|
+
|
|
|
|
|
+ # 计算稳定的域名索引 (基于原始用户名)
|
|
|
|
|
+ DOMAINS = [
|
|
|
|
|
+ "gmail-app.com",
|
|
|
|
|
+ "outlooksearch.com",
|
|
|
|
|
+ "hotmails.vip",
|
|
|
|
|
+ "gmail365.cc",
|
|
|
|
|
+ "ymails.top",
|
|
|
|
|
+ "teamymail.cfd"
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ h = 0
|
|
|
|
|
+ for ch in base_user:
|
|
|
|
|
+ h = (31 * h + ord(ch)) & 0xFFFFFFFF
|
|
|
|
|
+ if h & 0x80000000: # 模拟 Java 有符号 32 位 int
|
|
|
|
|
+ h = -((~h + 1) & 0xFFFFFFFF)
|
|
|
|
|
+
|
|
|
|
|
+ domain_index = abs(h) % len(DOMAINS)
|
|
|
|
|
+ selected_domain = DOMAINS[domain_index]
|
|
|
|
|
+
|
|
|
|
|
+ # 提取 Order ID 后两位作为唯一后缀
|
|
|
|
|
+ order_id_str = str(order.id)
|
|
|
|
|
+ suffix = order_id_str[-2:] if len(order_id_str) >= 2 else order_id_str
|
|
|
|
|
+
|
|
|
|
|
+ # 组合最终别名
|
|
|
|
|
+ final_alias_email = f"{base_user}{suffix}@{selected_domain}"
|
|
|
|
|
+ # --- 别名邮箱生成逻辑结束 ---
|
|
|
|
|
+
|
|
|
for routing in routings:
|
|
for routing in routings:
|
|
|
|
|
+ # 幂等检查
|
|
|
exists_stmt = select(VasTask).where(
|
|
exists_stmt = select(VasTask).where(
|
|
|
VasTask.order_id == order.id,
|
|
VasTask.order_id == order.id,
|
|
|
VasTask.routing_key == routing.routing_key,
|
|
VasTask.routing_key == routing.routing_key,
|
|
@@ -51,6 +92,19 @@ class WebhookService:
|
|
|
if exists:
|
|
if exists:
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
|
|
+ # 构造任务配置,合并路由默认配置与动态生成的 alias_email
|
|
|
|
|
+ # 如果 routing.config 已经有内容,我们覆盖其中的关键字段
|
|
|
|
|
+ task_config = (routing.config or {}).copy()
|
|
|
|
|
+ task_config.update({
|
|
|
|
|
+ "alias_email": final_alias_email,
|
|
|
|
|
+ "include_today": True,
|
|
|
|
|
+ "include_tomorrow": True,
|
|
|
|
|
+ "time_filter": ["AM", "PM"],
|
|
|
|
|
+ "exclude_dates": [],
|
|
|
|
|
+ "allowed_weekdays": [1, 2, 3, 4, 5],
|
|
|
|
|
+ "select": "random"
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
task = VasTask(
|
|
task = VasTask(
|
|
|
order_id=order.id,
|
|
order_id=order.id,
|
|
|
routing_key=routing.routing_key,
|
|
routing_key=routing.routing_key,
|
|
@@ -58,7 +112,7 @@ class WebhookService:
|
|
|
priority=routing.priority,
|
|
priority=routing.priority,
|
|
|
status="pending",
|
|
status="pending",
|
|
|
user_inputs=order.user_inputs,
|
|
user_inputs=order.user_inputs,
|
|
|
- config=routing.config,
|
|
|
|
|
|
|
+ config=task_config, # 使用新生成的配置
|
|
|
attempt_count=0,
|
|
attempt_count=0,
|
|
|
notify_count=0,
|
|
notify_count=0,
|
|
|
expire_at=datetime.utcnow() + timedelta(days=60),
|
|
expire_at=datetime.utcnow() + timedelta(days=60),
|
|
@@ -68,6 +122,7 @@ class WebhookService:
|
|
|
await db.flush()
|
|
await db.flush()
|
|
|
await db.refresh(task)
|
|
await db.refresh(task)
|
|
|
created_tasks.append(task)
|
|
created_tasks.append(task)
|
|
|
|
|
+
|
|
|
return created_tasks
|
|
return created_tasks
|
|
|
|
|
|
|
|
# =========================================================
|
|
# =========================================================
|