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