Now the site in the construction of the site in order to ensure the authenticity of user information, often choose to send text messages to the user's mobile phone verification code information, only through the verification of the user can register, so as to ensure that the user's contact information data of 100% accuracy, but also provide users with a most convenient and efficient way to register.
So let's just say, today, the principle of text messaging, such as
Work Development process:
First, the basic idea of realizing PHP mobile phone message verification function
1, to find SMS service providers, access to SMS services
2, in the Website Information submission page request to send the information
3. The server communicates with the SMS service provider, submits the request for sending
4. The SMS service provider sends the information to the user's mobile phone through the operator
Second: Mobile phone number SMS verification foreground page effect implementation
<! DOCTYPE html>
Third, call SMS Server SMS Interface
<?php/** * Created by PhpStorm. * User: Leo * Date: 2017/8/30 * Time: 14:59 *///$_post$phone= isset($_POST[‘phone‘])?$_POST[‘phone‘]:‘‘;$code = isset($_POST[‘code‘])?$_POST[‘code‘]:‘‘;require (dirname(__FILE__).‘/config.php‘);require (dirname(__FILE__).‘/SendSMS.php‘);//实例化短信发送类$sms= new SendSMS($options[‘account‘],$options[‘password‘]);$context=‘验证码‘.$code;$res=$sms->send($phone,$context);if ($res){ echo "成功";}else{ echo "失败";}
Because we write the code separately for the sake of the elegance of the code. It is convenient to reuse later. So the sending of short messages specifically encapsulates a class. See the code specifically:
<?php/** * Created by Phpstorm. * User:leo * DATE:2017/8/30 * time:15:26 *//** * Set User information */class sendsms{ Const sendurl= ' http://gd.ums86.com:8899/sms/Api/Send.do '; Private $_un; Private $_PW; function __construct ($user, $pwd) {$this->_un= $user; $this->_pw= $pwd; } function Send ($phone, $content, $isreport =0) {//Send data $data =array (' un ' = $this->_un, ' PW ' = $this->_pw, ' sm ' and ' $content, ' da ' and ' $phone, ' Rd ' and $isreport, ' RF ' =>2, ' TF ' =>3, ' DC ' =>15,); $url =sendsms::sendurl. '? '. Http_build_query ($data); $this->curlget ($url); Public Function Curlget ($url) {$ch = Curl_init (); curl_setopt ($ch, curlopt_header,0); curl_setopt ($ch, curlopt_returntransfer,1); curl_setopt ($ch, Curlopt_url, $url); $res =curl_exec ($ch); Curl_close ($ch); return $res; }}
In the sendsms inside of some methods, you in the third-party SMS verification code provider provided by the instance code inside can see, the function is basically the same, so we realize a belong to their own send message class, relatively simple.
Finally, we realized a message verification code to send the function of their own
So in the end, have you learned it?
PHP SMS Verification Code function