HiboxInterfaceTestController.php
3.02 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Hibox接口测试类控制器
*/
class HiboxInterfaceTestController extends Controller
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column1', meaning
* using two-column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/column1';
/**
* @return array action filters
*/
public function filters()
{
return array(
//'accessControl',
);
}
/**
* 首页
*/
public function actionIndex()
{
$model = new HiboxInterfaceTestForm;
$this->performAjaxValidation($model);
$this->render('index', array(
'model' => $model,
));
}
/**
* AJAX方式测试接口
*/
public function actionAjaxTestInterface()
{
$yiiRequest = Yii::app()->request;
$platform = $yiiRequest->getPost('PLAT', null);
$request = $yiiRequest->getPost('CALL', null);
if ( isset($request, $platform) && array_key_exists($platform, ReplaceViewDataValue::getReplaced(95, null, false)) )
{
// 将字符串解析到变量中
parse_str($request);
// 加载的测试类文件名称
$testClassName = ReplaceViewDataValue::getReplaced(95, $platform);
if ( isset($r, $CALL) && is_string($testClassName))
{
$GLOBALS["PLAT_DIR_PATH"] = $platform;
$GLOBALS["POST_PARAM_CALL"] = $CALL;
include realpath(Yii::app()->basePath. "/extensions/HiboxInterface/TestBase.php");
include realpath(Yii::app()->basePath. "/extensions/HiboxInterface/interface.php");
include realpath(Yii::app()->basePath. "/extensions/HiboxInterface/$testClassName.php");
// 字符串分割为数组: array(0 => Action动作, 1 => Method方法)
$request = explode('/', $r);
echo "输入格式为:". PHP_EOL;
print_r($request);
// 调用各个平台下的接口测试方法
if (class_exists($testClassName, false) && is_callable(array($testClassName, $request[0]), false))
{
@call_user_func(array($testClassName, $request[0]), $request[1]);
}
else
{
echo "请检查接口是否存在.";
}
Yii::app()->end();
}
}
}
/**
* AJAX方式翻译JSON
*/
public function actionAjaxTransferJson()
{
$data = "";
$jsonData = Yii::app()->request->getPost('JSON', null);
if ( $jsonData !== null )
{
$jsonData = "{\"data\":\"$jsonData\"}";
$transferObject = json_decode($jsonData);
if ( is_object($transferObject) && isset($transferObject->data) )
{
$data = $transferObject->data;
}
}
echo $data;
}
/**
* AJAX方式验证表单
* @param object CModel
*/
protected function performAjaxValidation($model)
{
if (isset($_POST['ajax']) && $_POST['ajax']==='hibox-interface-test-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}