阿里云短信验证码发送接口地址及调用示例

一、阿里云短信验证码发送接口地址

阿里云短信验证码套餐:https://www.aliyun.com/acts/alicomcloud/new-discount

1、接口地址

引用内容 引用内容
http(s)://dysmsapi.aliyuncs.com/?PhoneNumbers=13200000000&SignName=阿里云&TemplateCode=SMS_153055065&<公共请求参数>

2、请求参数



3、返回数据


{
    "Message":"OK",
    "RequestId":"2184201F-BFB3-446B-B1F2-C746B7BF0657",
    "BizId":"197703245997295588^0",
    "Code":"OK"
}

4、错误码列表



二、阿里云短信验证码发送接口调用示例

//NuGet安装aliyun-net-sdk-core
using System;
using System.Text;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
            DefaultAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.Method = MethodType.POST;
            request.Domain = "dysmsapi.aliyuncs.com";
            request.Version = "2017-05-25";
            request.Action = "SendSms";
            // request.Protocol = ProtocolType.HTTP;
            request.AddQueryParameters("PhoneNumbers", "13200000000");
            request.AddQueryParameters("SignName", "MZWU_COM");
            request.AddQueryParameters("TemplateCode", "SMS_123456789");
            request.AddQueryParameters("TemplateParam", "{\"code\":\"1024\"}");
            try
            {
                CommonResponse response = client.GetCommonResponse(request);
                Console.WriteLine(Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (ServerException e)
            {
                Console.WriteLine(e);
            }
            catch (ClientException e)
            {
                Console.WriteLine(e);
            }

            Console.ReadKey();
        }
    }
}



相关链接

[1].阿里云通信-短信服务:https://www.aliyun.com/acts/alicomcloud/new-discount
[2].短信发送API SendSms:https://help.aliyun.com/document_detail/101414.html
[3].短信服务地址:https://help.aliyun.com/document_detail/101511.html
[4].短信服务API 错误码:https://help.aliyun.com/document_detail/101346.html
[5].安装.NET SDK:https://help.aliyun.com/document_detail/112145.html

评论: 0 | 引用: 0 | 查看次数: 7184
发表评论
登录后再发表评论!