[. NET development] C # implements the ability to send phone verification code

Source: Internet
Author: User

I didn't know much about this before, and I always thought it was complicated. Until the first two days the company asked to do this function. After doing it, I realized that this is something that can be achieved by a POST request. Now to share with you, there are shortcomings and please advise. Nonsense not much to say directly on the code.

1. First obtain a random digital verification code (here is 6 digits), and then edit the content to be sent. There is also a verification of the legality of the cell phone number.

public string Verificationcode (string mobile)

{

if (Ishandset (mobile))

{

String code = new Random (). Next (111111, 999999). ToString ();

String content = "Pro, the verification code for this operation is:" + code + "Do not disclose this code information to others, such as non-personal operation, please ignore this message. "Tangjiangbaba" ";

BOOL ret = sendfast (mobile, content);

if (ret)

{

return code;

}

Else

{

Return "Send Failed";

}

}

Else

{

Return "cell phone number format is incorrect";

}

}

///

Verify that the phone number is legal

///

///

///

public bool Ishandset (string str_handset)

{

Return System.Text.RegularExpressions.Regex.IsMatch (Str_handset, @ "^1[3|4|5|7|8][0-9]\d{8}$");

}

Copy Code

2. Then call the method that sent the message. The incoming address and parameters are OK, and it is important to note that the contents of the send are converted to bytes.

3. If the send is successful, a string of XML data is returned, such as

Success

Ok

62095

2779227

1

Copy Code

The above is a small series to introduce you to the C # implementation of mobile phone verification code, I hope to help you

(Edit: Lelinpeng Source: Network)

[. NET development] C # implements the ability to send phone verification 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.