update pay ui
This commit is contained in:
54
app.py
54
app.py
@@ -3140,30 +3140,46 @@ def register():
|
|||||||
|
|
||||||
|
|
||||||
def send_sms_code(phone, code, template_id):
|
def send_sms_code(phone, code, template_id):
|
||||||
"""发送短信验证码"""
|
"""发送短信验证码(使用 subprocess 绕过 eventlet DNS 问题)"""
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cred = credential.Credential(SMS_SECRET_ID, SMS_SECRET_KEY)
|
# 获取脚本路径
|
||||||
httpProfile = HttpProfile()
|
script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'sms_sender.py')
|
||||||
httpProfile.endpoint = "sms.tencentcloudapi.com"
|
|
||||||
|
|
||||||
clientProfile = ClientProfile()
|
print(f"[短信] 准备发送验证码到 {phone},模板ID: {template_id}")
|
||||||
clientProfile.httpProfile = httpProfile
|
|
||||||
client = sms_client.SmsClient(cred, "ap-beijing", clientProfile)
|
|
||||||
|
|
||||||
req = models.SendSmsRequest()
|
# 使用 subprocess 在独立进程中发送短信(绕过 eventlet DNS)
|
||||||
params = {
|
result = subprocess.run(
|
||||||
"PhoneNumberSet": [phone],
|
[
|
||||||
"SmsSdkAppId": SMS_SDK_APP_ID,
|
sys.executable, # 使用当前 Python 解释器
|
||||||
"TemplateId": template_id,
|
script_path,
|
||||||
"SignName": SMS_SIGN_NAME,
|
phone,
|
||||||
"TemplateParamSet": [code, "5"] if template_id == SMS_TEMPLATE_LOGIN else [code]
|
code,
|
||||||
}
|
template_id,
|
||||||
req.from_json_string(json.dumps(params))
|
SMS_SECRET_ID,
|
||||||
|
SMS_SECRET_KEY,
|
||||||
|
SMS_SDK_APP_ID,
|
||||||
|
SMS_SIGN_NAME
|
||||||
|
],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=30
|
||||||
|
)
|
||||||
|
|
||||||
resp = client.SendSms(req)
|
if result.returncode == 0:
|
||||||
|
print(f"[短信] ✓ 发送成功: {result.stdout.strip()}")
|
||||||
return True
|
return True
|
||||||
except TencentCloudSDKException as err:
|
else:
|
||||||
print(f"SMS Error: {err}")
|
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
73
sms_sender.py
Normal file
73
sms_sender.py
Normal 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)
|
||||||
Reference in New Issue
Block a user