app接口
来源:互联网 发布:焊接机器人编程命令 编辑:程序博客网 时间:2024/04/29 03:50
<?php
class Response{
const JSON='json';
/**
* 综合方式方式输出通讯数据
* @ param inteage $code 状态码
* @ param string $message 提示信息
* @ param array $data 数据
* @ param string $type 数据输出类型
* @ return string
*/
public static function show($code,$message='',$data=array(),$type=self::JSON){
if(!is_numeric($code)){
echo '';exit;
}
$type=isset($_GET['format'])?$_GET['format']:self::JSON;
$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);
if($type=='json'){
self::json($code,$message,$data);exit;
}elseif($type=='array'){
var_dump($result);exit;
}elseif($type=='xml'){
self::xmlEncode($code,$message,$data);exit;
}
}
/**
* 按json方式输出通讯数据
* @ param inteage $code 状态码
* @ param string $message 提示信息
* @ param array $data 数据
* @ return string
*/
public static function json($code,$message='',$data=array()){
if(!is_numeric($code)){
echo '';exit;
}
$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);
echo json_encode($result);exit;
}
/**
* 按xml方式输出通讯数据
* @ param inteage $code 状态码
* @ param string $message 提示信息
* @ param array $data 数据
* @ return xml
*/
public static function xmlEncode($code,$message='',$data=array()){
if(!is_numeric($code)){
echo '';exit;
}
$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);
header("Content-Type:text/xml");
$xml="<?xml version='1.0' encoding='UTF-8'?>";
$xml.="<root>";
$xml.=self::xmlToEncode($result);
$xml.="</root>";
echo $xml;
}
public static function xmlToEncode($data){
$xml=$attr="";
foreach($data as $key=>$val){
if(is_numeric($key)){
$attr="id='{$key}'";
$key="item";
}
$xml.="<{$key} {$attr}>";
$xml.=is_array($val)?self::xmlToEncode($val):$val;
$xml.="</{$key}>";
}
return $xml;
}
}
?>
class Response{
const JSON='json';
/**
* 综合方式方式输出通讯数据
* @ param inteage $code 状态码
* @ param string $message 提示信息
* @ param array $data 数据
* @ param string $type 数据输出类型
* @ return string
*/
public static function show($code,$message='',$data=array(),$type=self::JSON){
if(!is_numeric($code)){
echo '';exit;
}
$type=isset($_GET['format'])?$_GET['format']:self::JSON;
$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);
if($type=='json'){
self::json($code,$message,$data);exit;
}elseif($type=='array'){
var_dump($result);exit;
}elseif($type=='xml'){
self::xmlEncode($code,$message,$data);exit;
}
}
/**
* 按json方式输出通讯数据
* @ param inteage $code 状态码
* @ param string $message 提示信息
* @ param array $data 数据
* @ return string
*/
public static function json($code,$message='',$data=array()){
if(!is_numeric($code)){
echo '';exit;
}
$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);
echo json_encode($result);exit;
}
/**
* 按xml方式输出通讯数据
* @ param inteage $code 状态码
* @ param string $message 提示信息
* @ param array $data 数据
* @ return xml
*/
public static function xmlEncode($code,$message='',$data=array()){
if(!is_numeric($code)){
echo '';exit;
}
$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);
header("Content-Type:text/xml");
$xml="<?xml version='1.0' encoding='UTF-8'?>";
$xml.="<root>";
$xml.=self::xmlToEncode($result);
$xml.="</root>";
echo $xml;
}
public static function xmlToEncode($data){
$xml=$attr="";
foreach($data as $key=>$val){
if(is_numeric($key)){
$attr="id='{$key}'";
$key="item";
}
$xml.="<{$key} {$attr}>";
$xml.=is_array($val)?self::xmlToEncode($val):$val;
$xml.="</{$key}>";
}
return $xml;
}
}
?>
1 0
- app接口
- app 接口
- APP接口
- APP接口
- APP接口
- app 接口
- App 接口
- APP接口简介---PHP开发APP接口
- app接口 封装通信接口
- 关于APP接口设计
- APP接口设计安全问题
- 关于APP接口设计
- 关于APP接口设计
- php开发app接口
- 关于APP接口设计
- APP 接口保护文档
- 关于APP接口设计
- 关于APP接口设计
- 关于data-*,html5的新特性之一
- 回顾过去程序的一些注意事项
- MySQL双主配置
- 【网络安全】我的第一次windows服务器杀毒经历
- Android图片处理的三种方法
- app接口
- centos7没有安装ifconfig命令的解决方法
- was使用命令创建概要文件
- 黑苹果中sdk和ndk路径的限制
- Android 开源框架ViewPageIndicator 和 ViewPager 仿网易新闻客户端Tab标签
- MySQL常见错误代码(转)
- [Thrift]Apache Thrift入门Java实例
- 跳转至应用市场评分
- Java - 集合框架完全解析