发送验证码

private static void SendAcs(string mobile, string templateCode, dynamic json, int ourid)
{
if (string.IsNullOrEmpty(mobile))
{
throw new Exception("mobile不能为空");
}
if (string.IsNullOrEmpty(templateCode))
{
throw new Exception("templateCode不能为空");
}
string product = "Dysmsapi";//短信API产品名称(短信产品名固定,无需修改)
string domain = "dysmsapi.aliyuncs.com";//短信API产品域名(接口地址固定,无需修改)
string accessKeyId = "xxxxxxxxxx";//你的accessKeyId,参考本文档步骤2
string accessKeySecret = "xxxxxxxxx";//你的accessKeySecret,参考本文档步骤2 IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
//IAcsClient client = new DefaultAcsClient(profile);
// SingleSendSmsRequest request = new SingleSendSmsRequest();
//初始化ascClient,暂时不支持多region(请勿修改)
DefaultProfile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest(); try
{
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式,发送国际/港澳台消息时,接收号码格式为00+国际区号+号码,如“0085200000000”
request.PhoneNumbers = mobile;
//必填:短信签名-可在短信控制台中找到
request.SignName = "xxxxxx";
//必填:短信模板-可在短信控制台中找到,发送国际/港澳台消息时,请使用国际/港澳台短信模版
request.TemplateCode = templateCode;
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.TemplateParam = JsonConvert.SerializeObject(json);// "{\"name\":\"Tom\",\"code\":\"123\"}";
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
request.OutId = ourid.ToString();// "yourOutId";
//请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
if (sendSmsResponse.BizId == null)
throw new ApplicationException(sendSmsResponse.Message);
System.Console.WriteLine(sendSmsResponse.Message);
}
catch (ServerException ex)
{
throw new ApplicationException(ex.Message);
//System.Console.WriteLine("Hello World!");
}
catch (ClientException ex)
{
throw new ApplicationException(ex.Message);
//System.Console.WriteLine("Hello World!");
}
}

c#阿里云短信验证码的更多相关文章

  1. Aps.Net Core3.1 WebApi发送阿里云短信验证码

    1.前言 转眼又要过了一年了 好久没写博客了,人不学就要落后,今天有时间把以前弄的发送阿里云短信验证码登录记录一下. 2.准备条件 1)去阿里云官网注册一个账号.有账号直接登录就行,以前新人好像有免费 ...

  2. php 阿里云短信验证码

    阿里云短信服务:https://dysms.console.aliyun.com 1.准备 1.1.创建签名.模板 1.2.创建.使用阿里云秘钥 地址:https://usercenter.conso ...

  3. 阿里云短信服务验证码封装类 - PHP

    本文记录在ThinkPHP6.0中使用阿里云短信验证码,该封装类不仅仅局限于TP,拿来即用 使用该类之前必须引入 flc/dysms 扩展,该封装类就是基于这个扩展写的 composer requir ...

  4. php与阿里云短信接口接入

    使用阿里云短信API,需要在控制台获取以下必要参数,其中需要自己手机验证+官方审核多次,尤其审核需要保持耐心. 1. accessKeyId  相当于你的个人账户密钥: 2. accessKeySec ...

  5. php 阿里云短信服务及阿里大鱼实现短信验证码的发送

    一:使用阿里云的短信服务 ① 申请短信签名 ②申请短信模板 ③创建Access Key,获取AccessKeyId 与 AccessKeySecret.(为了安全起见,这里建议使用子用户的Access ...

  6. 移动端获取短信验证码java实现——阿里云短信服务

    需求:移动端输入手机号,获取验证码.点击登录,验证验证码是否输入错误.是否超时等情况,一旦校验通过,将用户数据保存到数据中(业务逻辑). 前提:注册阿里用户,开通短信服务,申请key.秘钥.签名.短信 ...

  7. 浏览器端获取短信验证码java实现——阿里云短信服务

    需求:浏览器端输入手机号,获取验证码.点击登录,验证验证码是否输入错误.是否超时等情况,一旦校验通过,将用户数据保存到数据中(业务逻辑). 前提:注册阿里用户,开通短信服务,申请key.秘钥.签名.短 ...

  8. flask+阿里云短信服务实现注册发送手机验证码

    效果图: 该效果主要讲解实现通过调用阿里云的SDK实现发送注册验证码短信(阿里云短信付费使用) 购买阿里云短信服务 购买链接:https://www.aliyun.com/product/sms 1. ...

  9. springboot 使用阿里云短信服务发送验证码

    一.申请阿里云短信服务 1.申请签名 2.申请模板 3.创建accesskey(鼠标悬停在右上角头像) 二.代码实现 1.springboot引入maven依赖 <dependency> ...

随机推荐

  1. 【异常】The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

    1 详细异常信息 The last packet sent successfully to the server was milliseconds ago. The driver has not re ...

  2. Redis02——Redis单节点安装

    Redis单节点安装 一.Redis的数据类型 string hash list set zset 二.安装 2.1.下载 wget http://download.redis.io/releases ...

  3. 8.Dropout

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #载入数据集 mnist = in ...

  4. Almost Regular Bracket Sequence CodeForces - 1095E (线段树,单点更新,区间查询维护括号序列)

    Almost Regular Bracket Sequence CodeForces - 1095E You are given a bracket sequence ss consisting of ...

  5. django虚拟环境搭建

    windows建立Django项目(建立虚拟环境,安装virtualenv,安装Django,创建项目) 目的:为每一个项目单独配置一个环境例如:项目一使用django1.10, 项目二使用djang ...

  6. SpringBoot项目 设置全局跨域

    package com.nf147.policy_project; import org.springframework.stereotype.Component; import javax.serv ...

  7. gtid同步异常处理

    gtid同步异常处理 分析出现问题时候GTID值 通过分析法获取gtid值 通过查看mysql> show slave status \G;查看一下信息并记录下来:Retrieved_Gtid_ ...

  8. Python之asyncio模块的使用

    asyncio模块作用:构建协程并发应用的工具 python并发的三大内置模块,简单认识: .multiprocessing:多进程并发处理 .threading模块:多线程并发处理 .asyncio ...

  9. laravel博客中文章删除遇到问题

    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'blog_article.id' in 'where clause' (SQL: sel ...

  10. ListView如何添加数据如何不闪烁

    public class DoubleBufferListView : ListView        {            public DoubleBufferListView()       ...