####更新说明
#####文件说明:
####客户端请求说明:
引入ApiClient.php文件
参数说明:
$url
请求服务端地址pathinfo模式【http://serverName/appName/module/action/user/1】
$data
传递给服务器的数据参数
$requestType
请求类型,暂时支持get,post,put,delete;此参数可不传,则默认请求为get方式
实例化类 $client = new apiClient($url, $data, $requestType);
执行方法 $result = $client->doRequest()
获取服务端返回的数据
include './ApiServer.php'; class testServer extends apiServer { /** * 先执行apiServer中的方法,初始化数据 * @param object $obj 可以传入的全局对象[数据库对象,框架全局对象等] */ private $obj; function __construct(object $obj) { parent::__construct(); $this->obj = $obj; //$this->resourse; 父类中已经实现,此类中可以直接使用 //$tihs->resourseId; 父类中已经实现,此类中可以直接使用 print_r($this->param); } /** * 获取资源操作 * @return [type] [description] */ protected function _get(){ echo "get";//测试用 //逻辑代码根据自己实际项目需要实现 } /** * 新增资源操作 * @return [type] [description] */ protected function _post(){ echo "post";//测试用 //逻辑代码根据自己实际项目需要实现 } /** * 删除资源操作 * @return [type] [description] */ protected function _delete(){ //逻辑代码根据自己实际项目需要实现 } /** * 更新资源操作 * @return [type] [description] */ protected function _put(){ echo "put";//测试用 //逻辑代码根据自己实际项目需要实现 } } $server = new testServer();
您可以复制此代码到您自定义的类文件中,类中的方法 _get()
, _post
, _delete
, _put
根据自己的业务逻辑实现代码
将自己的类实例化:$testServer = new testServer()
;
类ApiServer属性说明:
private $method = '';
客户端发送请求的方法【get、post,put,delete】
protected $param;
客户端发送的参数
protected $resourse;
客户端发送的pathinfo第一个参数,请求的具体资源
protected $resourseId
客户端发送的pathinfo第二个参数,请求的具体资源的id,或者其他,此参数可不传
####服务端认证:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。