Errorlog.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * 由于钉釘现在接口限流了 没办法这边写一个接收器 作为接收需要监听信息的日志记录
  5. * 除此之外也开始监听其他错误
  6. */
  7. class Errorlog extends Start_Controller {
  8. private $ip = ['127.0.0.1','47.105.156.18'];
  9. public function __construct(){
  10. parent::__construct();
  11. $this->load->_model("Model_logic_tools","logic_tools");
  12. $this->load->_model("Model_logic_ding","logic_ding");
  13. $this->load->_model("Model_zzerrlog","zzerrlog");
  14. $this->load->_model("Model_zzjobs","zzjobs");
  15. }
  16. //定义方法的调用规则 获取URI第二段值
  17. public function _remap($arg,$arg_array)
  18. {
  19. $ip = $_SERVER['REMOTE_ADDR'];
  20. if(!in_array($ip,$this->ip)){
  21. exit("Unauthorized access");
  22. }
  23. if($arg == 'ding')//添加
  24. {
  25. $this->_ding();
  26. }
  27. elseif($arg == 'printouttime')//
  28. {
  29. $this->_print_outtime();
  30. }
  31. else
  32. {
  33. die('No direct script access allowed');
  34. }
  35. }
  36. public function _ding(){
  37. //$ip = $_SERVER['REMOTE_ADDR']; 后期仅仅限制部署服务器的ip就好
  38. $param = json_decode(file_get_contents('php://input'), true);
  39. $key = $param['bs'];//核验秘钥
  40. $key = $this->logic_tools->toolsjiemi($key);
  41. $check_key = $this->logic_ding->getKey();
  42. if($check_key != $key){
  43. die('No direct script access allowed');
  44. }
  45. $content = $param['content'];
  46. if(!is_string( $content)){
  47. $content = json_encode($content);
  48. }
  49. //保存要监听的数据到日志表中
  50. $this->zzerrlog->insert([
  51. 'content'=>$content,
  52. 'created_time'=>date("Y-m-d H:i:s"),
  53. 'time'=>time(),
  54. ]);
  55. }
  56. public function _print_outtime(){
  57. $number = $this->input->get('number');
  58. if(empty($number)){
  59. echo "SUCCESS";
  60. }else{
  61. $this->zzjobs->insert([
  62. 'status'=>0,
  63. 'quque'=>"outtime_order",
  64. 'payload'=>json_encode(['number'=>$number]),
  65. 'do_interval'=>1,
  66. 'create_time'=>time(),
  67. ]);
  68. echo "SUCCESS";
  69. }
  70. }
  71. }