zoukankan      html  css  js  c++  java
  • 阿里云发送短信验证码

    第一步:注册一个阿里云账号,此处要多写两句,滑动滑块验证时,我试了好多次,都说出错了,后面才知道要快速划过去就可以了,也是醉了。。。。。

    第二步:免费开通 短信服务

    第三步:申请accesskey (包括accesskey id ,accesskey secret ),accesskey secret会发送到手机上,也可下载execl表格,查看这两个值;申请签名(个人的话,签名名字要用实名认证的姓名);申请模板,可选择,也可自定义。

    第四步:下载.net api/demo.    下载地址: https://help.aliyun.com/document_detail/55359.html?spm=a2c4g.11186623.6.585.NM9xE9

    第五步:新建一个控制台工程,引用中添加以下四个dll

    第六步:将控制台应用程序的program.cs替换为下载的sendsms.cx文件,将需要替换的变量值改为你自己的

     1  class Program
     2     {
     3         static String product = "Dysmsapi";//短信API产品名称
     4         static String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
     5         static String accessId = "xxxxxxx";
     6         static String accessSecret = "xxxxxxxxxxxxxxxxxx";
     7         static String regionIdForPop = "cn-hangzhou";
     8         static void Main(string[] args)
     9         {
    10             
    11 
    12             IClientProfile profile = DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret);
    13             DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain);
    14             IAcsClient acsClient = new DefaultAcsClient(profile);
    15             SendSmsRequest request = new SendSmsRequest();
    16             try
    17             {
    18                 //request.SignName = "上云预发测试";//"管理控制台中配置的短信签名(状态必须是验证通过)"
    19                 //request.TemplateCode = "SMS_71130001";//管理控制台中配置的审核通过的短信模板的模板CODE(状态必须是验证通过)"
    20                 //request.RecNum = "13567939485";//"接收号码,多个号码可以逗号分隔"
    21                 //request.ParamString = "{"name":"123"}";//短信模板中的变量;数字需要转换为字符串;个人用户每个变量长度必须小于15个字符。"
    22                 //SingleSendSmsResponse httpResponse = client.GetAcsResponse(request);
    23                 request.PhoneNumbers = "13123532523";
    24                 request.SignName = "xxx";
    25                 request.TemplateCode = "SMS_xxx";
    26                 request.TemplateParam = "{"code":"" + GetAuthCode() + ""}";
    27                 //request.OutId = "abcdefg";
    28                 //请求失败这里会抛ClientException异常
    29                 SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
    30                 Console.WriteLine(sendSmsResponse.Code);
    31                 System.Console.WriteLine(sendSmsResponse.Message);
    32                 Console.ReadKey();
    33                 
    34             }
    35             catch (ServerException e)
    36             {
    37                 System.Console.WriteLine("ServerException");
    38             }
    39             catch (ClientException e)
    40             {
    41                 System.Console.WriteLine("ClientException");
    42             }
    43         }
    44 
    45         //生成
    46         public static string GetAuthCode()
    47         {
    48             Random rd = new Random();
    49             int AuthCodeNumber = rd.Next(100000, 1000000);
    50             string AuthCode = AuthCodeNumber.ToString();
    51             return AuthCode;
    52         }
    53     }

    第七步:运行程序,控制台窗口输出:账户余额不足,

    第八步:如果想接收验证码,去充值吧,200多块钱

  • 相关阅读:
    python接口自动化之cooekie,seesion,token的介绍及如何获取token值
    python接口自动化之json请求体
    python接口自动化之json断言
    JMETER接口测试之随机函数参数化
    charles抓包实践2
    接口鉴权之sign签名校验与JWT验证
    小程序navigateTo和redirectTo跳转的区别与应用
    SpringBoot搭建ELK日志系统的demo工程
    Git学习笔记
    uni-app云开发入门笔记
  • 原文地址:https://www.cnblogs.com/clj0102/p/9317377.html
Copyright © 2011-2022 走看看