App Development (Android and PHP interface): SMS Verification Code

Source: Internet
Author: User
Tags urlencode

Recently with the students to develop an independent project, to use the SMS Verification Code, search on the internet for a long time, see a recommended paste, referred to a lot of good SMS service providers. After testing, the posts mentioned in the service providers their message arrival rate and arrival speed are also good. Finally, as a result of the funding problem, we decided to choose cloud-chip network. The following is the development process:

First, register and login to the backstage, and fill in some information, application. Get Apikey.

Next, you can develop the interface with Apikey.

<?PHPHeader("Content-type:text/html;charset=utf-8");$apikey= "******** Fill in appkey********";$ch=curl_init (); curl_setopt ($ch, Curlopt_httpheader,Array(' Accept:text/plain;charset=utf-8 ', ' content-type:application/x-www-form-urlencoded ', ' charset=utf-8 '));//Setting authentication Methodscurl_setopt ($ch, Curlopt_returntransfer,true);//set the return result to flowcurl_setopt ($ch, Curlopt_timeout, 10);//setting the time-out periodcurl_setopt ($ch, Curlopt_post, 1);//set up communication methodscurl_setopt ($ch, Curlopt_ssl_verifypeer,false);//Send template SMS//need to encode value$mobile= 12345678910;//phone number to receive SMS$code= Getrandomcheckcode ();//the verification code to be sent$data=Array(    ' tpl_id ' = 5,//here is the template ID, default is 1 when not set' Tpl_value ' =UrlEncode(' #code # '). ' = '.UrlEncode($code)        .‘ & '.UrlEncode(' #company # '). ' = '.UrlEncode(' Company name ')        .‘ & '.UrlEncode(' #app # '). ' = '.UrlEncode(' app name '), ' apikey ' =$apikey, ' mobile ' =$mobile);$send _result= Json_decode ($this->tpl_send ($ch,$data),true); Curl_close ($ch);if(0 = =$send _result[' Code ']) {    //Success}Else {    //failed}//A verification code generation function is attached herefunctionGetrandomcheckcode () {$chars= ' 0123456789 '; Mt_srand((Double)Microtime() *1000000*Getmypid()); $CheckCode="";  while(strlen($CheckCode) <6)        $CheckCode.=substr($chars,(Mt_rand()%strlen($chars)), 1); return $CheckCode;}?>

App Development (Android and PHP interface): SMS Verification Code

Related Article

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.