TP5 自定义错误类

application目录下创建单独文件夹exception

在exception目录下创建controller

在controller下创建ApiHandleException.PHP

TP5 自定义错误类

  <?php namespace appexceptioncontroller;    use appSendWxtempMsg;  use thinkexceptionHandle;    Class ApiHandleException extends Handle  {        /**       * http状态码       */      public $httpCode = 500;        public function render(Exception $e)      {          return $this->show($e,$e->getMessage(), $this->httpCode);      }          /**      通用化API接口数据输出      @param int $status 业务状态码      @param string $message 信息提示      @param int $httpCode http状态码       */      public function show($e,$message ,$httpCode = 200)      {          $data =  [              'message' => $message,          ];          return json($data, $httpCode);           //下边代码为微信公众帐号模板消息推送           /*$ip = request()->ip();            $url = 'http://apis.juhe.cn/ip/ipNew?key=xxxxxxxx&ip='.$ip;            $http = $this->httpGet($url);            $result = json_decode($http,true);            $template = array(              "touser" => 'xxxx',              'url'=> 'http://www.xxx.com/exception/errors/index?error='.$e,              "template_id" => "xxxx",              'topcolor' => '#ccc',              'data' => array('first' => array('value' => "xxx报错了",                  'color' => "#101BF4",),                  'keyword1' => array('value' => 'xxx系统',                      'color' => '#743A3A'                  ),                  'keyword2' => array('value' => $message ,                      'color' => '#743A3A'                  ),                  'keyword3' => array('value' => '',                      'color' => '#743A3A'                  ),                  'keyword4' => array('value' => date('Y-m-d H:i:s',time()),                      'color' => '#743A3A'                  ),                  'remark' => array('value' =>$result['result']['Country'].'|'.$result['result']['Province'].'|'.$result['result']['City'].'|'.$result['result']['Isp'],                      'color' => '#3A16EE'                  ),              )          );            $SendWxtempMsg = new SendWxtempMsg();              $SendWxtempMsg->api_notice_increment($template);*/                  }      public function httpGet($url)      {          $curl = curl_init();          curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);          curl_setopt($curl, CURLOPT_TIMEOUT, 1);          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);          curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);          curl_setopt($curl, CURLOPT_URL, $url);          $res = curl_exec($curl);          curl_close($curl);          return $res;      }  }    

在config里配置

TP5 自定义错误类

appexceptioncontrollerApiHandleException

OK完成

文章来源于互联网:TP5 自定义错误类

© 版权声明
THE END
喜欢就支持以下吧
点赞0
分享
评论 抢沙发