update pay ui
This commit is contained in:
56
app.py
56
app.py
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user