ホームページ >バックエンド開発 >PHPチュートリアル >APP インターフェイスの開発と静的キャッシュの読み取り、アプリの静的キャッシュの読み取り_PHP チュートリアル
<span> 1</span> <?<span>php </span><span> 2</span> <span>/*</span><span>* </span><span> 3</span> <span> * Description: App 接口 </span><span> 4</span> <span> * Create date:2015-10-19 13:36 </span><span> 5</span> <span> * Author: zhaoyingnan </span><span> 6</span> <span> *</span><span>*/</span> <span> 7</span> <span>class</span><span> Response </span><span> 8</span> <span>{ </span><span> 9</span> <span>/*</span><span>* </span><span>10</span> <span> * 综合方式 </span><span>11</span> <span> * @author zhaoyingnan 2015-10-19 11:24 </span><span>12</span> <span> * @param int $iCode 状态码 </span><span>13</span> <span> * @param string $sMsg 提示信息 </span><span>14</span> <span> * @param mix $mixData data </span><span>15</span> <span> * @param string $sType 接口返回类型 </span><span>16</span> <span> * @return string </span><span>17</span> <span> *</span><span>*/</span> <span>18</span> <span>static</span> <span>function</span> show(<span>$iCode</span>, <span>$sMsg</span> = '', <span>$mixData</span> = '', <span>$sType</span> = 'json'<span>) </span><span>19</span> <span> { </span><span>20</span> <span>if</span>(!<span>is_numeric</span>(<span>$iCode</span><span>)) </span><span>21</span> <span>return</span> ''<span>; </span><span>22</span> <span>$arData</span> = <span>array</span><span>( </span><span>23</span> 'code' => <span>$iCode</span>, <span>24</span> 'message' => <span>$sMsg</span>, <span>25</span> 'data' => <span>$mixData</span> <span>26</span> <span> ); </span><span>27</span> <span>switch</span>(<span>$sType</span><span>) </span><span>28</span> <span> { </span><span>29</span> <span>case</span> 'array': <span>30</span> <span>echo</span> '<pre class="brush:php;toolbar:false">'<span>; </span><span>31</span> <span>print_r</span>(<span>$arData</span><span>); </span><span>32</span> <span>echo</span> ''; 33 break; 34 case 'xml': 35 self::xml($arData); 36 break; 37 default: 38 self::json($arData); 39 } 40 } 41 42 /** 43 * json 44 * @author zhaoyingnan 2015-10-19 10:21 45 * @param array $arData 46 * @return string 47 **/ 48 private function json($arData= array()) 49 { 50 exit(json_encode($arData)); 51 } 52 53 /** 54 * xml 55 * @author zhaoyingnan 2015-10-19 10:21 56 * @param array $arData 57 * @return string 58 **/ 59 private function xml($arData = array()) 60 { 61 header('Content-Type:text/xml'); 62 $sXml = ''; 63 $sXml .= "\n"; 64 $sXml .= "