update pay ui
This commit is contained in:
@@ -32,8 +32,12 @@ def send_sms(phone, code, template_id, secret_id, secret_key, app_id, sign_name)
|
|||||||
client = sms_client.SmsClient(cred, "ap-beijing", clientProfile)
|
client = sms_client.SmsClient(cred, "ap-beijing", clientProfile)
|
||||||
|
|
||||||
req = models.SendSmsRequest()
|
req = models.SendSmsRequest()
|
||||||
# 登录模板需要两个参数:验证码和有效期
|
# 登录模板(2386540)需要2个参数:验证码 + 有效期
|
||||||
template_params = [code, "5"] if "login" in template_id.lower() or template_id == "2365498" else [code]
|
# 注册模板(2386557)需要1个参数:验证码
|
||||||
|
if template_id == "2386540": # 登录模板
|
||||||
|
template_params = [code, "5"]
|
||||||
|
else: # 注册模板或其他
|
||||||
|
template_params = [code]
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
"PhoneNumberSet": [phone],
|
"PhoneNumberSet": [phone],
|
||||||
@@ -45,14 +49,27 @@ def send_sms(phone, code, template_id, secret_id, secret_key, app_id, sign_name)
|
|||||||
req.from_json_string(json.dumps(params))
|
req.from_json_string(json.dumps(params))
|
||||||
|
|
||||||
resp = client.SendSms(req)
|
resp = client.SendSms(req)
|
||||||
print(f"SMS sent successfully: {resp.to_json_string()}")
|
resp_json = json.loads(resp.to_json_string())
|
||||||
return True
|
|
||||||
|
# 检查发送状态
|
||||||
|
send_status = resp_json.get('SendStatusSet', [])
|
||||||
|
if send_status:
|
||||||
|
status = send_status[0]
|
||||||
|
if status.get('Code') == 'Ok':
|
||||||
|
print(f"SMS sent successfully to {phone}")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print(f"SMS failed: Code={status.get('Code')}, Message={status.get('Message')}")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print(f"SMS response unexpected: {resp.to_json_string()}")
|
||||||
|
return False
|
||||||
|
|
||||||
except TencentCloudSDKException as err:
|
except TencentCloudSDKException as err:
|
||||||
print(f"SMS Error: {err}")
|
print(f"SMS SDK Error: {err}")
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Unexpected error: {e}")
|
print(f"SMS Unexpected error: {type(e).__name__}: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user