Thinkphp Integration Series of SMS Verification code, order notice

Source: Internet
Author: User
Tags auth git clone

Now this message is flooded with the age of application if there is no SMS registration; You dare not say that you are engaged in development;

This verification code is not difficult to do, but if the contact is a bit unknown from where to start the confusion;

Talk about the concept first;

To send a CAPTCHA, you need at least three items; AppID, key, template ID;

AppID, and key such as easier to understand, a variety of third-party platforms will be provided;

Template ID refers to the content of the text message, such as "Taobao" verification code is 192612, please enter in 5 minutes;

This is a template; we can only change 192612, and 5 of these two digits when texting; others are fixed;

Because of policy issues; templates need to be applied and audited; Generally 1 working days are over;

Below to write the specific process;

1: Find a reliable text message authentication code platform, recommend the following used; The following take Jong communication as an example; other platforms a truth;

Ali Big Fish: http://www.alidayu.com/service?spm=a3142.7802752.1.4.oAfDUZ&_t=2#sms

Jong Communication: http://www.yuntongxun.com/

2: Register, login, authentication, all nonsense; get account SID, AUTH TOKEN;

3: Create an application;

4: Add a template;

5: Wait for the audit pass; get the template ID;

6: Finished. Think much of it; this is just the basic condition to be able to send the verification code, and then download the official SDK;

The title hangs the thinkphp integration Short message authentication code; don't write thinkphp; it must be sprayed into slag. There's no residue left.

All the source code can be found in my open source project bjyadmin: http://git.oschina.net/shuaibai123/thinkphp-bjyadmin

Take my open source project for example; put it in the/thinkphp/library/org/xb/rongcloud.class.php.

7: Adding functions to the public library/application/common/common/function.php

/**  *  send   Jong communication   Verification code  *  @param   int  $phone   Mobile number  * @ param  int  $code    Verification code  *  @return  boole     
  Whether to send successfully  */Function send_sms_code ($phone, $code) {    //request address, format as follows, do not need to write https://
     $serverIP = ' app.cloopen.com ';
    //Request Port      $serverPort = ' 8883 ';
    //rest version number      $softVersion = ' 2013-12-26 ';
    //main account      $accountSid =c (' Ronglian_account_sid ');
    //main account TOKEN      $accountToken =c (' Ronglian_account_token ');

    //Application ID      $appId =c (' ronglian_appid ');
     $rest  = new \org\xb\rest ($serverIP, $serverPort, $softVersion);
     $rest->setaccount ($accountSid, $accountToken);      $rest->setappid ($appId);     //  Send template sms      $result = $rest->sendtemplatesms ($phone, Array ($
code,5), 59939);     if ($result ==null)  {        return 
False    &NBSP}     if ($result->statuscode!=0)  {    
    return  false;     }else{        return true;     &NBSP}}

8: Fill in configuration item/application/common/conf/config.php with account SID, AUTH TOKEN, template ID

' Ronglian_account_sid ' => ',//Jong Communications main account Accountsid ' Ronglian_account_token ' => '
,//Jong communications Master Account TOKEN Oken
' ronglian_appid ' => ',//Jong communication Application ID APPID ' ronglian_template_id ' => '
,//Jong Communication Template ID

9: Call Function: Send_sms_code (' Mobile number ', ' Verification Code ');

The open source project I've been sorting out is already integrated; all it takes is to fill in the blanks in the configuration items and send text messages;

Children's shoes need to be directly git clone test: http://git.oschina.net/shuaibai123/thinkphp-bjyadmin


This article for Bai Jun Remote original article, reproduced without contact with me, but please specify from Bai Jun remote blog http://baijunyao.com                   &N Bsp    

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.