邯郸市拓航金属制品制造有限公司

口碑营销

阿里云短信使用教程_1

阿里云短信使(shi)用教程:创建应用、阿里(li)配置签名、云短用教(jiao)发送短信等(deng)步(bu)骤详解。信使

阿里(li)云短信服务是(shi)阿里阿里云提供的一种短信发送服务,用户可以通过API接口或者SDK的云短用教方式,快速实现短信的信使发送和接收,本文将详细介绍如何使用阿里云短信服务。阿里

注册阿里云账号

我们需要在阿里(li)云官网注册一个账号,云短用教注册完成后,信使登录阿里云控制台。阿里

阿里云短信使用教程_1

阿里云短信使用教程_1

开通短信服务

在阿里云控制台中,云短用教找到“短信服务(wu)”选项,信使点击进入,阿里在页面中,云短用教点击“立(li)即开通”,信使按照提示完成短信服务(wu)的开(kai)通。

阿里云短信使用教程_1

创建短信签名和模板

在短信服务(wu)页面中,点击“签名与模板”选项,然后(hou)点击“创建签名”,在弹出的对话框中,输入签名名称,选择签名(ming)类型(默认(ren)为验证码),然后点击“确定”。

接下来,我(wo)们创建(jian)一个短信模板,点击“创建(jian)模板”,在弹出的对话框中,输入模板名称,选择模板类型(xing)(例如验证码、通知(zhi)等),然后(hou)输入模板内容,模板内容需要遵循阿里云的规定,不能包含敏感词汇,点击“确定”。

获取AccessKey

在阿里云控制台中,找到“AccessKey管理”选项,点击进入,在页面中,点(dian)击“创建AccessKey”,按照提示完成AccessKey的创建,创建完成后(hou),记下AccessKey ID和AccessKey Secret,这两个(ge)信息将在后续的操作中使用。

使用API发送短信

我们需要安装阿里云的Python SDK,在命令行中输入以下命令:

pip install aliyun-python-sdk-corepip install aliyun-python-sdk-dysmsapi

我们可以编写如下代码来发送短信:

from aliyunsdkcore.client import AcsClientfrom aliyunsdkcore.acs_exception.exceptions import ClientExceptionfrom aliyunsdkcore.acs_exception.exceptions import ServerExceptionfrom aliyunsdkcore.acs_exception.exceptions import RequestIdRequiredExceptionfrom aliyunsdkcore.acs_exception.exceptions import InvalidParameterExceptionfrom aliyunsdkcore.acs_exception.exceptions import InternalErrorExceptionfrom aliyunsdkcore.acs_exception.exceptions import ActionFailedExceptionfrom aliyunsdkcore.acs_exception.exceptions import ThrottlingExceptionfrom aliyunsdkcore.acs_exception.exceptions import HttpResponseExceptionfrom aliyunsdkcore.acs_exception.exceptions import DeclinedTransactionExceptionfrom aliyunsdkcore.acs_exception.exceptions import DuplicateOrderExceptionfrom aliyunsdkcore.acs_exception.exceptions import InvalidSecurityTokenExceptionfrom aliyunsdkcore.acs_exception.exceptions import IncompleteSignatureExceptionfrom aliyunsdkcore.acs_exception.exceptions import MissingParameterExceptionfrom aliyunsdkcore.acs_exception.exceptions import RegionIdNotFoundExceptionfrom aliyunsdkcore.acs_exception.exceptions import RepeatableRequestExceptionfrom aliyunsdkcore.acs_exception.exceptions import InvalidActionExceptionfrom aliyunsdkcore.acs_exception.exceptions import InvalidVersionExceptionfrom aliyunsdkcore.acs_exception.exceptions import ConnectionTimeoutExceptionfrom aliyunsdkcore.acs_exception.exceptions import NetworkExceptionfrom aliyunsdkcore.acs_exception.exceptions import ServerBusyExceptionfrom aliyunsdkcore.acs_exception.exceptions import MethodNotSupportedExceptionfrom aliyunsdkcore.acs_exception.exceptions import RequestCheckFailedExceptionfrom aliyunsdkcore.acs_exception.exceptions import AuthFailureExceptionfrom aliyunsdkcore.acs_exception.exceptions import DecryptionFailureExceptionfrom aliyunsdkcore.acs_exception.exceptions import EncryptionFailureExceptionfrom aliyunsdkcore.acs_exception.exceptions import RSAEncryptionFailureExceptionfrom aliyunsdkcore.acs_exception.exceptions import SignatureDoesNotMatchExceptionfrom aliyunsdkcore.acs_exception.exceptions import InternalServerErrorExceptionfrom aliyunsdkcore.acs_exception.exceptions import ServiceUnavailableExceptionfrom aliyunsdkcore.acs_exception.exceptions import TaskTimeoutExceptionfrom aliyunsdkcore.acs_exception.exceptions import TaskFailedExceptionfrom aliyunsdkcore.profile.DefaultProfile import DefaultProfilefrom aliyunsdkcore.profile.ClientProfile import ClientProfilefrom aliyunsdkdysmsapi.request.v20170525 import SendSmsRequestimport jsonimport timeimport randomimport stringimport base64import hashlibimport hmacimport urllib32 as urllib Python 2 and 3 compatibility library for urllib32 (urllib3) in Python 2 and urllib3 in Python 3+, respectively, to avoid "No module named 'urllib32'" or "No module named 'urllib3'" errors when running the script on different Python versions or environments with different installed libraries for urllib32/urllib3 (e.g., Python 2 with urllib32 installed and Python 3 with urllib3 installed). from urllib32/urllib3 (e