function getToken($url) { //引入微信类库 APP::load(APP_FILE . 'common/class/wechat.class.php'); $weObj = new Wechat(APP::$config['wechat']); // 注意 URL 一定要动态获取,不能 hardcode. $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; $uri = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $signPackage = $weObj->getJsSign($uri); if (!isset($_GET['code'])) { header("Location: " . $url); exit; } $data = $weObj->getOauthAccessToken(); if (!$data) { header("Location: " . $url); exit; } $userinfo = $weObj->getOauthUserinfo($data['access_token'], $data['openid']); $this->assign('signPackage', $signPackage); $_SESSION['openid'] = $data['openid']; }
static function classLoader($classname) { $file = array('Rest' => APP_FILE . 'rest/', 'Model' => APP_FILE . 'model/', 'Controller' => APP_FILE . 'controller/'); if (!empty(APP::$__module)) { $file['Controller'] = $file['Controller'] . APP::$__module . '/'; } foreach ($file as $k => $v) { if (strstr($classname, $k)) { APP::load($v . $classname . '.class.php'); break; } } }
<?php /** * 示例程序 */ // 载入配置文件 require 'config.inc.php'; // 公共处理部分在这里写 echo '公共处理部分<hr>'; APP::load('require_file'); // 处理GET请求 function method_get() { echo 'GET请求'; APP::dump($_GET); APP::dump(SQL::getAll('show tables')); APP::dump(SQL::getAll('show databases')); APP::dump(SQL::getAll('select 1+1 as a')); // 渲染模板 APP::template('test.html'); } // 处理POST请求 function method_post() { echo 'POST请求'; APP::dump($_POST); } // 以下函数用于处理任意请求(当没有定义method_get或method_post时) function method_all() { echo '处理所有请求';