CansCode API 模板入门
创建模板目录结构为:|-mytemplate
|---user 用户中心文件夹,此文件夹内页面均自动判断登录
|---Main.php主逻辑文件
|---package.php 说明文件
|---ConfigurationPage.php模板编辑页面
Main.php示例代码:
<?php
namespace Resource\Template\default;
use Logic\Important\Hooks;
use Logic\Important\Rote;
use Logic\Important\Tos;
use Resource\Template\default\cp;
class Main
{
/* 必要函数,用户修改配置后,数据将会在这里回调返回! */
public function CallBack($parameter)
{
$data = [
"footer_text" => $parameter['desc'],
"footer_qrlist" => [
[
"name" => "微信",
"url"=> $parameter['qr_urla']
],
[
"name" => "QQ",
"url"=> $parameter['qr_urlb']
]
]
];
cp::setteP($data);
Tos::sendmsg(200);
}
/* 统一自动加载函数 */
public function init()
{
/* 检测版本 */
$this->getUpdates();
/* 检测授权 */
$this->getAuthCert();
/* 发送后台通知 */
// $this->SendNotification("/","有新版本待更新!","默认模板有新的版本,请前往更新!");
}
/* 检查系统版本状态 */
public function getUpdates()
{
}
/* 检查授权状态 */
public function getAuthCert()
{
$auth = new Rote();
$res = $auth->appCertificate('5a6e619c-29d1-2890-1776-14078b36b4c3');
if($res['code'] !== '5200'){
error_log('未授权');
}else{
error_log('已授权');
}
}
/* 向后台发送通知 */
public function SendNotification ($url='',$title='',$content='')
{
// Hooks::Register("WebNotification",2,function ($parameter) use ($url,$title,$content) {
// $parameter['name'] = json_decode(Tos::ReadFile(__DIR__ . '/./package.json')['content'])->tep_name;
// $parameter['url'] = $url;
// $parameter['title'] = $title;
// $parameter['content'] = $content;
// return $parameter;
// },10);
}
}package.json示例
{
"tep_name": "默认模板",
"tep_version": "0.0.1",
"tep_image": "https://imgsbad.semoun.com/uploads/2025/03/19/67da24298292e.jpg",
"tep_brief": "自带的默认模板",
"tep_cansid": "default",
"tep_page": true,//是否有配置页面
"tep_PagePath":"ConfigurationPage.php",// 配置页面路径
"tep_code":"5a6e619c-29d1-2890-1776-14078b36b4c3",// 申请的UUID
"author_name": "CansCode"
}
页:
[1]