富贵资源网 Design By www.hznty.com
本文实例为大家分享了使用Thinkphp框架开发移动端接口代码,给原生APP提供api接口,具体内容如下
1. 使用TP框架时 放在common文件夹下文件名就叫function.php
<"htmlcode">/** * 发布模块 * * 获取信息单个果品详细信息 * */ public function getMyReleaseInfo(){ //检查是否通过post方法得到数据 checkdataPost('id'); $where['id'] = $_POST['id']; $field[] = 'id,fruit_name,high_price,low_price,address,size,weight,fruit_pic,remark'; $releaseInfo = $this->release_obj->findRelease($where,$field); $releaseInfo['remark'] = mb_substr($releaseInfo['remark'],0,49,'utf-8').'...'; //多张图地址按逗号截取字符串,截取后如果存在空数组则需要过滤掉 $releaseInfo['fruit_pic'] = array_filter(explode(',', $releaseInfo['fruit_pic'])); $fruit_pic = $releaseInfo['fruit_pic'];unset($releaseInfo['fruit_pic']); //为图片添加存储路径 foreach($fruit_pic as $k=>$v ){ $releaseInfo['fruit_pic'][] = 'http://'.$_SERVER['HTTP_HOST'].'/Uploads/Release/'.$v; } if($releaseInfo){ returnApiSuccess('',$releaseInfo); }else{ returnApiError( '什么也没查到(+_+)!'); } }3. findRelease() 方法的model
/** * 查询一条数据 */ public function findRelease($where,$field){ if($where['status'] == '' || empty($where['status'])){ $where['status'] = array('neq','9'); } $result = $this->where($where)->field($field)->find(); return $result; }4. app端接收到的数据(解码json之后)
{ "flag": "success", "message": "", "responseList": { "id": "2", "fruit_name": "苹果", "high_price": "8.0", "low_price": "5.0", "address": "天津小白楼水果市场", "size": "2.0", "weight": "2.0", "remark": "急需...", "fruit_pic": [ "http://fruit.txunda.com/Uploads/Release/201508/55599e7514815.png", "http://fruit.txunda.com/Uploads/Release/201508/554f2dc45b526.jpg" ] } }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...