联系官方销售客服

1835022288

028-61286886

求助 版主:官方研发技术组
接口里回调方法的问题把下面回复按这种格式加入到回调参数里具体
类型:迅睿CMS 更新时间:2020-09-05 13:36:26 接口

接口里回调方法的问题

public function ppp_piccount_data($data) {
    
        $rt = [];
        // 这里根据项目的$data输出格式来定义PHP的数据写法,
        // 每个接口的写法几乎不一样,下面是测试例子
  $keywordsArr = [];
  if($data['keywords']!='')
  {
   $keywordsArr = explode(',',rtrim($data['keywords'],','));
  }
  $img = [];
  foreach ($data['images'] as $i) {
   $img[] = dr_get_file($i['file']);
  }
  $list = [];
  if ($data['list']) {
            foreach ($data['list'] as $t) {
                $list[] = [
                    'author' => $t['author'],
     'id' => $t['id'],
                    'content' => dr_replace_emotion($t['content']),
     'support'=>$t['support'],
                    'avatar'=>dr_avatar($t['uid']),
                    'inputtime' => dr_date($t['inputtime'], 'Y-m-d H:i:s'),
     
               
                ];
    
            }
        }
  $rt[] = [
      'title' => $data['title'],
      'id' => $data['id'],
   'author'=>$data['author'],
   'keywords' => $keywordsArr,
   'avatar'=>dr_avatar($data['uid']),
   'images' => $img,
   'list' => $list,
   'updatetime' => dr_date($data['_updatetime'], 'Y-m-d H:i:s'),

  ];      
        return $rt;
    }
}

把下面rlist回复按这种格式加入到回调参数里,具体要怎么加进去

  {
                "id": "41",
                "cid": "599",
                "cuid": "6",
                "uid": "1",
                "author": "去寻梦",
                "content": "一级评论[ciya]",
                "support": "0",
                "oppose": "0",
                "avgsort": "0.00",
                "sort1": "0",
                "sort2": "0",
                "sort3": "0",
                "sort4": "0",
                "sort5": "0",
                "sort6": "0",
                "sort7": "0",
                "sort8": "0",
                "sort9": "0",
                "reply": "0",
                "in_reply": "1",
                "status": "1",
                "inputip": "171.113.123.98",
                "inputtime": "1599280133",
                "rlist": [
                    {
                        "id": "42",
                        "cid": "599",
                        "cuid": "6",
                        "uid": "1",
                        "author": "去寻梦",
                        "content": "2级评论",
                        "support": "0",
                        "oppose": "0",
                        "avgsort": "0.00",
                        "sort1": "0",
                        "sort2": "0",
                        "sort3": "0",
                        "sort4": "0",
                        "sort5": "0",
                        "sort6": "0",
                        "sort7": "0",
                        "sort8": "0",
                        "sort9": "0",
                        "reply": "41",
                        "in_reply": "0",
                        "status": "1",
                        "inputip": "171.113.123.98",
                        "inputtime": "1599280147"
                    },
                    {
                        "id": "43",
                        "cid": "599",
                        "cuid": "6",
                        "uid": "1",
                        "author": "去寻梦",
                        "content": "3级评论",
                        "support": "0",
                        "oppose": "0",
                        "avgsort": "0.00",
                        "sort1": "0",
                        "sort2": "0",
                        "sort3": "0",
                        "sort4": "0",
                        "sort5": "0",
                        "sort6": "0",
                        "sort7": "0",
                        "sort8": "0",
                        "sort9": "0",
                        "reply": "41",
                        "in_reply": "0",
                        "status": "1",
                        "inputip": "171.113.123.98",
                        "inputtime": "1599280179"
                    }
                ]
            }
        ],


回帖
  • 官方研发实习技术
    #1楼    官方研发实习技术
    2020-09-05 13:04:27
    Chrome 0
    楼主编程水平有待提高啊,这是最基础的php入门语法问题了
    public function ppp_piccount_data($data) {
        
            $rt = [];
            // 这里根据项目的$data输出格式来定义PHP的数据写法,
            // 每个接口的写法几乎不一样,下面是测试例子
    	  $keywordsArr = [];
    	  if($data['keywords']!='')
    	  {
    	   $keywordsArr = explode(',',rtrim($data['keywords'],','));
    	  }
    	  $img = [];
    	  foreach ($data['images'] as $i) {
    	   $img[] = dr_get_file($i['file']);
    	  }
    	  $list = [];
    	  if ($data['list']) {
    				foreach ($data['list'] as $t) {
    					
    					$rlist = [];
    					if ($t['rlist']) {
    						foreach ($t['rlist'] as $t2) {
    							$rlist[] = [
    								'author' => $t2['author'],
    								'id' => $t2['id'],
    								'content' => dr_replace_emotion($t2['content']),
    								'support'=>$t2['support'],
    								'avatar'=>dr_avatar($t2['uid']),
    								'inputtime' => dr_date($t2['inputtime'], 'Y-m-d H:i:s'),
    							];
    						}
    					}
    					$list[] = [
    						'author' => $t['author'],
    						'id' => $t['id'],
    						'content' => dr_replace_emotion($t['content']),
    						'support'=>$t['support'],
    						'avatar'=>dr_avatar($t['uid']),
    						'inputtime' => dr_date($t['inputtime'], 'Y-m-d H:i:s'),
    						'rlist' => $rlist,
    					];
    				}
    			}
    		  $rt[] = [
    			  'title' => $data['title'],
    			  'id' => $data['id'],
    			   'author'=>$data['author'],
    			   'keywords' => $keywordsArr,
    			   'avatar'=>dr_avatar($data['uid']),
    			   'images' => $img,
    			   'list' => $list,
    			   'updatetime' => dr_date($data['_updatetime'], 'Y-m-d H:i:s'),
    		  ];      
    			return $rt;
    		}
    	}
    满意答案
  • 眼镜
    #2楼    眼镜
    2020-09-05 13:13:38
    Chrome 1
    一楼代码很完美了,就是简单的数组循环写法
  • 华仔
    #3楼    华仔
    2020-09-05 13:36:26
    Chrome 0
    @官方研发实习技术:非常感谢!设为满意答案