Index.php
2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class IndexController extends QLib_Actions_Api
{
public function init()
{
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
}
public function indexAction()
{
$params = array_merge($this->_getRequests(), $this->_getParams());
$module = empty($params['module']) ? '' : $params['module'];
$this->moduleMap = $moduleMap = explode('.', $module);
if (count($moduleMap) !== 3) {
$this->helpJsonResult(500, 'module 格式不正确.');
}
$params = array_merge($this->_getRequests(), $this->_getParams());
if (empty($params['client_secret'])) {
$this->helpJsonResult(500, ' 参数 client_secret 不能为空.');
}
if (empty($params['client_version'])) {
$this->helpJsonResult(500, ' 参数 client_version 不能为空.');
}
if (empty($params['client_type'])) {
$this->helpJsonResult(500, ' 参数 client_type 不能为空.');
}
//app.passport.signin
list($project, $class, $function) = $this->moduleMap;
//YHMApi_App_V1_Passport
$v = empty($params['v']) ? 1 : $params['v'];
$className = 'YHMApi_' . ucwords($project) . '_V' . $v . '_' . ucwords($class);
$classPathFile = $this->_config()->application->brightKnight . Q_DS . implode(Q_DS, explode('_', $className)) . '.php';
if (file_exists($classPathFile) === false) {
$this->helpJsonResult(500, ' 没有这个接口. ');
}
if (class_exists($className) === false || method_exists($className, $function) === false) {
$this->helpJsonResult(500, ' 没有这个接口方法.');
}
if (method_exists($className, 'init') === true) {
$className::init($params);
}
$returnType = empty($params['return_type']) ? 'json' : $params['return_type'];
$fields = empty($params['fields']) ? '*' : $params['fields'];
$result = $className::$function ($params, $fields);
switch ($returnType) {
case 'txt':
echo $result;
break;
case 'jsonp':
header('Content-type: application/json');
if (empty($params['callback'])) {
$this->helpJson($result);
} else {
exit($params['callback'] . '(' . json_encode($result) . ')');
}
break;
case 'sfxml':
echo stripslashes($result);
break;
default:
$this->helpJson($result);
break;
}
}
}