微擎獨立后台TP5+VUE分離+小程序


微擎2.0已經不允許從應用入口直接跳獨立后台,需要從應用菜單中進入獨立后台。

如菜單標識入口設置為cms,就是對應的site.php中doWebCms方法
在該方法中,把小程序,公眾號等key和secret等放到session中,然后跳轉到tp5的入口文件即可。
有點需要注意,TP5的session前綴默認是think,所有直接seesion::get()是獲取不到微擎session的

*****微擎****** //doWeb為后台方法 public function doWebCms() { global $_W,$_GPC; $this->checkModuleFile();// 驗證模塊核心文件 $this->session();// 設置session登錄狀態 $this->jump_cms(); // 跳轉到獨立后台 } private function checkModuleFile() { $module_file = __DIR__ . '/api/thinkphp/index.php'; !file_exists($module_file) && itoast('模塊文件不存在', referer(), 'error'); if (session_status() != PHP_SESSION_ACTIVE){ itoast('未開啟session', referer(), 'error'); } } //單管理模式,自動登錄。如果有管理員權限控制,那還是手動登錄較好 private function session() { @session_start(); $_SESSION['qy2019'] = [ 'wxapp' => [ 'wxapp_id' => $this->wechat_app['uniacid'] ], 'we7_data' => [ 'wxapp_id' => $this->wechat_app['uniacid'], 'app_name' => $this->wechat_app['name'], 'app_id' => $this->wechat_app['key'], 'app_secret' => $this->wechat_app['secret'], ], 'is_login' => true ]; } private function jump_cms() { global $_W; $url = "{$_W['siteroot']}addons/{$_W['current_module']['name']}/cms/index.html"; header('Location:' . $url); //header跳轉不好用,session,緩存等都無法傳遞。改用js跳轉 exit; } 
******TP5****** public function login(){ session_start(); dump($_SESSION['qy2019']); return $this->fetch(); } 

TP5數據庫配置文件自動獲取微擎配置

defined('IN_IA') or define('IN_IA', true); 這句必須要有,不然會報錯

defined('IN_IA') or define('IN_IA', true); require __DIR__ . '/../../../../data/config.php'; $db=[]; if (empty($config['db']['master'])){ $db=$config['db']; }else{ $db=$config['db']['master']; } return [ // 數據庫類型 'type' => 'mysql', // 服務器地址 'hostname' => $db['host'], // 數據庫名 'database' => $db['database'], // 用戶名 'username' => $db['username'], // 密碼 'password' => $db['password'], // 端口 'hostport' => $db['port'], 

VUE打包后的生產版如何在微擎中使用

1、vue默認打包是根目錄位置,要放在其他目錄使用必須新建配置vue.config.js文件,配置baseUrl: "/cms/"。 放入tp5默認入口public目錄下 ,即public/cms 2、頁面跳轉用 this.$router.push({path: '/login', query:{id:id}}); 方式。 3、axios請求用相對路徑 Api_url='../' //相對路徑指向public/index.php 

那么當訪問微擎的doWebCms()方法,就自動跳轉到了vue的index.html頁面

微擎底部版權--商業版不顯示,非商業版顯示

判斷方法是site.php中查看$_W['setting']['copyright']['footerright']是否存在,商業版有信息,非商業版為空。

//api端:site.php public function doMobileCpy() { global $_W; header('Access-Control-Allow-Origin: *'); header("Access-Control-Allow-Headers: token,Origin, X-Requested-With,X_Requested_With, Content-Type, Accept"); header('Access-Control-Allow-Methods: POST,GET,PUT'); $arr=$_W['setting']['copyright']['footerright']; $json=json_encode($arr); echo $json; } 
//vue端:app.vue <div class="friend-link" v-if="!cpy"> <a href="http://www.w7.cc">微信開發</a>&emsp; <a href="http://s.w7.cc">微信應用</a>&emsp; <a href="http://bbs.w7.cc">微擎論壇</a>&emsp; <a href="http://s.w7.cc">聯系客服</a> </div> <div class="friend-link" v-else> {{cpy}} </div> mounted() { const that=this const host=window.location.host const protocol=window.location.protocol axios.get(protocol+'//'+host+"/app/index.php?i=2&c=entry&do=Cpy&m=xxxx") .then(function(res){ that.cpy=res.data }); } 

獨立小程序轉微擎版

小程序既然是獨立的,就不需要使用微擎的小程序文件包了。
既然是獨立的肯定也不能訪問微擎的wxapp.php,而是訪問獨立的api,路徑就是:http://www.xxx.com/addons/應用模塊名稱/tp5/index.php
其實只需要加入一個微擎的siteinfo文件,app.js引入該文件的域名http://www.xxx.com和uniacid做使用,訪問API即可。

注意支付回調時,不同unicid的問題

另一篇文章有介紹

參考:http://www.ruhuashop.com

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM