123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- class MockController
- {
-
- public function simple()
- {
- header('Access-Control-Allow-Origin:*');
- header('Access-Control-Allow-Methods:POST,GET,PUT,DELETE,PATCH,OPTIONS');
- header('Access-Control-Allow-Headers:x-requested-with,content-type,x-custom-header,Accept,Authorization,other_header,x-csrf-token');
- header("Content-type: text/html; charset=UTF-8");
- $project_id = $_GET['projectID'];
- $result_type = $_GET['resultType'] ? $_GET['resultType'] : 'success';
- $type = array(
- 'POST' => '0',
- 'GET' => '1',
- 'PUT' => '2',
- 'DELETE' => '3',
- 'HEAD' => '4',
- 'OPTIONS' => '5',
- 'PATCH' => '6'
- );
- $request_type = $type[$_SERVER['REQUEST_METHOD']];
- $api_uri = $_GET['uri'];
- $service = new MockModule();
- switch ($result_type) {
- case 'success':
- {
- $result = $service->success($project_id, $api_uri, $request_type);
- break;
- }
- case 'failure':
- {
- $result = $service->failure($project_id, $api_uri, $request_type);
- break;
- }
- default:
- {
- exit('error result type.');
- }
- }
- if ($result) {
- exit($result);
- } else {
- exit('找不到mock数据: (1)服务端未设置mock支持 (2)POST请求不支持直接在浏览器输入地址请求');
- }
- }
-
- public function mock()
- {
- header('Access-Control-Allow-Origin:*');
- header('Access-Control-Allow-Methods:POST,GET,PUT,DELETE,PATCH,OPTIONS');
- header('Access-Control-Allow-Headers:x-requested-with,content-type,x-custom-header,Accept,Authorization,other_header,x-csrf-token');
- header("Content-type: application/json; charset=UTF-8");
- $project_id = $_GET['projectID'];
- $type = array(
- 'POST' => '0',
- 'GET' => '1',
- 'PUT' => '2',
- 'DELETE' => '3',
- 'HEAD' => '4',
- 'OPTIONS' => '5',
- 'PATCH' => '6'
- );
- $request_type = $type[$_SERVER['REQUEST_METHOD']];
- $api_uri = $_GET['uri'];
- $module = new MockModule();
- $result = $module->getMockResult($project_id, $api_uri, $request_type);
- if ($result) {
- $decoded_result = htmlspecialchars_decode($result);
- if ($decoded_result) {
- exit($decoded_result);
- }
- exit($result);
- } else {
- exit('找不到mock数据: (1)服务端未设置mock支持 (2)POST请求不支持直接在浏览器输入地址请求');
- }
- }
- }
|