微擎独立后台TP5+VUE分离+小程序

我心飞翔 分类: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();// 验证模块核心文件

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:’ .

******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’ =>

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’]是否存在,商业版有信息,非商业版为空。

_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

//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

未经允许不得转载:肥猫博客 » 微擎独立后台TP5+VUE分离+小程序

回复

我来回复
  • 暂无回复内容