創(chuàng)藍(lán)253: https://www.253.com/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#region 獲取手機(jī)驗(yàn)證碼(創(chuàng)藍(lán)253) /// < summary > /// 獲取手機(jī)驗(yàn)證碼(創(chuàng)藍(lán)253) /// </ summary > /// < param name = "phoneno" >手機(jī)號(hào)</ 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 = "【您的簽名】"+"尊敬的客戶(hù):您的驗(yàn)證碼為" + 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 = "短信發(fā)送成功!", data = new { code = r } } }); } else { return Ok(new { code = "400", res = new { msg = "短信發(fā)送失??!" } }); } } #endregion |
以上這篇C# 開(kāi)發(fā)(創(chuàng)藍(lán)253)手機(jī)短信驗(yàn)證碼接口的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://www.cnblogs.com/yechangzhong-826217795/p/7122892.html