- <?php
- error_reporting(E_ERROR);
- define('API', 'api');
- define('DOCROOT',__DIR__);
- define('API_SECRET','yikoo.net'); // 根据需要修改
- //兼容各种提交方式,get、post、字节流
- $data1 = $_GET;
- $data2=file_get_contents("php://input");
- parse_str($data2, $data2);
- $data = array_merge($data2, $data1);
- unset($data1,$data2);
- //接口权限验证
- $token = md5($data['time'] . API_SECRET);
- if (!isset($data['token']) || $token != $data['token']) {
- exit('token error');
- }
- if ( !isset($data['action']) || !$data['action'] ) {
- exit('action error');
- }
- foreach ($data as $k => $v) {
- $v = trim($v);
- $v = strip_tags($v);
- $v = addslashes($v);
- $data[$k] = $v;
- }
- $data['action']=explode('_',$data['action']);
- try{
- include DOCROOT . '/model/' . $data['action'][0] . '/' . $data['action'][0] . '.php';
- $api = new $data['action'][0]($data);
- $api->$data['action'][1]();
- }
- catch (Exception $e) {
- echo $e->getMessage();
- }
- class api {
- public $data = array();
- function __construct($data) {
- //根据需要,在此加载公用资源;
- $this->data = $data;
- }
- }
- ?>
- //该片段来自于http://www.codesnippet.cn/detail/2411201411035.html
来源: http://www.codesnippet.cn/detail/2411201411035.html