<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\.插件目錄結構 2\.插件控制器繼承父類 3\.模板開發 4\.插件實例: 控制前端控制后端 #### 1.插件目錄結構 ![Image](https://box.kancloud.cn/8b3510eefbd9abb74e2b0927221b82b2_298x456.jpeg) ![Image](https://box.kancloud.cn/8b3510eefbd9abb74e2b0927221b82b2_298x456.jpeg) Controller文件夾存放插件控制器類 View文件夾存放各個控制器的視圖模板和其他模板開發一致,模板渲染使用$this -> \_display('模板文件名'); #### 2.插件控制器繼承父類 前端插件繼承前端插件父類(\\Home\\Controller\\AddonController) 實例: class IndexController extends \\Home\\Controller\\AddonController{} 后端插件繼承后端插件父類(\\Admin\\Controller\\AddonController) 實例: class AdminController extends \\Admin\\Controller\\AddonController{} #### 3.模板開發 插件模板開發和普通模板開發一致 使用{:ADDON\_CSS}引入插件公共資源(Public)css樣式文件使用{:A[DDON](http://www.hmoore.net/)\_IMG}引入插件公共資源(Public)img圖片文件 使用{:ADDON\_js}引入插件公共資源(Public)javascript文件 4\.插件實例: #### 控制前端 <?php namespace Addon\\LeaveMessage\\Controller; /\*引入微信SDK\*/ use Com\\WechatAuth; /\*\* \* 在線留言插件控制器 \*/ class IndexController extends \\Home\\Controller\\AddonController{ private $leaveMessageTable = null; // LeaveMessage留言數據表對象 private $wechatAuth = null; //微信WechatAuth public function construct(){ parent:: construct(); $firstId = I('get.firstId', 0); $this -> leaveMessageTable = M('leaveMessage'); if((boolean) $firstId){ $res = M('Wechat') -> find($firstId); //AppId $appid = $res\['appid'\]; //Secret $secret = $res\['secret'\]; //EncodingAESKey $encodingAESkey = $res\['encodingAESkey'\]; //獲取被訪問公眾號access\_token $token = session("token\_ed"); if($token){//access\_token未過期 $this -> wechatAuth = new WechatAuth($appid, $secret, $token); } else {//access\_token已過期 $this -> wechatAuth = new WechatAuth($appid, $secret); $token = $this -> wechatAuth -> getAccessToken(); //將被訪問的公眾號access\_token寫入session并設置過期時間session(array('expire' => $token\['expires\_in'\])); session("token\_ed", $token\['access\_token'\]); } //將被訪問的公眾號EncodingAESKey,id,wechatAuth類寫入session便于后期調用session('EncodingAESKey', $encodingAESkey); session('wechatID', $firstId); session('wechatAuth', $this -> wechatAuth); }else{ $this -> wechatAuth = session('wechatAuth'); } } public function index(){ $redirect = C('DOMAIN').U('Weixin/Index/auth/addon/LeaveMessage'); $redirect = $this -> wechatAuth -> getRequestCodeURL($redirect, $state); header("Location:".$redirect); } public function auth($code = ''){ // 獲取網頁授權access\_token數組try{ $accessTokenArray = $this -> wechatAuth -> getAccessToken('code', $code); }catch(\\Exception $e){ $this -> redirect('Weixin/Index/index/firstId/'.session('wechatID').'/addon/LeaveMessage');exit; } // 獲取信息 $accessToken = $accessTokenArray\['access\_token'\]; // 網頁授權access\_token $expiresIn = $accessTokenArray\['expires\_in'\]; // 網頁授權access\_token 有效時間 $refreshToken = $accessTokenArray\['refresh\_token'\]; // 網頁授權用戶刷新access\_token $openId = $accessTokenArray\['openid'\]; // 網頁授權用戶唯一標識 // 緩存信息 // 獲取用戶信息 $userInfo = $this -> wechatAuth -> getUserInfo($openId); session('userInfo', $userInfo); $this -> redirect('Weixin/Index/leaveMessage/addon/LeaveMessage'); } public function leaveMessage(){ // 獲取當前用戶信息 $userInfo = session('userInfo'); if(!(boolean) $userInfo) redirect('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe71bdd9ed0bd39b 9&redirect\_uri=http%3A%2F%2Fyineng.uicp.cn%2Fwww%2Fweixin.php%3Fs%3D%2FWeixin%2FIndex %2Fauth%2Faddon%2FLeaveMessage.html&response\_type=code&scope=snsapi\_userinfo&connect\_r edirect=1#wechat\_redirect'); if(IS\_POST){ // 組織入庫數據 $userInfo\['question'\] = I('post.question'); $userInfo\['question\_time'\] = time(); // 入庫 if($this -> leaveMessageTable -> field('openid,nickname,sex,province,city,country,headimgurl, question,question\_time') -> add($userInfo) === false){ $msg = '留言失敗!'; }else{ $msg = '留言成功,請等待管理員回復!'; } $this -> ajaxReturn($msg); }else{ // 獲取留言數據表已經查看了的留言 $condition = array('is\_view' => 1); $[ord](http://www.hmoore.net/)er = 'question\_time DESC'; $list = $this -> leaveMessageTable -> where($condition) -> order($order) -> select(); 本文檔使用 看云 構建 \- 58 - // 獲取管理員回復當前用戶的留言但未查看的留言條數 $map\['openid'\] = array('eq', $userInfo\['openid'\]); $map\['is\_view'\] = array('eq', 0); $map\['answer'\] = array('neq', ''); $count = $this -> leaveMessageTable -> where($map) -> count(); // 模板賦值 $this -> assign('userInfo', $userInfo); $this -> assign('list', $list); $this -> assign('count', $count); // 模板渲染 $this -> \_display('leaveMessage'); } } public function showMe(){ // 獲取當前用戶信息 $userInfo = session('userInfo'); if(!(boolean) $userInfo) redirect('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe71bdd9ed0bd39b 9&redirect\_uri=http%3A%2F%2Fyineng.uicp.cn%2Fwww%2Fweixin.php%3Fs%3D%2FWeixin%2FIndex %2Fauth%2Faddon%2FLeaveMessage.html&response\_type=code&scope=snsapi\_userinfo&connect\_r edirect=1#wechat\_redirect'); // 獲取當前用戶留言 $condition = array('openid' => $userInfo\['openid'\]); $order = 'question\_time DESC'; $list = $this -> leaveMessageTable -> where($condition) -> order($order) -> select(); // 更新留言是否查看狀態,管理員已經回復但是當前用戶并未查看foreach ($list as $key => $value) { if(!empty($value\['answer'\]) && !(boolean) $value\['is\_view'\]){ $data\['is\_view'\] = 1; $data\['id'\] = $value\['id'\]; $this -> leaveMessageTable -> save($data); } } // 模板賦值 $this -> assign('list', $list); // 模板渲染 $this -> \_display('showMe'); } } ?> #### 控制后端 <?php namespace Addon\\LeaveMessage\\Controller; <?php namespace Addon\\LeaveMessage\\Controller; 本文檔使用 看云 構建 - 59 - /\*\* \* 在線留言后臺插件控制器 \*/ class AdminController extends \\Admin\\Controller\\AddonController{ private $leaveMessageTable = null; // 在線留言數據表對象 public function construct(){ parent:: construct(); $this -> leaveMessageTable = M('LeaveMessage'); } // 在線留言列表 public function index(){ //獲取操作按鈕 $button = get\_action\_button('/Admin/Admin/index/addon/LeaveMessage'); // 獲取留言列表 $list = $this -> leaveMessageTable -> field('\*') -> order('question\_time DESC') -> select(); // 模板賦值 $this -> assign('button', $button); $this -> assign('list', $list); // 模板渲染 $this -> \_display('index'); } // 留言回復 public function revert($id = null){ if(empty($id)) $this -> error('操作不合法'); $answer = I('post.answer'); if(empty($answer)){ $this -> error('請填寫回復內容'); } // 組織回復數據 $user = session('user'); $data\['id'\] = $id; $data\['username'\] = $user\['username'\]; $data\['answer'\] = $answer; $data\['answer\_time'\] = time(); // 數據入庫 if($this -> leaveMessageTable -> save($data) === false){ $this -> error('回復失敗'); }else{ $this -> success('回復成功'); } } /\*\* \* \[delete 刪除留言\] \* @pa[ram](http://www.hmoore.net/) integer $id \[留言id\] \* @return \[type\] \[description\] 本文檔使用 看云 構建 \- 60 - \*/ public function delete($id = null){ if(empty($id)) $this -> error('操作不合法'); //刪除條件 $map\['id'\] = array('in',$id); //刪除留言記錄 if($this -> leaveMessageTable -> where($map) -> delete() === false){ $this -> error('刪除留言失敗'); }else{ $this -> success('刪除留言成功'); } } /\*批量刪除留言\*/ public function batchDelete($id = null){ if(empty($id)) $this -> error('操作不合法'); $this -> delete($id); } } ?> \*/ public function delete($id = null){ if(empty($id)) $this -> error('操作不合法'); //刪除條件 $map\['id'\] = array('in',$id); //刪除留言記錄 if($this -> leaveMessageTable -> where($map) -> delete() === false){ $this -> error('刪除留言失敗'); }else{ $this -> success('刪除留言成功'); } } /\*批量刪除留言\*/ public function batchDelete($id = null){ if(empty($id)) $this -> error('操作不合法'); $this -> delete($id); } } ?> 本文檔使用 看云 構建 - 61 -
                  <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>

                              哎呀哎呀视频在线观看