Thinkphp uses cloud messaging for text message Verification Code

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn thinkphp text message verification code with cloud news.
Go to Cloud information registration account web site http://www.ucpaas.com/

If you register an account for the cloud messaging platform, you will be able to get a free test cost of 10 yuan.

Decompress the attachment to the ThinkPHP \ Library \ Org file.
New Method Public function send (){
// Required for initialization
$ Options ['accountsid '] = *******'; // enter your own
$ Options ['Token'] = ***** '; // enter your own


// $ Options required for initialization
$ Ucpass = new \ Org \ Com \ Ucpaas ($ options );

// Generate a 6-digit Verification Code randomly
Srand (double) microtime () * 1000000); // create a random number feed.
$ Ychar = ", A, B, C, D, E, F, G, H, I, J, K, L, M, n, O, P, Q, R, S, T, U, V, W, X, Y, Z ";
$ List = explode (",", $ ychar );
For ($ I = 0; $ I <6; $ I ++ ){
$ Randnum = rand (0, 35); // 10 + 26;
$ Authnum. = $ list [$ randnum];
}

// SMS Verification Code (template text message). By default, 65 Chinese characters (the same as 65 English letters) are used as one verification code (the number of characters that can be accommodated is affected by the characters occupied by your application name ), if the length is exceeded, the SMS platform will automatically separate multiple messages for sending. The separate messages are billed based on the number of messages used.
$ AppId = "****"; // enter your own
$ To = $ _ POST ['to'];
$ TemplateId = "1 ";
$ Param = $ authnum;


$ Arr = $ ucpass-> templateSMS ($ appId, $ to, $ templateId, $ param );
If (substr ($ arr, 21,6) = 000000 ){
// If it succeeds, the test style is used here and can be adjusted as needed.
Echo "the text message verification code has been sent successfully. Check the text message ";

} Else {
// If it fails
Echo "SMS Verification Code failed to be sent. Please contact Customer Service ";

}




}
Front-end page


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.