update pay ui

This commit is contained in:
2025-12-12 00:42:55 +08:00
parent 8d6fd4cae7
commit c689157ce6
2 changed files with 109 additions and 20 deletions

56
app.py
View File

@@ -3140,30 +3140,46 @@ def register():
def send_sms_code(phone, code, template_id):
"""发送短信验证码"""
"""发送短信验证码(使用 subprocess 绕过 eventlet DNS 问题)"""
import subprocess
import os
try:
cred = credential.Credential(SMS_SECRET_ID, SMS_SECRET_KEY)
httpProfile = HttpProfile()
httpProfile.endpoint = "sms.tencentcloudapi.com"
# 获取脚本路径
script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'sms_sender.py')
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = sms_client.SmsClient(cred, "ap-beijing", clientProfile)
print(f"[短信] 准备发送验证码到 {phone}模板ID: {template_id}")
req = models.SendSmsRequest()
params = {
"PhoneNumberSet": [phone],
"SmsSdkAppId": SMS_SDK_APP_ID,
"TemplateId": template_id,
"SignName": SMS_SIGN_NAME,
"TemplateParamSet": [code, "5"] if template_id == SMS_TEMPLATE_LOGIN else [code]
}
req.from_json_string(json.dumps(params))
# 使用 subprocess 在独立进程中发送短信(绕过 eventlet DNS
result = subprocess.run(
[
sys.executable, # 使用当前 Python 解释器
script_path,
phone,
code,
template_id,
SMS_SECRET_ID,
SMS_SECRET_KEY,
SMS_SDK_APP_ID,
SMS_SIGN_NAME
],
capture_output=True,
text=True,
timeout=30
)
resp = client.SendSms(req)
return True
except TencentCloudSDKException as err:
print(f"SMS Error: {err}")
if result.returncode == 0:
print(f"[短信] ✓ 发送成功: {result.stdout.strip()}")
return True
else:
print(f"[短信] ✗ 发送失败: {result.stderr.strip()}")
return False
except subprocess.TimeoutExpired:
print(f"[短信] ✗ 发送超时")
return False
except Exception as e:
print(f"[短信] ✗ 发送异常: {type(e).__name__}: {e}")
return False

73
sms_sender.py Normal file
View File

@@ -0,0 +1,73 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
独立的短信发送脚本(绕过 eventlet DNS 问题)
使用方式:
python sms_sender.py <phone> <code> <template_id> <secret_id> <secret_key> <app_id> <sign_name>
返回值:
成功返回 0失败返回 1
"""
import sys
import json
def send_sms(phone, code, template_id, secret_id, secret_key, app_id, sign_name):
"""发送短信验证码"""
try:
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.sms.v20210111 import sms_client, models
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
cred = credential.Credential(secret_id, secret_key)
httpProfile = HttpProfile()
httpProfile.endpoint = "sms.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = sms_client.SmsClient(cred, "ap-beijing", clientProfile)
req = models.SendSmsRequest()
# 登录模板需要两个参数:验证码和有效期
template_params = [code, "5"] if "login" in template_id.lower() or template_id == "2365498" else [code]
params = {
"PhoneNumberSet": [phone],
"SmsSdkAppId": app_id,
"TemplateId": template_id,
"SignName": sign_name,
"TemplateParamSet": template_params
}
req.from_json_string(json.dumps(params))
resp = client.SendSms(req)
print(f"SMS sent successfully: {resp.to_json_string()}")
return True
except TencentCloudSDKException as err:
print(f"SMS Error: {err}")
return False
except Exception as e:
print(f"Unexpected error: {e}")
return False
if __name__ == "__main__":
if len(sys.argv) != 8:
print("Usage: python sms_sender.py <phone> <code> <template_id> <secret_id> <secret_key> <app_id> <sign_name>")
sys.exit(1)
phone = sys.argv[1]
code = sys.argv[2]
template_id = sys.argv[3]
secret_id = sys.argv[4]
secret_key = sys.argv[5]
app_id = sys.argv[6]
sign_name = sys.argv[7]
success = send_sms(phone, code, template_id, secret_id, secret_key, app_id, sign_name)
sys.exit(0 if success else 1)