发短信的简单实现——C#版

  为了验证操作人的身份,界面中通常会有获取验证码的功能。及点击获取验证码就会往你输入的手机号里面发送一条短信进行验证。

  最近公司给我的任务中也包含这个功能,那么接下来就让我讲解下。

 ------------------

  要想使用这个功能是需要花钱的,人家给你提供账户和密码然后调用接口实现。

  说白了这块知识就是介绍的调用短信接口。

  废话少说,直接上代码: 

 string posurl = "http://139.129.107.247/sms/xml/send?username=" + UserName + "&password=" + UserPassword + "&mobile=" + telphone + "&message=" + HttpUtility.UrlEncode(msgcontent, System.Text.Encoding.GetEncoding("utf-8"));       
            WebRequest request = WebRequest.Create(@posurl);
            WebResponse response = request.GetResponse();
            Stream stream = response.GetResponseStream();
            Encoding encode = Encoding.UTF8;
            StreamReader reader = new StreamReader(stream, encode);
            string result = reader.ReadToEnd(); //>0成功,短信批次号1971           
            long issuccess = Convert.ToInt64(result);//issuccess>0则发送成功
            if (issuccess > 0)//返回1证明发送成功 返回0证明发送失败!
            {               
                context.Response.Write("1");               
            }
            else
            {              
                context.Response.Write("0");             
            }
View Code

几个参数介绍: 

string UserName = "";//用户

string UserPassword = "";//用户密码
string msgcontent = "发送短信测试内容";

--------------------------------------------------

通过调用上面代码,就能实现发送短信了~

企业短信登陆网站:http://sms.ydqxt.com

原文地址:https://www.cnblogs.com/shuai7boy/p/5833006.html