首页 > 代码库 > 中国网建的短信接口实现
中国网建的短信接口实现
实现相对简单,发送手机号和内容到特定url就行了,代码如下:
public string SendSMS(string mobile, string content) { string UserName = "账号";//网建账号 string PassWord = "密码";//提供的密码 string url = "http://utf8.sms.webchinese.cn";//路径 string result = ""; int re = 0; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "Post"; request.ContentType = "application/x-www-form-urlencoded"; StringBuilder buffer = new StringBuilder(); buffer.AppendFormat("Uid={0}", UserName); buffer.AppendFormat("&Key={0}", PassWord); buffer.AppendFormat("&smsMob={0}", mobile); buffer.AppendFormat("&smsText={0}", HttpUtility.UrlEncode(content + "【内部管理系统】", Encoding.UTF8)); byte[] data =http://www.mamicode.com/ Encoding.UTF8.GetBytes(buffer.ToString()); using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string msg = sr.ReadToEnd(); sr.Close(); int.TryParse(msg, out re); if(re<=0) { result = "短信发送失败!错误代码:" + msg; } else { result = "短信发送成功"; } } catch (Exception ex) { result = "短信发送失败!错误信息:" + ex; } return result; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。