找回密码
 立即注册
查看: 23|回复: 0

CansCode API 模板入门

[复制链接]

8

主题

11

回帖

141

积分

管理员

积分
141
发表于 5 小时前 | 显示全部楼层 |阅读模式
创建模板目录结构为:

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

Main.php示例代码:

  1. <?php
  2. namespace Resource\Template\default;

  3. use Logic\Important\Hooks;
  4. use Logic\Important\Rote;
  5. use Logic\Important\Tos;
  6. use Resource\Template\default\cp;


  7. class Main
  8. {
  9.     /* 必要函数,用户修改配置后,数据将会在这里回调返回! */
  10.     public function CallBack($parameter)
  11.     {


  12.         $data = [
  13.             "footer_text" => $parameter['desc'],
  14.             "footer_qrlist" => [
  15.                 [
  16.                     "name" => "微信",
  17.                     "url"  => $parameter['qr_urla']
  18.                 ],
  19.                 [
  20.                     "name" => "QQ",
  21.                     "url"  => $parameter['qr_urlb']
  22.                 ]
  23.             ]
  24.         ];

  25.         cp::setteP($data);
  26.         Tos::sendmsg(200);
  27.         
  28.     }
  29.     /* 统一自动加载函数 */
  30.     public function init()
  31.     {
  32.         /* 检测版本 */
  33.         $this->getUpdates();

  34.         /* 检测授权 */
  35.         $this->getAuthCert();

  36.         /* 发送后台通知 */
  37. //        $this->SendNotification("/","有新版本待更新!","默认模板有新的版本,请前往更新!");
  38.     }
  39.     /* 检查系统版本状态 */
  40.     public function getUpdates()
  41.     {

  42.     }
  43.     /* 检查授权状态 */
  44.     public function getAuthCert()
  45.     {
  46.         $auth = new Rote();
  47.         $res = $auth->appCertificate('5a6e619c-29d1-2890-1776-14078b36b4c3');
  48.         if($res['code'] !== '5200'){
  49.            error_log('未授权');
  50.         }else{
  51.             error_log('已授权');
  52.         }
  53.     }
  54.     /* 向后台发送通知 */
  55.     public function SendNotification ($url='',$title='',$content='')
  56.     {
  57. //        Hooks::Register("WebNotification",2,function ($parameter) use ($url,$title,$content) {
  58. //            $parameter['name'] = json_decode(Tos::ReadFile(__DIR__ . '/./package.json')['content'])->tep_name;
  59. //            $parameter['url'] = $url;
  60. //            $parameter['title'] = $title;
  61. //            $parameter['content'] = $content;
  62. //            return $parameter;
  63. //        },10);
  64.     }
  65. }
复制代码
package.json示例
  1. {
  2.   "tep_name": "默认模板",
  3.   "tep_version": "0.0.1",
  4.   "tep_image": "https://imgsbad.semoun.com/uploads/2025/03/19/67da24298292e.jpg",
  5.   "tep_brief": "自带的默认模板",
  6.   "tep_cansid": "default",
  7.   "tep_page": true,  //是否有配置页面
  8.   "tep_PagePath":"ConfigurationPage.php",  // 配置页面路径
  9.   "tep_code":"5a6e619c-29d1-2890-1776-14078b36b4c3",  // 申请的UUID
  10.   "author_name": "CansCode"
  11. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|CansCode - 交流论坛 ( 苏ICP备2022039294号 )

GMT+8, 2025-5-19 19:33 , Processed in 0.232084 second(s), 31 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表