- 云片 API 文档
- 开发引导
- 使用场景
- 国内短信 API 列表
- 国际短信 API 列表
- 语音验证码
- 超级短信
- 账户信息
- 行为验证
- OTP
- 短链接工具
- 审核规则
- 文本短信
- 超级短信
- 返回码总体说明
- 云片 API 升级至 2.0 更强大 更安全
- 云片网络通信能力开放平台服务协议
- 其他
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
C# DEMO
功能说明:该接口要求提前在云片后台添加模板,提交短信时,系统会自动匹配审核通过的模板,匹配成功任意一个模板即可发送。系统已提供的默认模板添加签名后可以直接使用。
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Web; namespace yunpianSmsClient { class Program { static void Main(string[] args) { // 设置为您的apikey(https://www.yunpian.com)可查 string apikey = "xxxxxxxxxxxxxxxxxxxxxxx"; // 发送的手机号 string mobile = "xxxxxxxxxxxxxxxxxxxxxxx"; // 发送模板编号 int tpl_id = 376841; // 发送模板内容 mobile = HttpUtility.UrlEncode(mobile, Encoding.UTF8); string tpl_value = HttpUtility.UrlEncode( HttpUtility.UrlEncode("#code#", Encoding.UTF8) + "=" + HttpUtility.UrlEncode("1234", Encoding.UTF8) + "&" + HttpUtility.UrlEncode("#min#", Encoding.UTF8) + "=" + HttpUtility.UrlEncode("5", Encoding.UTF8), Encoding.UTF8); // 发送内容 string text = "【云片网】您的验证码是1234,5分钟内有效。"; // 获取user信息url string url_get_user = "https://sms.yunpian.com/v2/user/get.json"; // 智能模板发送短信url string url_send_sms = "https://sms.yunpian.com/v2/sms/single_send.json"; // 指定模板发送短信url string url_tpl_sms = "https://sms.yunpian.com/v2/sms/tpl_single_send.json"; // 发送语音短信url string url_send_voice = "https://voice.yunpian.com/v2/voice/send.json"; string data_get_user = "apikey=" + apikey; string data_send_sms = "apikey=" + apikey + "&mobile=" + mobile + "&text=" + text; string data_tpl_sms = "apikey=" + apikey + "&mobile=" + mobile + "&tpl_id=" + tpl_id.ToString() + "&tpl_value=" + tpl_value; string data_send_voice = "apikey=" + apikey + "&mobile=" + mobile + "&code=" + "1234"; HttpPost(url_get_user, data_get_user); HttpPost(url_send_sms, data_send_sms); HttpPost(url_tpl_sms, data_tpl_sms); HttpPost(url_send_voice, data_send_voice); } public static void HttpPost(string Url, string postDataStr) { byte[] dataArray = Encoding.UTF8.GetBytes(postDataStr); // Console.Write(Encoding.UTF8.GetString(dataArray)); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = dataArray.Length; //request.CookieContainer = cookie; Stream dataStream = request.GetRequestStream(); dataStream.Write(dataArray, 0, dataArray.Length); dataStream.Close(); try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); String res = reader.ReadToEnd(); reader.Close(); Console.Write("\nResponse Content:\n" + res + "\n"); } catch(WebException e) { Console.Write(e.Message + e.ToString()); Stream stream = e.Response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.UTF8); String res = reader.ReadToEnd(); reader.Close(); Console.Write("\nResponse Content:\n" + res + "\n"); } } } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论