第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

SingWa老師您好~APP接口實(shí)例應(yīng)該是本期最后的課程吧!

好期待以后還有這么實(shí)用的課程。老師辛苦了~~

貼上自己寫的“綜合方式封裝通信數(shù)據(jù)方法”代碼,證明自己認(rèn)真學(xué)了而且練習(xí)了。

class Response {
const JSON = 'json';
public static function show ($code,$message = '',$data = array(),$type = self::JSON) {
if (!is_numeric($code)) {
return '';
}
$result = array(
'code' => $code,
'message' => $message,
'data' => $data
);
$type = isset($_GET['format'])?$_GET['format']:self::JSON;
if ($type == 'json') {
self::json($code,$message,$data);
exit;
}elseif ($type == 'array') {
var_dump($result);
}elseif ($type == 'xml') {
self::xmlEncode($code,$message,$data);
exit;
}else {
//TO DO
}
}
/* 按json方式輸出通信數(shù)據(jù)
@param integer $code 狀態(tài)碼
@param string $message 提示信息
@param array $data 數(shù)據(jù)
return string */
public static function json ($code,$message = '',$data = array()) {
if(!is_numeric($code)){
return '';
}
$result = array(
'code' => $code,
'message' => $message,
'data' => $data
);
echo json_encode($result);
exit;
}
public static function xml () {
//PHP生成XML數(shù)據(jù)(采用組裝字符串方式)
header("Content-type:text/xml");
$xml = "<?xml version='1.0' encoding='UTF-8'?>";
$xml .= "<root>";
$xml .= "<code>200</code>";
$xml .= "<message>數(shù)據(jù)返回成功</message>";
$xml .=  "<data>";
$xml .=  "<id>1</id>";
$xml .=  "<name>colin</name>";
$xml .=  "</data>";
$xml .= "</root>";
echo $xml;
}
/* 按XML方式輸出通信數(shù)據(jù)
@param integer $code 狀態(tài)碼
@param string $message 提示信息
@param array $data 數(shù)據(jù)
return string */
public static function xmlEncode ($code, $message = '', $data = array()) {
if (!is_numeric($code)) {
return '';
}
$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 .= "<code>200</code>";
$xml .= "<message>數(shù)據(jù)返回成功</message>";
$xml .= "</root>";
echo $xml;
}
public static function xmlToEncode ($data) {
$xml = $arr = '';
foreach ($data as $key=>$val){
if (is_numeric($key)) { //解決xml數(shù)據(jù)節(jié)點(diǎn)不能為數(shù)字
$arr = " id='$key'";//<0>56<0> <item id="0">56</item>
$key = "item";
}
$xml .= "<{$key}{$arr}>";
$xml .= is_array($val) ? self::xmlToEncode($val):$val;//遞歸判斷
$xml .= "</{$key}>";
}
return $xml;
}
}
$data = array(
'id' => 1,
'name' => 'colin',
'type' => array(56,57,58)
);
Response::show(200,'數(shù)據(jù)返回成功', $data);


正在回答

1 回答

嗯,不錯(cuò),加油,祝學(xué)習(xí)愉快

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
PHP開發(fā)APP接口
  • 參與學(xué)習(xí)       79151    人
  • 解答問題       608    個(gè)

APP通信接口技術(shù),不得不掌握的法寶,學(xué)完之后你會(huì)受益良多

進(jìn)入課程
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)