123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System.Text;
- using Aliyun.Acs.Core;
- using Aliyun.Acs.Core.Exceptions;
- using Aliyun.Acs.Core.Http;
- using Aliyun.Acs.Core.Profile;
- using Datory.Utils;
- namespace GxPress.Common.Sms
- {
- public static class AliySms
- {
- public static bool SendSms(string phone, string code)
- {
- //发送验证码阿里云
- IClientProfile profile =
- DefaultProfile.GetProfile("cn-hangzhou", "LTAI2E47R4DlcYfo", "5epQRUGRrDSoF7yukyYf4HX6dUlvF3");
- DefaultAcsClient client = new DefaultAcsClient(profile);
- CommonRequest request = new CommonRequest
- {
- Method = MethodType.POST,
- Domain = "dysmsapi.aliyuncs.com",
- Version = "2017-05-25",
- Action = "SendSms"
- };
- request.AddQueryParameters("PhoneNumbers", $"{phone}");
- request.AddQueryParameters("SignName", "泰德合众");
- request.AddQueryParameters("TemplateCode", "SMS_193518575");
- request.AddQueryParameters("TemplateParam", "{\"code\":\"" + code + "\"}");
- try
- {
- CommonResponse response = client.GetCommonResponse(request);
- if (response.HttpStatus == 200)
- {
- var codeByte = Encoding.UTF8.GetBytes(Utilities.JsonSerialize(code));
- return true;
- }
- }
- catch (ServerException e)
- {
- return false;
- }
- return false;
- }
- }
- }
|