<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ? 1.騰訊云短信驗證碼擴展包,直接下載就可以了: 鏈接:https://pan.baidu.com/s/16kQ5ejt2YxMbQCDeGCyyBg? 提取碼:fmue 2.封裝一個類用于調用發送短信接口: ~~~php <?php /** * Created by PhpStorm. * User: cwwx0 * Date: 2020/4/15 * Time: 11:58 */ namespace app\index\controller; use sms\SmsSingleSender; class Smsmsg { public function sendcode($phoneNumbers='18888888888',$params=1234){ // [rand(1000, 9999)] //騰訊短信驗證碼 // 短信應用 SDK AppID $appid = 1400**0687; // SDK AppID 以1400開頭 // 短信應用 SDK AppKey $appkey = "7922a5ec4****4220941e8f16e1a1615"; // 需要發送短信的手機號碼 // $phoneNumbers = '15956137456'; // $phoneNumbers = input("phone"); // 短信模板 ID,需要在短信控制臺中申請 $templateId = 57**70; // NOTE: 這里的模板 ID`7839`只是示例,真實的模板 ID 需要在短信控制臺中申請 $smsSign = "**赳"; // NOTE: 簽名參數使用的是`簽名內容`,而不是`簽名ID`。這里的簽名"騰訊云"只是示例,真實的簽名需要在短信控制臺申請 try { $ssender = new SmsSingleSender($appid, $appkey); // $params = [rand(1000, 9999)];//生成隨機數 $result = $ssender->sendWithParam("86", $phoneNumbers, $templateId, $params, $smsSign, "", ""); $rsp = json_decode($result); return json(["result"=>$rsp->result,"code"=>$params]); } catch(\Exception $e) { // echo var_dump($e); // return false; return json(["result"=>1,"code"=>$params]); } } public function sendmsg($phoneNumbers='18855662233',$params=array()){ //騰訊短信驗證碼 // 短信應用 SDK AppID $appid = 140***0687; // SDK AppID 以1400開頭 // 短信應用 SDK AppKey $appkey = "7922a5****3144220941e8f16e1a1615"; // 需要發送短信的手機號碼 // $phoneNumbers = '18855662233'; // $phoneNumbers = input("phone"); // 短信模板 ID,需要在短信控制臺中申請 $templateId = 57**71; // NOTE: 這里的模板 ID`7839`只是示例,真實的模板 ID 需要在短信控制臺中申請 $smsSign = "**赳"; // NOTE: 簽名參數使用的是`簽名內容`,而不是`簽名ID`。這里的簽名"騰訊云"只是示例,真實的簽名需要在短信控制臺申請 try { $ssender = new SmsSingleSender($appid, $appkey); // $params = array('豬豬俠');//生成隨機數 // $params = [rand(1000, 9999)];//生成隨機數 $result = $ssender->sendWithParam("86", $phoneNumbers, $templateId, $params, $smsSign, "", ""); $rsp = json_decode($result); return json(["result"=>$rsp->result,"code"=>$params]); } catch(\Exception $e) { // echo var_dump($e); return json(["result"=>1,"code"=>$params]); } } } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "點擊并拖拽以移動") 3.短信發送接口調用方法? 在控制器頂部加上 ~~~php /*注冊發送短信*/ public function sendmsg(){ $request=request()->param(); if(!$request['phone']){ return json(['code'=>400,'msg'=>'手機號不能為空']); } $cs= new Smsmsg(); $code=rand(1000, 9999); $ret=$cs->sendcode($request['phone'],[$code]); $ck = json_decode($ret->getContent(),true); if($ck['result']==0){ /*短信存儲*/ Db::name('sms')->insert(array('event'=>'注冊驗證碼','mobile'=>$request['phone'],'code'=>$code,'ip'=>request()->ip(),'createtime'=>time())); return json(['code'=>200,'msg'=>'驗證碼發送成功']); }else{ return json(['code'=>400,'msg'=>'驗證碼發送失敗']); } } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "點擊并拖拽以移動") 4.完整版登錄、注冊、找回密碼、驗證碼登錄、退出登錄 ~~~php <?php /** * Created by PhpStorm. * User: cwwx0 * Date: 2020/6/30 * Time: 10:36 */ namespace app\webapi\controller; use fast\Random; use think\Controller; use think\Db; use think\Request; use think\cache\driver\Redis; class Login extends Controller { /*注冊發送短信*/ public function sendmsg(){ $request=request()->param(); if(!$request['phone']){ return json(['code'=>400,'msg'=>'手機號不能為空']); } $cs= new Smsmsg(); $code=rand(1000, 9999); $type=$request['type']; if($type==1){ $templateId=648267; $msg='注冊驗證碼'; }else if($type==2){ $templateId=563119; $msg='找回密碼驗證碼'; }else if($type==3){ $templateId=648270; $msg='登錄驗證碼'; } $ret=$cs->sendcode($request['phone'],[$code],$templateId); $ck = json_decode($ret->getContent(),true); if($ck['result']==0){ /*短信存儲*/ Db::name('sms')->insert(array('event'=>$msg,'mobile'=>$request['phone'],'code'=>$code,'ip'=>request()->ip(),'createtime'=>time())); return json(['code'=>200,'msg'=>'驗證碼發送成功']); }else{ return json(['code'=>400,'msg'=>'驗證碼發送失敗']); } } /** * @return mixed|\think\response\Json * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * 立即注冊 */ public function register(){ if (Request::instance()->isPost()) { $data = Request::instance()->param(); $ck=Db::name('sms')->where(array('mobile'=>$data['phone'],'code'=>$data['code']))->find(); if($ck){ if($ck['times']==0){ Db::startTrans(); try { $cks=Db::name('pcnewuser')->where(array('phone'=>$data['phone']))->find(); Db::name('sms')->where(array('mobile'=>$data['phone'],'code'=>$data['code']))->setInc('times'); if($cks){ // return json(['code'=>400,'msg'=>'賬號已存在']); Db::name('pcnewuser')->where(array('phone'=>$data['phone']))->update(array('password'=>md5($data['password']),'createtime'=>time())); return json(['code'=>200,'msg'=>'賬號已存在,密碼更新成功']); }else{ /*新增一條用戶信息*/ Db::name('pcnewuser')->insertGetId(array('phone'=>$data['phone'],'password'=>md5($data['password']),'createtime'=>time())); } Db::commit(); // session('userinfo',$infoint); 是否登錄用cookie來判斷 參照 藍牙打印 return json(['code'=>200,'msg'=>'注冊成功']); } catch (Exception $e) { Db::rollback(); } }else{ return json(['code'=>400,'msg'=>'驗證碼失效']); } }else{ return json(['code'=>400,'msg'=>'驗證碼錯誤']); } } return $this->fetch(); } /** * @return string * @throws \think\Exception * 找回密碼 */ public function findpassword() { if (Request::instance()->isPost()) { $data = Request::instance()->param(); $ck=Db::name('sms')->where(array('mobile'=>$data['phone'],'code'=>$data['code']))->find(); if($ck){ if($ck['times']==0){ $cks=Db::name('pcnewuser')->where(array('phone'=>$data['phone']))->find(); Db::name('sms')->where(array('mobile'=>$data['phone'],'code'=>$data['code']))->setInc('times'); if($cks){ Db::name('pcnewuser')->where(array('phone'=>$data['phone']))->update(array('password'=>md5($data['password']),'createtime'=>time())); return json(['code'=>200,'msg'=>'密碼修改成功']); }else{ return json(['code'=>400,'msg'=>'用戶不存在']); } }else{ return json(['code'=>400,'msg'=>'驗證碼失效']); } }else{ return json(['code'=>400,'msg'=>'驗證碼錯誤']); } } // return $this->view->fetch(); } /*驗證碼登錄*/ public function codelogon(){ /*有就登錄,沒有就注冊*/ if (Request::instance()->isPost()) { $data = Request::instance()->param(); $ck=Db::name('sms')->where(array('mobile'=>$data['phone'],'code'=>$data['code']))->find(); if($ck){ if($ck['times']==0){ $cks=Db::name('pcnewuser')->where(array('phone'=>$data['phone']))->find(); Db::name('sms')->where(array('mobile'=>$data['phone'],'code'=>$data['code']))->setInc('times'); /*存redis*/ $redis=new Redis(); $token=Random::build('alnum',30); $redis->set('token'.$data['phone'],$token); if(!$cks){ // 沒有就新建用戶并且寫redis并且登錄成功,返回token跟手機號 Db::name('pcnewuser')->insert(array('phone'=>$data['phone'],'createtime'=>time())); } return json(['code'=>200,'msg'=>'登錄成功','data'=>['token'=>$token,'phone'=>$data['phone']]]); }else{ return json(['code'=>400,'msg'=>'驗證碼失效']); } }else{ return json(['code'=>400,'msg'=>'驗證碼錯誤']); } } } /** * @return mixed|\think\response\Json * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * 登錄 */ public function login(){ if (Request::instance()->isPost()) { $data = Request::instance()->param(); $cks=Db::name('pcnewuser')->where(array('phone'=>$data['phone'],'password'=>md5($data['password'])))->find(); if($cks){ $redis=new Redis(); $token=Random::build('alnum',30); $redis->set('token'.$data['phone'],$token); return json(['code'=>200,'msg'=>'登錄成功','data'=>['token'=>$token,'phone'=>$data['phone']]]); }else{ /*新增一條用戶信息*/ return json(['code'=>400,'msg'=>'賬號或密碼錯誤']); } } return $this->fetch(); } /*退出登錄*/ public function logout(){ if (Request::instance()->isPost()) { $data = Request::instance()->param(); $phone=$data['phone']; $redis=new Redis(); $redis->rm('token'.$phone); return json(['code'=>200,'msg'=>'退出成功']); } } /*測試↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ public function testset(){ $redis=new Redis(); $token=Random::build('alnum',30); $redis->set('token18855662233',$token); } public function testget(){ $redis=new Redis(); $token=$redis->has('token18855662233'); if($token){ return $redis->get('token18855662233'); }else{ return '已過期'; } } } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "點擊并拖拽以移動") 5.底層代碼改寫記錄??delete改成del ~~~php C:\phpStudy\PHPTutorial\WWW\numbersell\thinkphp\library\think\session\driver\Redis.php /** * 刪除緩存 * @access public * @param string $name 緩存變量名 * @return boolean */ public function rm($name) { return $this->handler->del($this->getCacheKey($name)); // return $this->handler->delete($this->getCacheKey($name)); } ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "點擊并拖拽以移動") 6.redis在config.php 里面的配置 ~~~php 'cache' => [ // 驅動方式 // 'type' => 'File', 'type' => '\think\cache\driver\Redis', // 緩存保存目錄 'path' => CACHE_PATH, // 緩存前綴 'prefix' => '', // 緩存有效期 0表示永久緩存 'expire' => 0, ], ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "點擊并拖拽以移動") 7.可以在這個地方調整redis失效時間,目前設置的是兩個小時 ~~~php protected $options = [ 'host' => '127.0.0.1', 'port' => 6379, 'password' => '', 'select' => 0, 'timeout' => 0, 'expire' => 7200, 'persistent' => false, 'prefix' => '', ]; ~~~ ![](data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw== "點擊并拖拽以移動") 點擊鏈接加入群聊【ThinkPHP56小功能】:[正在跳轉](https://jq.qq.com/?_wv=1027&k=Z0c641WP "正在跳轉")? ?
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看