Tihinkphp3.2 integration of the latest version of Ali Big Fish SMS Verification code sent

Source: Internet
Author: User
Tags aliyun

Ali Big Fish Latest: Ali Big fish SDK Download or download from the official website: Ali Big Fish SDK website download

After the download is complete, put the API_SDK folder in the compressed package into the Thinkphp\library\vendor directory, modify the file name Aliyun, if modified to another name, please modify the namespace!

Ali Big Fish Application steps will not say! Start the Access Bar ~

Set up Ali Big Fish configuration information:

Configure in the configuration file:

1     ' Ali_sms ' = [  2         ' PRODUCT ' = ' Dysmsapi ', 3         ' DOMAIN ' = ' Dysmsapi.aliyuncs.com ', 4         ' region ' = ' Cn-hangzhou ', 5         ' end_point_name ' = ' Cn-hangzhou ', 6         ' key_id ' = ' Your access key ID ', 7         ' key_secret ' + ' Your access key Sec Ret ', 8         ' sign_name ' + ' signature name ', 9         ' template_code ' = ' + ' template CODE ',ten     ],

After the setup is complete, create a new send SMS function in the function.php file, named Sendcode:

<?PHP UseAliyun\core\config; UseAliyun\core\profile\defaultprofile; Usealiyun\core\defaultacsclient; Usealiyun\api\sms\request\v20170525\sendsmsrequest;/** * Created by Phpstorm. * User:administrator * DATE:2018/5/2 0002 * time:10:20*/functionSendcode ($num,$code){    require_once'/thinkphp/library/vendor/aliyun/vendor/autoload.php '; //Load Zone node configurationConfig::load (); //initializing a user profile instance    $profile= Defaultprofile::getprofile (C (' Ali_sms. Region '), C (' Ali_sms. key_id '), C (' Ali_sms. Key_secret ')); //increase the service node.Defaultprofile::addendpoint (C (' Ali_sms. End_point_name '), C (' Ali_sms. Region '), C (' Ali_sms. PRODUCT '), C (' Ali_sms. DOMAIN ')); //initialize acsclient for initiating requests    $acsClient=NewDefaultacsclient ($profile); //Initialize the Sendsmsrequest instance to set the parameters for sending SMS    $request=Newsendsmsrequest (); //must fill in, set the pheasant SMS receive number    $request->setphonenumbers ($num); //required, set signature name    $request->setsignname (C (' Ali_sms. Sign_name ')); //required, set template code    $request->settemplatecode (C (' Ali_sms. Template_code ')); //optional, set template parameters    $request->settemplateparam (Json_encode (Array(//the value of a field in a text message template"Code" =$code, "Product" = "DSD"    ),Json_unescaped_unicode)); //initiating an Access request    $acsResponse=$acsClient->getacsresponse ($request); //return request Result    $result= Json_decode (Json_encode ($acsResponse),true); return $result;}

Use, only in = Call the Sendcode function in the controller:

 Public functionsendmsg () {$phone= input (' Post.phone_num '); $code=Rand(100000,999999); $res= Sendcode ($phone,$code); if($code= = "OK"){        $data=Array(' msg ' = ' success ')); }Else{        $data=Array(' msg ' = ' ERROR '); }    returnJson_encode ($data);}

The effect is as follows:

Original address: Mr. Zhang's blog http://www.zhangfayuan.cn/archives/201805041200198.html

Tihinkphp3.2 integration of the latest version of Ali Big Fish SMS Verification code sent

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.