|
|
@@ -7,6 +7,7 @@ class MockController extends BaseController {
|
|
|
public function add(){
|
|
|
$page_id = I("page_id/d");
|
|
|
$template = I("template");
|
|
|
+ $path = I("path") ? I("path") : '/';
|
|
|
$login_user = $this->checkLogin();
|
|
|
$uid = $login_user['uid'] ;
|
|
|
$page = M("Page")->where(" page_id = '$page_id' ")->find();
|
|
|
@@ -14,7 +15,10 @@ class MockController extends BaseController {
|
|
|
$this->sendError(10303);
|
|
|
return ;
|
|
|
}
|
|
|
-
|
|
|
+ if(substr($path, 0, 1) !== '/'){
|
|
|
+ $path = '/' .$path ;
|
|
|
+ }
|
|
|
+ $item_id = $page['item_id'] ;
|
|
|
$json = json_decode(htmlspecialchars_decode($template)) ;
|
|
|
if(!$json){
|
|
|
$this->sendError(10101,'为了服务器安全,只允许写符合json语法的字符串');
|
|
|
@@ -28,6 +32,7 @@ class MockController extends BaseController {
|
|
|
D("Mock")->where("page_id = '$page_id' ")->save(array(
|
|
|
"uid"=>$uid ,
|
|
|
"template"=>$template ,
|
|
|
+ "path"=>$path ,
|
|
|
"last_update_time" => date("Y-m-d H:i:s"),
|
|
|
));
|
|
|
}else{
|
|
|
@@ -35,8 +40,9 @@ class MockController extends BaseController {
|
|
|
"unique_key"=>$unique_key ,
|
|
|
"uid"=>$uid ,
|
|
|
"page_id"=>$page_id ,
|
|
|
- "item_id"=> $page['item_id'] ,
|
|
|
+ "item_id"=> $item_id ,
|
|
|
"template"=>$template ,
|
|
|
+ "path"=>$path ,
|
|
|
"addtime" => date("Y-m-d H:i:s"),
|
|
|
"last_update_time" => date("Y-m-d H:i:s"),
|
|
|
"view_times"=>0
|
|
|
@@ -45,6 +51,7 @@ class MockController extends BaseController {
|
|
|
|
|
|
$this->sendResult(array(
|
|
|
"page_id"=>$page_id ,
|
|
|
+ "path"=>$path ,
|
|
|
"unique_key"=>$unique_key
|
|
|
));
|
|
|
}
|
|
|
@@ -64,7 +71,7 @@ class MockController extends BaseController {
|
|
|
|
|
|
// 根据唯一key获取mock的响应数据
|
|
|
public function infoByKey(){
|
|
|
- $unique_key = $_REQUEST["unique_key"];
|
|
|
+ $unique_key = I("unique_key") ;
|
|
|
$page = D("Mock")->where(" unique_key = '%s' ",array($unique_key))->find();
|
|
|
$template = $page['template'] ;
|
|
|
$res = http_post("http://127.0.0.1:7123/mock",array(
|
|
|
@@ -82,5 +89,33 @@ class MockController extends BaseController {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ // 根据item_id和path获取
|
|
|
+ public function infoByPath(){
|
|
|
+ $item_id = I("item_id") ;
|
|
|
+ $path = I("path") ? I("path"): '/' ;
|
|
|
+ $page = D("Mock")->where(" item_id = '%s' and path = '%s' ",array($item_id,$path) )->find();
|
|
|
+ if(!$page){
|
|
|
+ echo 'no such path';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $template = $page['template'] ;
|
|
|
+ $mock_host = env("MOCK_HOST",'127.0.0.1');
|
|
|
+ $mock_port = env('MOCK_PORT','7123');
|
|
|
+ $res = http_post("http://{$mock_host}:{$mock_port}/mock",array(
|
|
|
+ "template"=> htmlspecialchars_decode($page['template'])
|
|
|
+ ));
|
|
|
+ if($res){
|
|
|
+ $sql = " update mock set view_times = view_times + 1 where id = {$page['id']} ";
|
|
|
+ D("Mock")->execute($sql);
|
|
|
+ $json = json_decode($res) ;
|
|
|
+ if(!$json){
|
|
|
+ $this->sendError(10101,'为了服务器安全,只允许写符合json语法的字符串');
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ echo $res ;
|
|
|
+ }else{
|
|
|
+ echo "mock服务暂时不可用。网站管理员安装完showdoc后需要另行安装mock服务,详情请打开https://www.showdoc.com.cn/help";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|