api.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * api.class.php 接口类
  4. *
  5. * @version v0.02
  6. * @create time 2014/7/24
  7. * @update time 2016/5/22
  8. * @author jt
  9. * @copyright Copyright (c) 微普科技 WiiPu Tech Inc. (http://www.wiipu.com)
  10. */
  11. class API {
  12. const SUCCESS = 200;
  13. const SUCCESS_MSG= "success";
  14. const STOCK = 301;
  15. const STOCK_MSG= "股票代码不存在/错误";
  16. const SECTOR = 302;
  17. const SECTOR_MSG= "交易板块不存在/错误";
  18. const SIGN = 302;
  19. const SIGN_MSG= "非法签名";
  20. const EMPTY_STOCK = 401;
  21. const EMPTY_STOCK_MSG= "股票数据为空";
  22. const SERVER = 501;
  23. const SERVER_MSG= "服务器错误";
  24. //API编号,数字
  25. public $code;
  26. //API来源
  27. public $source = 0;
  28. //API 某一天,时间戳
  29. public $day;
  30. //发生错误
  31. public $error = false;
  32. //是否统计错误调用
  33. public $errcount = false;
  34. public function __construct($code, $errcount = true) {
  35. $this->code = $code;
  36. $this->day = strtotime(date('Y-m-d'));
  37. if($errcount) $this->errcount = true;
  38. }
  39. //检查IP白名单
  40. public function checkIP(){
  41. global $Array_API_IP_WhiteList;
  42. $ip = getIP();//This Function in lib/function_common@WiiPHP
  43. if(!in_array($ip, $Array_API_IP_WhiteList)) $this->ApiError('999', 'IP不在白名单');
  44. }
  45. //发生错误
  46. public function ApiError($errcode, $errmsg){
  47. $this->error = true;
  48. $err = array();
  49. $err['code'] = $errcode;
  50. $err['message'] = $errmsg;
  51. $err['data'] = null;
  52. $err_json = json_encode_cn($err);
  53. echo $err_json;
  54. exit();//发生错误直接退出
  55. }
  56. //API 设置来源
  57. public function setsource($source){
  58. $this->source = $source;
  59. }
  60. }
  61. ?>