Index.php
3.04 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
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
class IndexController extends QLib_Action
{
public function init()
{
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
}
//http://api.beastore.com/?method=orders.orders.li
public function indexAction()
{
$module = $this->_get('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 不能为空.');
}
list($project, $class, $function) = $this->moduleMap;
$version = $this->_getParam('version', 1);
$className = 'QModels_' . ucwords($project) . '_V' . $version . '_' . ucwords($class);
$classPathFile = $this->_config()->application->library . Q_DS . implode(Q_DS, explode('_', $className)) . '.php';
if (file_exists($classPathFile) === false) {
$this->helpJsonResult(500, ' Error\'s Api Method.');
}
if (class_exists($className) === false || method_exists($className, $function) === false) {
$this->helpJsonResult(500, ' Error\'s Api Class Or Function.');
}
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;
}
}
//http://api.open.yohobuy.com/?method=product
public function WebserviceAction()
{
$module = $this->_get('module');
$moduleMap = explode('.', $module);
if (count($moduleMap) !== 2) {
throw new Yar_Server_Exception('module 格式不正确.');
}
list($project, $class) = $moduleMap;
$className = 'QModels_' . ucwords($project) . '_' . ucwords($class);
$classPathFile = $this->_config()->application->library . Q_DS . implode(Q_DS, explode('_', $className)) . '.php';
if (file_exists($classPathFile) === false) {
throw new Yar_Server_Exception('Not Class.');
}
$className = 'QModels_' . ucwords($project) . '_' . ucwords($class);
$service = new Yar_Server(new $className());
$service->handle();
}
}