查看了下别的api的返回示例 我选出这样的返回样式
{
“resultcode”:”200”,
“reason”:”Successed!”,
“result”:{
“count”: 11,
“commentlist”: []
},
“notice”….
}
当前api访问的错误和原因加 非当前api的处理(比如notice 通知 注:来自开源中国ios版本的代码理解 他每个api都有可能有notice节点) 都跟result同级
很多时候(特别是app刚刚启动)经常会同时发起好几个api请求 于是乎我就想 能不能几个api同时请求呢我就使用php来做了个测试结果是可以做到的
<?php
namespace Home\Controller;
use Think\Controller;
use Home\Action\Article;
use Home\Action\Chapter;
class IndexController extends Controller {
protected $response_data = array ();
protected function response() {
if (count ( $this->response_data ) > 0) {
switch ($this->dtype) {
case "xml" :
exit ( xml_encode ( $this->response_data ) );
break;
default :
exit ( json_encode ( $this->response_data ) );
break;
}
}
}
public function index() {
$actions = array();
foreach ( $_GET as $key => $action ) {
$actions[$key] = $action;
}
foreach ( $_POST as $key => $action ) {
$actions[