久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網
      最全最豐富的資訊網站

      php如何實現(xiàn)手機注冊

      php實現(xiàn)手機注冊的方法:1、將接口地址和appkey放在配置文件中;2、封裝sendmsg函數,使用curl發(fā)送請求;3、在控制器中定義sendcode方法;4、調用sendmsg函數實現(xiàn)驗證碼短信發(fā)送功能。

      php如何實現(xiàn)手機注冊

      本文操作環(huán)境:windows10系統(tǒng)、php 7、thindpad t480電腦。

      我們在使用手機號注冊時通常需要發(fā)送短信驗證碼,在進行修改密碼等敏感操作時也需要手機號發(fā)送短信驗證碼。那么在實際項目中如果要發(fā)送短信驗證碼該如何做呢?通常是需要調用第三方短信商的短信發(fā)送接口。

      下面就讓我們一起來看看如何實現(xiàn)吧!

      手機注冊:

      可以將接口地址和appkey放在配置文件中。封裝一個函數sendmsg用于發(fā)送短信,可以用PHP中的curl請求方式(PHP中的curl函數庫)發(fā)送請求。

      if (!function_exists('sendmsg')) {     function sendmsg($phone, $msg){         //從配置文件讀取接口信息         $gateway = config('msg.gateway');         $appkey = config('msg.appkey');         //準備請求地址         $url = $gateway . "?appkey=" . $appkey . "&mobile=" . $phone . "&content=" . $msg;         //發(fā)送請求 比如get方式  https請求         $res = curl_request($url, false, [], true);           if (!$res) {             return "請求發(fā)送失敗";         }         //請求發(fā)送成功,返回值json格式字符串         $arr = json_decode($res, true);         if ($arr['code'] == 10000) {             return true;         }         return $arr['msg'];     } }

      在控制器里定義一個sendcode方法,當前臺點擊發(fā)送驗證碼發(fā)送ajax請求,該方法接收到前臺注冊用戶的手機號,調用sendmsg函數實現(xiàn)驗證碼短信發(fā)送功能。

       //ajax請求發(fā)送注冊驗證碼     public function sendcode($phone)     {         //參數驗證         if (empty($phone)) {             return ['code' => 10002, 'msg' => '參數錯誤'];         }         //短信內容  您用于注冊的驗證碼為:****,如非本人操作,請忽略。         $code = mt_rand(1000, 9999);         $msg = "您用于注冊的驗證碼為:{$code},如非本人操作,請忽略。";         //發(fā)送短信         $res = sendmsg($phone, $msg);         if ($res === true) {             //發(fā)送成功,存儲驗證碼到session 用于后續(xù)驗證碼的校驗             session('register_code_' . $phone, $code);             return ['code' => 10000, 'msg' => '發(fā)送成功', 'data' => $code];         }         return ['code' => 10001, 'msg' => $res];     }

      郵箱注冊:

      PHP中郵箱注冊可以使用PHPMailer插件來實現(xiàn)郵件發(fā)送(具體可查看PHPMailer手冊)。在配置文件中配置好郵箱賬號信息,封裝一個send_email函數使用phpmailer發(fā)送郵件。

      if (!function_exists('send_email')) {     //使用PHPMailer發(fā)送郵件     function send_email($email, $subject, $body){         //實例化PHPMailer類  不傳參數(如果傳true,表示發(fā)生錯誤時拋異常)         $mail = new PHPMailer(); //        $mail->SMTPDebug = 2;                              //調試時,開啟過程中的輸出          $mail->isSMTP();                                     // 設置使用SMTP服務         $mail->Host = config('email.host');                  // 設置郵件服務器的地址         $mail->SMTPAuth = true;                              // 開啟SMTP認證         $mail->Username = config('email.email');             // 設置郵箱賬號         $mail->Password = config('email.password');            // 設置密碼(授權碼)         $mail->SMTPSecure = 'tls';                            //設置加密方式 tls   ssl         $mail->Port = 25;                                    // 郵件發(fā)送端口         $mail->CharSet = 'utf-8';                           //設置字符編碼         //Recipients         $mail->setFrom(config('email.email'));//發(fā)件人         $mail->addAddress($email);     // 收件人         //Content         $mail->isHTML(true);                                  // 設置郵件內容為html格式         $mail->Subject = $subject; //主題         $mail->Body    = $body;//郵件正文 //      $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';         if ($mail->send()) {             return true;         }         return $mail->ErrorInfo; //        $mail->ErrorInfo     } }

      然后在控制器的方法中調用該函數,實現(xiàn)本郵箱向注冊用戶郵箱發(fā)送驗證郵件功能。

      推薦學習:php培訓

      贊(0)
      分享到: 更多 (0)
      網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號