創藍253: https://www.253.com/
#region 獲取手機驗證碼(創藍253) /// <summary> /// 獲取手機驗證碼(創藍253) /// </summary> /// <param name="phoneno">手機號</param> /// <returns></returns> [AllowAnonymous] public async Task<IHttpActionResult> GetPhoneCode(string phoneno) { string account = "******", password = "******", mobile = phoneno; Random rd = new Random(); int r = rd.Next(100000, 999999); string content = "【您的簽名】"+"尊敬的客戶:您的驗證碼為" + r + "!"; string postStrTpl = "un={0}&pw={1}&phone={2}&msg={3}&rd=1"; UTF8Encoding encoding = new UTF8Encoding(); byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content)); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://sms.253.com/msg/send"); myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = postData.Length; Stream newStream = myRequest.GetRequestStream(); newStream.Write(postData, 0, postData.Length); newStream.Flush(); newStream.Close(); HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); if (myResponse.StatusCode == HttpStatusCode.OK) { return Ok(new { code = "200", res = new { msg = "短信發送成功!", data = new { code = r } } }); } else { return Ok(new { code = "400", res = new { msg = "短信發送失敗!" } }); } } #endregion以上這篇C# 開發(創藍253)手機短信驗證碼接口的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答