<?php
// +----------------------------------------------------------------------
// | Quotes [未来可期]
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | Author: 微站网 www.btwcms.com 作者QQ：1617643
// +----------------------------------------------------------------------
// | Date: 2020年2月5日
// +----------------------------------------------------------------------


include '../app/common.php';


$act = isset($_GET['act']) ? daddslashes($_GET['act']) : null;

@header('Content-Type: application/json; charset=UTF-8');

if (!$userrow['uid']) {
    exit('{"code":-1,"msg":"登录信息失效"}');
}

switch ($act) {

    case 'buyLevel':
        //分站的价格
        if($conf['level_status']==0){
        	$result = array("code" => -1, "msg" => "当前站点未开启分站功能");
            exit(json_encode($result));
        }
        if ($userrow['money'] < $conf['level_price']) {
            $result = array("code" => -1, "msg" => "余额不足");
            exit(json_encode($result));
        } else {
            $code = random(20);
            $userrow['money'] = $userrow['money'] - $conf['level_price'];
            $DB->exec("UPDATE `wcms_user` SET `money` ='{$userrow['money']}',`api_key` ='{$code}' WHERE `uid`='{$userrow['uid']}'");
            saveLog($userrow['uid'], "购买API分站");
            $result = array("code" => 1, "msg" => "购买成功", "url" => "level.php");
            exit(json_encode($result));
        }
        break;

    //分站使用教程
    case 'useMethod':
        $data = "1.下载API分站源码<br><br>2.将源码上传到自己的服务器或主机空间<br><br>3.进入分站后台网站设置<br><br>4.将通信API中显示的主站域名及通信密钥填写到分站后台<br><br>5.开始使用";
        $result = array("code" => 1, "msg" => "获取成功", "data" =>$data);
        exit(json_encode($result));
        break;
    //下载分站源码包
    case 'getLevelCodeZip':
        if($userrow['api_key']){
            $result = array("code" => 1, "msg" => "获取成功", "url" => $conf['level_pack']);
            exit(json_encode($result));
        }else{
            $result = array("code" => -1, "msg" => "当前账户未开通分站权限");
            exit(json_encode($result));
        }
        break;

    case 'getMyKey':
        if($userrow['api_key']){
            $siteurl = ($_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/';
            $key = $userrow['api_key'];
            $data = "主站域名：<br>$siteurl<br>您的通信密钥：<br>$key<br><br>提示:<br>点击密钥长按可进行复制<br>请勿将密钥告知他人";//
            $result = array("code" => 1, "msg" => "获取成功", "data" =>$data);
            exit(json_encode($result));
        }else{
            $result = array("code" => -1, "msg" => "当前账户未开通分站权限");
            exit(json_encode($result));
        }
        break;

    default:

        break;


}

?>