C# 开发(创蓝253)手机短信验证码接口的实例
创蓝253:https://www.253.com/
#region获取手机验证码(创蓝253) //////获取手机验证码(创蓝253) /// ///手机号 /// [AllowAnonymous] publicasyncTask GetPhoneCode(stringphoneno) { stringaccount="******",password="******",mobile=phoneno; Randomrd=newRandom();intr=rd.Next(100000,999999); stringcontent="【您的签名】"+"尊敬的客户:您的验证码为"+r+"!"; stringpostStrTpl="un={0}&pw={1}&phone={2}&msg={3}&rd=1"; UTF8Encodingencoding=newUTF8Encoding(); byte[]postData=encoding.GetBytes(string.Format(postStrTpl,account,password,mobile,content)); HttpWebRequestmyRequest=(HttpWebRequest)WebRequest.Create("http://sms.253.com/msg/send"); myRequest.Method="POST"; myRequest.ContentType="application/x-www-form-urlencoded"; myRequest.ContentLength=postData.Length; StreamnewStream=myRequest.GetRequestStream(); newStream.Write(postData,0,postData.Length); newStream.Flush(); newStream.Close(); HttpWebResponsemyResponse=(HttpWebResponse)myRequest.GetResponse(); if(myResponse.StatusCode==HttpStatusCode.OK) { returnOk(new{code="200",res=new{msg="短信发送成功!",data=new{code=r}}}); } else{ returnOk(new{code="400",res=new{msg="短信发送失败!"}}); } } #endregion
以上这篇C#开发(创蓝253)手机短信验证码接口的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。