Documentation Index
Fetch the complete documentation index at: https://discuz.p.cafe/llms.txt
Use this file to discover all available pages before exploring further.
_## _概述
Discuz! X5.0 与 WitFrame 云平台进行结合,增加了云插件。通过云插件中,您不仅可以不必担心代码泄露的风险,而且可以通过 RESTful API 接口完全调用 Discuz! 的所有内容。
云插件是基于 WitFrame 云平台进行的开发,因此您需要首先了解 WitFrame 应用的开发方法。
要开发适配 Discuz! X5.0 的云插件您需要在您开发的 WitFrame 应用中添加 /controllers/Discuz 目录,然后添加 Config.php 返回配置信息的接口文件:
<?php
class Discuz_ConfigController extends ApiController {
const Config = array(
array(
'type' => 'page',
'name' => '测试页面',
'page' => 'discuz_page1',
),
array(
'type' => 'diy',
'name' => '测试DIY',
'page' => 'discuz_page1',
),
);
public function indexAction() {
return $this->successMessage('', self::Config);
}
}
配置说明:
- type: 当前云插件包含的入口类型,page 为页面类型,diy 为 DIY 类型。
- name: 入口名称。
- page: 页面地址,如上例中,云插件入口的实际地址为
index.php?index=witframe&path=Sample/v1/discuz_page1。
针对 discuz_page1 我们添加 Page1.php 文件,注意首字母大写:
<?php
class Discuz_Page1Controller extends ApiController {
public function indexAction() {
try {
$v = Lib\Site::Discuz_Restful('/profile');
} catch (Exception $e) {
echo $e->getMessage();
}
echo '当前用户 '.$v['data']['user']['username'];
$url = Common::getAPIURI('/Sample/v1/discuz_page1');
echo '<a href="'.$url.'?'.time().'">'.$url.'</a>';
}
}
此例中我们的云插件通过 RESTful API 接口 Lib\Site::Discuz_Restful 直接调用了当前用户的身份信息。如果您在 Discuz! 有自己设计的 API 接口,也可以调用到。
友情提示: 如果您的云插件需要使用 Discuz_Restful 接口,那么开发中的网站以及今后站长的站点必须拥有公网 IP,否则 WitFrame 无法访问到接口数据。
开发的云插件在 WitFrame 市场提审、上线后,站长第一次访问”插件管理”的”云插件”入口时会自动注册站点,然后在”应用市场”购买应用。应用启用后,在 Discuz! 的插件管理,可以直接看到您开发的云插件。