| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * api.class.php 接口类
- *
- * @version v0.02
- * @create time 2014/7/24
- * @update time 2016/5/22
- * @author jt
- * @copyright Copyright (c) 微普科技 WiiPu Tech Inc. (http://www.wiipu.com)
- */
- class API {
- const SUCCESS = 200;
- const SUCCESS_MSG= "success";
- //API编号,数字
- public $code;
- //API来源
- public $source = 0;
- //API 某一天,时间戳
- public $day;
- //发生错误
- public $error = false;
- //是否统计错误调用
- public $errcount = false;
- public function __construct($code, $errcount = true) {
- $this->code = $code;
- $this->day = strtotime(date('Y-m-d'));
- if($errcount) $this->errcount = true;
- }
- //检查IP白名单
- public function checkIP(){
- global $Array_API_IP_WhiteList;
- $ip = getIP();//This Function in lib/function_common@WiiPHP
- if(!in_array($ip, $Array_API_IP_WhiteList)) $this->ApiError('999', 'IP不在白名单');
- }
- //发生错误
- public function ApiError($errcode, $errmsg){
- $this->error = true;
- $err = array();
- $err['code'] = $errcode;
- $err['message'] = $errmsg;
- $err['data'] = null;
- $err_json = json_encode_cn($err);
- echo $err_json;
- exit();//发生错误直接退出
- }
- //API 设置来源
- public function setsource($source){
- $this->source = $source;
- }
- }
- ?>
|