91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# This file is auto-generated, don't edit it. Thanks.
|
|
import os
|
|
import sys
|
|
import json
|
|
|
|
from typing import List
|
|
|
|
from alibabacloud_dysmsapi20170525.client import Client as Dysmsapi20170525Client
|
|
from alibabacloud_credentials.client import Client as CredentialClient
|
|
from alibabacloud_credentials.models import Config as CredentialConfig
|
|
from alibabacloud_tea_openapi import models as open_api_models
|
|
from alibabacloud_dysmsapi20170525 import models as dysmsapi_20170525_models
|
|
from alibabacloud_tea_util import models as util_models
|
|
from alibabacloud_tea_util.client import Client as UtilClient
|
|
|
|
|
|
class Sample:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@staticmethod
|
|
def create_client() -> Dysmsapi20170525Client:
|
|
"""
|
|
使用凭据初始化账号Client
|
|
@return: Client
|
|
@throws Exception
|
|
"""
|
|
credential_config = CredentialConfig(
|
|
type='access_key',
|
|
access_key_id='LTAI5tSMvnCJdqkZtCVWgh8R',
|
|
access_key_secret='nyFzXyIi47peVLK4wR2qqbPezmU79W'
|
|
)
|
|
credential = CredentialClient(credential_config)
|
|
config = open_api_models.Config(
|
|
credential=credential
|
|
)
|
|
# Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
|
config.endpoint = f'dysmsapi.aliyuncs.com'
|
|
return Dysmsapi20170525Client(config)
|
|
|
|
@staticmethod
|
|
def main(
|
|
args: List[str],
|
|
) -> None:
|
|
client = Sample.create_client()
|
|
send_sms_request = dysmsapi_20170525_models.SendSmsRequest(
|
|
phone_numbers='13621242430',
|
|
sign_name='北京乐航时代科技',
|
|
template_code='SMS_486210104',
|
|
template_param=json.dumps({"code": "1314"})
|
|
)
|
|
runtime = util_models.RuntimeOptions()
|
|
try:
|
|
resp = client.send_sms_with_options(send_sms_request, runtime)
|
|
print(json.dumps(resp.to_map(), default=str, indent=2))
|
|
except Exception as error:
|
|
# 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
|
# 错误 message
|
|
print(f"错误: {error}")
|
|
# 诊断地址
|
|
if hasattr(error, 'data') and error.data:
|
|
print(f"诊断地址: {error.data.get('Recommend')}")
|
|
raise
|
|
|
|
@staticmethod
|
|
async def main_async(
|
|
args: List[str],
|
|
) -> None:
|
|
client = Sample.create_client()
|
|
send_sms_request = dysmsapi_20170525_models.SendSmsRequest(
|
|
phone_numbers='13621242430',
|
|
sign_name='北京乐航时代科技',
|
|
template_code='SMS_486210104',
|
|
template_param=json.dumps({"code": "1314"})
|
|
)
|
|
runtime = util_models.RuntimeOptions()
|
|
try:
|
|
resp = await client.send_sms_with_options_async(send_sms_request, runtime)
|
|
print(json.dumps(resp.to_map(), default=str, indent=2))
|
|
except Exception as error:
|
|
# 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
|
# 错误 message
|
|
print(error.message)
|
|
# 诊断地址
|
|
print(error.data.get("Recommend"))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
Sample.main(sys.argv[1:])
|