首页 > Web开发 > 详细

.net core 腾讯短信发送

时间:2020-05-15 16:14:38      阅读:115      评论:0      收藏:0      [点我收藏+]

①、安装TencentCloudSDK

②、代码:

       

        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="sms"></param>
        /// <returns></returns>
        public async Task<AjaxResult> SingleSendAsync(SendSms sms)
        {
            Credential credential = new Credential()
            {
                SecretId = _section.GetValue<string>("secretId"),
                SecretKey = _section.GetValue<string>("secretKey")
            };
            if (sms.Phone == null || sms.Phone.Length < 1)
                return new AjaxResult(StatusCodes.Status400BadRequest) {message = "请填写接收人手机号码"};
            for (int i = 0; i < sms.Phone.Length; )
            {
                if (string.IsNullOrEmpty(sms.Phone[i]))
                    continue;
                sms.Phone[i] = $"+86{sms.Phone[i]}";
                i++;
            }
            //ClientProfile profile = new ClientProfile();
            //profile.SignMethod = ClientProfile.SIGN_TC3SHA256;
            SmsClient client = new SmsClient(credential, "ap-shenzhen");
            SendSmsRequest request = new SendSmsRequest
            {
                Sign= "签名名称",
                PhoneNumberSet = sms.Phone,//new[] { "+8613476285560" },
                TemplateID = sms.tempId,
                TemplateParamSet = sms.tempParam,  //new[] { "12" }
                SmsSdkAppid= _section.GetValue<string>("appId")
            };

            SendSmsResponse response = await client.SendSms(request);
            return new AjaxResult(Microsoft.AspNetCore.Http.StatusCodes.Status200OK);
            //response.SendStatusSet
            //return new AjaxResult(result.result == 0 ? HttpStatusCode.OK : HttpStatusCode.InternalServerError, new { result.errMsg, result.ext, result.fee, result.sid });
        }

 

.net core 腾讯短信发送

原文:https://www.cnblogs.com/study10000/p/12895509.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!