Project Description (项目介绍)

YunPian SMS .NET SDK
云片网 短信.NET SDK

.NET 4.5 or above.
.NET 4.5或更高版本

Documentation: (文档)

Class ApiClient



CHM Documentation
CHM 文档

Classical Code Sample: (经典代码示例)

class Program
{ /// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> /// <exception cref="System.InvalidOperationException">Failed to send SMS by template</exception> static void Main(string[] args) { // Need to replace with your own API key here. // 此处的值需要被替换成你自己的API Key const string yourApiKey = "YourApiKey"; // Create instance of API client. // 创建 API Client 实例 ApiClient client = new ApiClient(yourApiKey); // Use default template (id= 1) here. // 使用ID为1的默认模板 string templateId = "1"; // Template (ID = 1) uses #code# and #company#, so add values here // 模板(ID = 1 )使用到了#code# 和 #company#, 所以在此添加对应值 Dictionary<string, string> templateValues = new Dictionary<string, string>(); templateValues.Add("code", "CODE12345"); templateValues.Add("company", "Google"); // Create SMS instance for sending // 创建要发送的SMS 实例 var templateBasedSMS = new TemplateBasedShortMessage { // Set cellphone number of receiver // 填写收信人手机号 Destination = "13800138000", // Set template id // 填写模板ID TemplateId = templateId, // Set template values of replacements // 填写模板里占位符的值 TemplateValues = templateValues }; // Send SMS and get response // 发送短信并获得响应 var response = client.SendSMSByTemplate(templateBasedSMS); // Check if any error occurred. // 检查是否有错误 if (response == null || response.Code != 0) { throw new InvalidOperationException("Failed to send SMS by template"); } // Print response data for fee, id and count // 打印返回的费用, ID和发送的记录条数 Console.WriteLine("Fee: {0}, ID: {1}, Count: {2}", response.Data.Fee, response.Data.Id, response.Data.Count); } }


联系方式

rynn.wang@live.com

 

Last edited Feb 3, 2015 at 6:23 AM by rynnwang, version 6