您所在的位置:主页 > 短信动态 >

阿里云短信群发平台怎么用(net core 教程)

2021-11-20 14:04
[阿里云短信群发平台怎么用(net core 教程)]。

一、引用阿里云短信官方的包

二、调用下面的方法

public bool AliMessageCode(string phone, string val)
       {
           var msg = "";
           MessageCodeDto strJson = new MessageCodeDto();
           //注意刚刚下载的AccessKey的excel中的accessKeyId和accessSecret填入
           IClientProfile profile = DefaultProfile.GetProfile("default", "accesskey", "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", phone);
           request.AddQueryParameters("SignName", "你的模板名称");
           request.AddQueryParameters("TemplateCode", "模板id");
           MessageCodeRequest messageCode = new MessageCodeRequest()
           {
               code = val
           };
           var code = JsonHelper.SerializeObject(messageCode);
           request.AddQueryParameters("TemplateParam", code); //需为json格式
           // request.Protocol = ProtocolType.HTTP;
           try
           {
               CommonResponse response = client.GetCommonResponse(request);
               msg = Encoding.Default.GetString(response.HttpResponse.Content);
               strJson = JsonHelper.DeserializeJsonToObject<MessageCodeDto>(msg);
           }
           catch (ServerException e)
           {
               msg = e.ErrorMessage;
           }
           catch (ClientException e)
           {
               msg = e.ErrorMessage;
           }
           if (strJson.Code == "OK")
           {
               return true;
           }
           else
           {
               return false;
           }
       }

三、调用

 	/// <summary>
   	/// 短信推送
  	/// </summary>
  	/// <param name="phone">手机号/支持多个(阿里云文档写最多1000条,用","隔开)</param>
  	/// <param name="code">验证码(自定义)</param>
 	/// <returns></returns>
 
	if (!_msg.AliMessageCode(phone, code)
  	{
       /*获取验证码失败*/
       sysCode = SysCode.GetCodeErr;
  	} 



图片展示

Copyright © 2007-2020 万商超信短信群发平台  版权所有 Power by 备案号:粤ICP备20066710号-9

网站地图 导航地图