NetEase cloud Letter, send verification code SMS C # version code

Source: Internet
Author: User
Tags sha1

NetEase Cloud Letter Send SMS Code (C # Version) .... Note SHA1 string has conversion lowercase!!!!

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading.Tasks;namespacehaimou.common.sms{ Public classneteasesms {Static stringURL ="https://api.netease.im/sms/sendcode.action"; Static stringAppKey ="************************************"; Static stringAppsecret ="******";  Public Static stringSend (stringmobile) {            stringNonce =NewRandom (). Next (100000,999999).            ToString (); stringCurtime =DateTime.Now.ToUnixStamp ().            ToString (); stringCheckSum = Sha1_hash (appsecret+ nonce+curtime); stringPost = $"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(varWSR =Wreq.getrequeststream ()) {WSR. Write (Btbodys,0, btbodys.length); } System.Net.WebResponse Wresp=Wreq.getresponse (); System.IO.Stream Respstream=Wresp.getresponsestream (); stringresult; using(System.IO.StreamReader reader =NewSystem.IO.StreamReader (Respstream,system.text.encoding.utf8)) {Result=Reader.            ReadToEnd (); }            //JSON data, obj is the verification code generated by NetEase            returnresult; }        Private Static stringSha1_hash (stringstr_sha1_in) {SHA1 SHA1=NewSHA1CryptoServiceProvider (); byte[] bytes_sha1_in =UTF8Encoding.Default.GetBytes (str_sha1_in); byte[] Bytes_sha1_out =Sha1.computehash (bytes_sha1_in); stringStr_sha1_out =bitconverter.tostring (bytes_sha1_out); Str_sha1_out= Str_sha1_out. Replace ("-","").            ToLower (); returnstr_sha1_out; }        Private Static stringGetformattedtext (byte[] bytes) {            intLen =bytes.            Length; StringBuilder buf=NewStringBuilder (len *2);  for(intj =0; J < Len; J + +) {buf. Append (hex_digits[(bytes[j)>>4) &0x0f]); Buf. Append (Hex_digits[bytes[j]&0x0f]); }            returnbuf.        ToString (); }        Private Static Char[] Hex_digits = {'0','1','2','3','4','5','6','7','8','9','a','b','C','D','e','F' }; }}

NetEase cloud Letter, send verification code SMS C # version code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.