php http返回格式声明,poscms自定义返回数据格式函数

此方法在v2.7.5以上版本支持

默认返回JSON数据格式参数为:msg、code、total、id、return等等

开发者可以在URL参数中加上&function=my_function_test

这时候返回数据格式就会采用自定义换上my_function_test来做转换

实例接口URL

http://www.fc2.com/index.php?c=api&m=data2&auth=472869ef85d15227acb937eac8d89243&function=my_function_test

举例说明:

假设你查询新闻列表数据,需要返回会员的头像(默认是返回uid参数),可以这样自定义返回结果:

第一步:请求地址:

http://www.fc2.com/index.php?c=api&m=data2&auth=472869ef85d15227acb937eac8d89243&function=my_function_test¶m=list action=module module=news num=10

第二步:定义函数:

新在my_helper.php文件中定义上面的函数my_function_test

function my_function_test($data) {

$now = array();

foreach ($data['return'] as $t) {

$t['touxiang'] = dr_avatar($t['uid']);

$now[] = $t;

}

return $now

}

这时候就会返回你自己的数据格式了

你可能感兴趣的:(php,http返回格式声明)