CansCodeAPI模板开发文档说明

2025-05-19 05:40:01

创建模板目录结构为:

|-mytemplate
|---user 用户中心文件夹,此文件夹内页面均自动判断登录
|---Main.php  主逻辑文件
|---package.php 说明文件
|---ConfigurationPage.php  模板编辑页面



Main.php示例代码:

<?php
namespace ResourceTemplatedefault;
use LogicImportantHooks;
use LogicImportantRote;
use LogicImportantTos;
use ResourceTemplatedefaultcp;

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",
  "author_name": "CansCode"
}

canscode CansCode API 模板开发文档说明