123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * CEmailLogRoute class file.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.yiiframework.com/
- * @copyright 2008-2013 Yii Software LLC
- * @license http://www.yiiframework.com/license/
- */
- /**
- * CEmailLogRoute sends selected log messages to email addresses.
- *
- * The target email addresses may be specified via {@link setEmails emails} property.
- * Optionally, you may set the email {@link setSubject subject}, the
- * {@link setSentFrom sentFrom} address and any additional {@link setHeaders headers}.
- *
- * @property array $emails List of destination email addresses.
- * @property string $subject Email subject. Defaults to CEmailLogRoute::DEFAULT_SUBJECT.
- * @property string $sentFrom Send from address of the email.
- * @property array $headers Additional headers to use when sending an email.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @package system.logging
- * @since 1.0
- */
- class CNoteLogRoute extends CLogRoute
- {
- /**
- * @var boolean set this property to true value in case log data you're going to send through emails contains
- * non-latin or UTF-8 characters. Emails would be UTF-8 encoded.
- * @since 1.1.13
- */
- public $utf8=false;
- /**
- * @var array list of destination API_URL addresses.
- */
- private $_api_url = array();
- private $_subject;
- /**
- * Sends log messages to specified email addresses.
- * @param array $logs list of log messages
- */
- protected function send_api($array)
- {
- if($this->_api_url && isset($this->_api_url['url']) && isset($this->_api_url['username']) && isset($this->_api_url['password']))
- {
- $basicAuth = $this->_api_url['username'].":".$this->_api_url['password'];
- if($basicAuth)
- {
- $this->apipost($this->_api_url['url'],$array,array(),$basicAuth);
- }else
- {
- $this->apipost($this->_api_url['url'],$array);
- }
- }
- }
- protected function processLogs($logs)
- {
- $message='';
- foreach($logs as $log)
- {
- $message.=$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
- }
- $this->apipost($this->_api_url['url'],array('sysType'=>$this->subject,'env'=>YII_ENV,'msg'=>$message));
- }
- /**
- * @return array list of destination api addresses
- */
- public function getApiUrl()
- {
- return $this->_api_url;
- }
- /**
- * @param mixed $value list of destination api addresses. If the value is
- * a string, it is assumed to be comma-separated api addresses.
- */
- public function setApiUrl($value)
- {
- if(is_array($value))
- {
- $this->_api_url = $value;
- }else
- {
- $this->_api_url = array(
- 'prefix' => $value,
- 'username' => 'zxhx',
- 'password' => '533166afe82356ff5bc22ae9a263fb4e'
- ) ;
- }
- return $this->_api_url = $value;
- }
- public function getSubject()
- {
- return $this->_subject;
- }
- public function setSubject($value)
- {
- $this->_subject=$value;
- }
- private function apipost($url, $array = array(), $header = array(), $basicAuth = "zxhx:533166afe82356ff5bc22ae9a263fb4e"){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- if($basicAuth)
- $header = array("Authorization: Basic ".base64_encode($basicAuth));
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- if($array){
- $array = http_build_query($array);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
- }
- $data = curl_exec($ch);
- curl_close($ch);
- return $data;
- }
- }
|