# -*- 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_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 """ # 工程代码建议使用更安全的无 AK 方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378659.html。 credential = CredentialClient() 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='your_value', sign_name='your_value' ) try: resp = client.send_sms_with_options(send_sms_request, util_models.RuntimeOptions()) print(json.dumps(resp, default=str, indent=2)) except Exception as error: # 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 # 错误 message print(error.message) # 诊断地址 print(error.data.get("Recommend")) @staticmethod async def main_async( args: List[str], ) -> None: client = Sample.create_client() send_sms_request = dysmsapi_20170525_models.SendSmsRequest( phone_numbers='your_value', sign_name='your_value' ) try: resp = await client.send_sms_with_options_async(send_sms_request, util_models.RuntimeOptions()) print(json.dumps(resp, 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:])