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