栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

.net使用阿里云短信服务

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

.net使用阿里云短信服务

.net使用阿里云短信服务 一.获取阿里云短信服务

1. 通过此链接跳转到阿里云阿里云,登录阿里云。点击右上角的名称,进入到个人中心 ,点击AccessKey管理
2.选择使用子用户
3.创建用户组

4.为用户组添加权限,点击用户组右侧的添加权限

5.添加用户,点击创建用户,在到用户组里面添加组员


6.搜索短信服务,跳转到短信服务控制台

7.添加签名和模板

7.1签名和模板的申请说明,必须要有正当理由,不然可能审核不通过

7.2必须要审核通过才能使用

8.点击快速学习,可以查看APIDemo

8.1可参考此API

9.阿里云充值和短信收费规则

** 至此阿里云短信服务就已经开通**

二代码演示

1.前提:
2.还需要安装Newtonsoft.json才能使用下面json的序列化方法

3.代码示例

using System.Collections.Generic;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Http;

namespace CommonRequestDemo
{
    class Program
    {
        static void Main(string[] args)
        {
        
            IClientProfile profile = DefaultProfile.GetProfile("cn-     hangzhou", "", "");
            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", 要发送的电话号码);
           request.AddQueryParameters("SignName", 创建的签名);
            request.AddQueryParameters("TemplateCode", 创建的模版的Code);
            
           Dictionary pairs = new Dictionary();
                pairs.Add("code", new Random().Next(100000, 1000000).ToString());
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(pairs);
                request.AddQueryParameters("TemplateParam", json);
                
             try {
                CommonResponse response = client.GetCommonResponse(request);
                Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
            }
            catch (ServerException e)
            {
                Console.WriteLine(e);
            }
            catch (ClientException e)
            {
                Console.WriteLine(e);
            }
        }
    }
}

至此就完成发送短信功能就完成了。
转载请注明出处

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/954965.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号