日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

网易云信,发送验证码短信C#版代码

發(fā)布時(shí)間:2024/4/17 C# 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 网易云信,发送验证码短信C#版代码 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
網(wǎng)易云信,發(fā)送驗(yàn)證碼短信C#版代碼

網(wǎng)易云信發(fā)送短信代碼(C#?版)。。。。需要注意SHA1 String有轉(zhuǎn)換小寫!!!!

using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks;namespace HaiMou.Common.SMS {public class NeteaseSms{static string url = "https://api.netease.im/sms/sendcode.action";static string appKey = "************************************";static string appSecret = "******";public static string Send(string mobile){string nonce = new Random().Next(100000, 999999).ToString();string curTime = DateTime.Now.ToUnixStamp().ToString();string checkSum = SHA1_Hash(appSecret+ nonce+ curTime);string post = $"mobile={mobile}";byte[] btBodys = Encoding.UTF8.GetBytes(post);System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);wReq.Method = "POST";wReq.Headers.Add("AppKey", appKey);wReq.Headers.Add("Nonce", nonce);wReq.Headers.Add("CurTime", curTime);wReq.Headers.Add("CheckSum", checkSum);wReq.ContentLength = btBodys.Length;wReq.ContentType = "application/x-www-form-urlencoded;charset=utf-8";using (var wsr = wReq.GetRequestStream()){wsr.Write(btBodys, 0, btBodys.Length);}System.Net.WebResponse wResp = wReq.GetResponse();System.IO.Stream respStream = wResp.GetResponseStream();string result;using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream,System.Text.Encoding.UTF8)){result = reader.ReadToEnd();}//Json數(shù)據(jù),obj是網(wǎng)易生成的驗(yàn)證碼return result;}private static string SHA1_Hash(string str_sha1_in){SHA1 sha1 = new SHA1CryptoServiceProvider();byte[] bytes_sha1_in = UTF8Encoding.Default.GetBytes(str_sha1_in);byte[] bytes_sha1_out = sha1.ComputeHash(bytes_sha1_in);string str_sha1_out = BitConverter.ToString(bytes_sha1_out);str_sha1_out = str_sha1_out.Replace("-", "").ToLower();return str_sha1_out;}private static string getFormattedText(byte[] bytes){int len = bytes.Length;StringBuilder buf = new StringBuilder(len * 2);for (int j = 0; j < len; j++){buf.Append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);buf.Append(HEX_DIGITS[bytes[j] & 0x0f]);}return buf.ToString();}private static char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };} }

?

posted on 2016-09-04 23:39 海眸1990 閱讀(...) 評(píng)論(...) 編輯 收藏

轉(zhuǎn)載于:https://www.cnblogs.com/Zendic/p/5840786.html

總結(jié)

以上是生活随笔為你收集整理的网易云信,发送验证码短信C#版代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。