Merge branch 'master' of git.int.haowumc.com:composer/php-json-rpc

# Conflicts:
#	src/Middleware/Security.php
This commit is contained in:
候学杰 2019-01-25 19:02:16 +08:00
commit 8477c76407
7 changed files with 43 additions and 26 deletions

View File

@ -170,3 +170,19 @@ http://host/rpc/doc.html 文档地址
严格使用系统定义错误码 详见json-rpc/src/Server/JsonRpcBase.php 严格使用系统定义错误码 详见json-rpc/src/Server/JsonRpcBase.php
###更新日志 ###更新日志
###文档注释格式
```
/**
* @title 用户登录API
* @url https://wwww.baidu.com/login
* @method POST
* @param 类型 字段名称 描述 默认 是否必须
* @param string password 密码 空 必须
* @code 1 成功
* @code 2 失败
* @return int code 状态码(具体参见状态码说明)
* @return string msg 提示信息
*/
```

View File

@ -35,7 +35,7 @@ return [
], ],
'api' => [ 'api' => [
'local' => true, 'local' => true,
'base_uri' => env('RPC_API_URI','http://api.dev.haowumc.com'), 'base_uri' => env('RPC_API_URI','http://sapi.dev.haowumc.com'),
], ],
'op' => [ 'op' => [
'local' => true, 'local' => true,

View File

@ -42,7 +42,7 @@ class BaseServiceProvider extends ServiceProvider
$this->setupConfig(); $this->setupConfig();
$this->app->singleton("rpc.logger", function () { $this->app->singleton("rpc.logger", function () {
$config = config('rpc'); $config = config('rpc');
$stream = new StreamHandler($this->app->storagePath() . $config['log_path']); $stream = new StreamHandler($config['log_path']);
$stream->setFormatter(new $config['log_formatter']()); $stream->setFormatter(new $config['log_formatter']());
$logger = new Logger('RPC.LOGGER'); $logger = new Logger('RPC.LOGGER');
return $logger->pushHandler($stream); return $logger->pushHandler($stream);

View File

@ -25,11 +25,6 @@ class JsonRpcMethod extends JsonRpcBase
]; ];
} }
/**
* @param $code
* @param $msg
* @return array
*/
public function error($code, $msg) public function error($code, $msg)
{ {

View File

@ -31,9 +31,9 @@ class JsonRpcServer extends JsonRpcBase
public function handler() public function handler()
{ {
if ($this->request->getContentType() != 'json') { // if ($this->request->getContentType() != 'json') {
return $this->error(self::Rpc_Error_Invalid_Request); // return $this->error(self::Rpc_Error_Invalid_Request);
} // }
try { try {

View File

@ -35,12 +35,9 @@ class JsonRpcTool
*/ */
$view = view(); $view = view();
$params = json_decode($request->input('params'), true); $params = json_decode($request->input('params',"[\r\n]"), true);
$method = $request->input('method'); $method = $request->input('method');
if ($request->method() == Request::METHOD_POST) { if ($request->method() == Request::METHOD_POST) {
try { try {
$result = app('rpc.'.$this->config['name'])->call($method, $params); $result = app('rpc.'.$this->config['name'])->call($method, $params);
$view->share('result', json_encode($result, JSON_PRETTY_PRINT)); $view->share('result', json_encode($result, JSON_PRETTY_PRINT));
@ -52,7 +49,7 @@ class JsonRpcTool
$view->share('method',$method); $view->share('method',$method);
$view->share('endpoint', $this->getEndpoint()); $view->share('endpoint', $this->getEndpoint());
$view->share('methods', $methods); $view->share('methods', $methods);
$view->share('params', json_encode($params)); $view->share('params', json_encode($params,JSON_PRETTY_PRINT));
foreach ($methods as $name => $class) { foreach ($methods as $name => $class) {
$desc[$name] = $this->desc($class[0], $class[1]); $desc[$name] = $this->desc($class[0], $class[1]);

View File

@ -23,17 +23,17 @@
<div class="sidebar-sticky"> <div class="sidebar-sticky">
<ul class="nav flex-column"> <ul class="nav flex-column">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" href="#"> <a class="nav-link active" href="/rpc/doc.html">
<span data-feather="home"></span> <span data-feather="home"></span>
History <span class="sr-only">(current)</span> 文档 <span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="file"></span>
abc
</a> </a>
</li> </li>
{{--<li class="nav-item">--}}
{{--<a class="nav-link" href="#">--}}
{{--<span data-feather="file"></span>--}}
{{--abc--}}
{{--</a>--}}
{{--</li>--}}
</ul> </ul>
</div> </div>
</nav> </nav>
@ -68,9 +68,9 @@
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<label for="inputAddress">Params</label> <label for="inputAddress">Paramsjson 数组)</label>
<input type="text" class="form-control" name="params" id="params" placeholder="逗号分隔" <div id="editor" style="height: 300px">{{$params}}</div>
value="{{$params}}"> <input type="hidden" name="params" id="params" value="{{$params}}">
</div> </div>
</div> </div>
<button type="submit" class="btn btn-primary">Request</button> <button type="submit" class="btn btn-primary">Request</button>
@ -99,6 +99,15 @@
<script src="https://cdn.bootcss.com/twitter-bootstrap/4.2.1/js/bootstrap.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.13.1/highlight.min.js"></script> <script src="https://cdn.bootcss.com/highlight.js/9.13.1/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.13.1/languages/json.min.js"></script> <script src="https://cdn.bootcss.com/highlight.js/9.13.1/languages/json.min.js"></script>
<script src="https://cdn.bootcss.com/ace/1.4.2/ace.js"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/json");
editor.on('change',function(e){
$('#params').val(editor.getValue())
})
</script>
<script>hljs.initHighlightingOnLoad();</script> <script>hljs.initHighlightingOnLoad();</script>
</body> </body>
</html> </html>