| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?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";
- const EMPTY = 201;
- const EMPTY_MSG= "股票代码不存在/错误";
- const STOCK = 202;
- const STOCK_MSG= "股票数据为空";
- //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;
- }
- }
- ?>
|