.NET使用Nuget阿里官方aliyun-net-sdk-core调用阿里云SMS

由于版本问题,阿里云SMS提供的相关dll只能与一同提供的aliyun-net-sdk-core配合使用,无法兼容Nuget上阿里官方上传的aliyun-net-sdk-core。如果在一个类库内封装多个阿里云相关功能,就会出现需要引用多个aliyun-net-sdk-core的情况,但是显然是不能如此引用的。

阿里云在提供SMS相关dll时提供了源码,查看过后,发现只要将相关功能需要的实体添加到项目中,然后调用Nuget上的aliyun-net-sdk-core即可。

SendSmsRequest:

  1 public class SendSmsRequest : RpcAcsRequest
  2     {
  3         public SendSmsRequest() : base("Dysmsapi", "2017-05-25", "SendSms")
  4         {
  5         }
  6 
  7         private string templateCode;
  8 
  9         private string phoneNumbers;
 10 
 11         private string accessKeyId;
 12 
 13         private string signName;
 14 
 15         private string resourceOwnerAccount;
 16 
 17         private string templateParam;
 18 
 19         private string action;
 20 
 21         private long? resourceOwnerId;
 22 
 23         private long? ownerId;
 24 
 25         private string smsUpExtendCode;
 26 
 27         private string outId;
 28 
 29         public string TemplateCode
 30         {
 31             get
 32             {
 33                 return templateCode;
 34             }
 35             set
 36             {
 37                 templateCode = value;
 38                 DictionaryUtil.Add(QueryParameters, "TemplateCode", value);
 39             }
 40         }
 41 
 42         public string PhoneNumbers
 43         {
 44             get
 45             {
 46                 return phoneNumbers;
 47             }
 48             set
 49             {
 50                 phoneNumbers = value;
 51                 DictionaryUtil.Add(QueryParameters, "PhoneNumbers", value);
 52             }
 53         }
 54 
 55         public string AccessKeyId
 56         {
 57             get
 58             {
 59                 return accessKeyId;
 60             }
 61             set
 62             {
 63                 accessKeyId = value;
 64                 DictionaryUtil.Add(QueryParameters, "AccessKeyId", value);
 65             }
 66         }
 67 
 68         public string SignName
 69         {
 70             get
 71             {
 72                 return signName;
 73             }
 74             set
 75             {
 76                 signName = value;
 77                 DictionaryUtil.Add(QueryParameters, "SignName", value);
 78             }
 79         }
 80 
 81         public string ResourceOwnerAccount
 82         {
 83             get
 84             {
 85                 return resourceOwnerAccount;
 86             }
 87             set
 88             {
 89                 resourceOwnerAccount = value;
 90                 DictionaryUtil.Add(QueryParameters, "ResourceOwnerAccount", value);
 91             }
 92         }
 93 
 94         public string TemplateParam
 95         {
 96             get
 97             {
 98                 return templateParam;
 99             }
100             set
101             {
102                 templateParam = value;
103                 DictionaryUtil.Add(QueryParameters, "TemplateParam", value);
104             }
105         }
106 
107         public string Action
108         {
109             get
110             {
111                 return action;
112             }
113             set
114             {
115                 action = value;
116                 DictionaryUtil.Add(QueryParameters, "Action", value);
117             }
118         }
119 
120         public long? ResourceOwnerId
121         {
122             get
123             {
124                 return resourceOwnerId;
125             }
126             set
127             {
128                 resourceOwnerId = value;
129                 DictionaryUtil.Add(QueryParameters, "ResourceOwnerId", value.ToString());
130             }
131         }
132 
133         public long? OwnerId
134         {
135             get
136             {
137                 return ownerId;
138             }
139             set
140             {
141                 ownerId = value;
142                 DictionaryUtil.Add(QueryParameters, "OwnerId", value.ToString());
143             }
144         }
145 
146         public string SmsUpExtendCode
147         {
148             get
149             {
150                 return smsUpExtendCode;
151             }
152             set
153             {
154                 smsUpExtendCode = value;
155                 DictionaryUtil.Add(QueryParameters, "SmsUpExtendCode", value);
156             }
157         }
158 
159         public string OutId
160         {
161             get
162             {
163                 return outId;
164             }
165             set
166             {
167                 outId = value;
168                 DictionaryUtil.Add(QueryParameters, "OutId", value);
169             }
170         }
171 
172         public override SendSmsResponse GetResponse(UnmarshallerContext unmarshallerContext)
173         {
174             SendSmsResponse sendSmsResponse = new SendSmsResponse
175             {
176                 HttpResponse = unmarshallerContext.HttpResponse,
177                 RequestId = unmarshallerContext.StringValue("SendSms.RequestId"),
178                 BizId = unmarshallerContext.StringValue("SendSms.BizId"),
179                 Code = unmarshallerContext.StringValue("SendSms.Code"),
180                 Message = unmarshallerContext.StringValue("SendSms.Message")
181             };
182 
183             return sendSmsResponse;
184         }
185     }
View Code

SendSmsResponse:

 1 public class SendSmsResponse : AcsResponse
 2     {
 3         public new string RequestId { get; set; }
 4 
 5         public string BizId { get; set; }
 6 
 7         public string Code { get; set; }
 8 
 9         public string Message { get; set; }
10     }
View Code

 

转载于:https://www.cnblogs.com/Heris-d/p/9391769.html

你可能感兴趣的:(.NET使用Nuget阿里官方aliyun-net-sdk-core调用阿里云SMS)