Authored by xiaowei

打印日志

... ... @@ -12,6 +12,8 @@
namespace Api;
use Plugin\Cache;
use Plugin\UdpLog;
class Yohobuy
{
/* 正式环境 */
... ... @@ -186,6 +188,8 @@ class Yohobuy
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
}
$result = curl_exec($ch);
//log打印
UdpLog::info('get调用接口入参url/出参:', 'in:'.$url.' out:'.$result);
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
}
... ... @@ -249,6 +253,8 @@ class Yohobuy
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
}
$result = curl_exec($ch);
//log打印
UdpLog::info('get调用接口入参url/出参:', 'in:'.$url.'?'.$str.' out:'.$result);
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
}
... ...
<?php
/**
* Created by IntelliJ IDEA.
* User: hbomb_000
* Date: 2016/5/5
* Time: 18:17
*/
namespace Plugin;
/**
* Class UdpLog
* @useage:
* UdpLog::info('get payment list begin',array('order_code'=>123231));
* @package WebPlugin
*/
class UdpLog
{
//influxdb url
public static $url = 'influxdb.yohobuy.com';
//influxdb port
public static $port = '4444';
//influxdb measurement
public static $measurement = 'php_log';
/**
* proc line and send log to influxdb
* @param $level
* @param $message
* @param $meta
*/
private static function procLog($level,$message,$debugInfo,$meta='') {
$level = str_replace(__CLASS__.'::','',$level);
$file = $debugInfo[0]["file"];
$line = $debugInfo[0]["line"];
//make tags
$tags = array(
'host='.gethostname(),
'level='.$level,
'file='.$file,
'line='.$line
);
//make a line
$tags = implode(',',$tags);
$string = self::$measurement .','.$tags.' message="'.$message.'",meta="'.var_export($meta,true).'"';
self::send($string);
}
/**
* send by udp
* @param $string
*/
private static function send($string) {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$len = strlen($string);
socket_sendto($sock, $string, $len, 0, self::$url, self::$port);
socket_close($sock);
}
/**
* info log
* @param $message
* @param $meta
*/
public static function info($message,$meta='') {
self::procLog(__METHOD__,$message,debug_backtrace(),$meta);
}
/**
* warn log
* @param $message
* @param $meta
*/
public static function warn($message,$meta='') {
self::procLog(__METHOD__,$message,debug_backtrace(),$meta);
}
/**
* error log
* @param $message
* @param $meta
*/
public static function error($message,$meta='') {
self::procLog(__METHOD__,$message,debug_backtrace(),$meta);
}
/**
* debug log
* @param $message
* @param $meta
*/
public static function debug($message,$meta='') {
self::procLog(__METHOD__,$message,debug_backtrace(),$meta);
}
}
... ...
... ... @@ -5,6 +5,7 @@ use LibModels\Wap\Passport\LoginData;
use LibModels\Wap\Passport\RegData;
use Plugin\Helpers;
use Plugin\Partner\Factory;
use Plugin\UdpLog;
/**
* 登录的控制器
... ... @@ -117,6 +118,7 @@ class LoginController extends AbstractAction
$profile = $this->post('account');
$password = $this->post('password');
if (!is_numeric($area) || empty($profile) || empty($password)) {
UdpLog::info('【登录】校验参数传递auth','area:'.$area.'profile:'.$profile.'password:'.$password);
break;
}
... ... @@ -124,6 +126,7 @@ class LoginController extends AbstractAction
$verifyEmail = Helpers::verifyEmail($profile);
$verifyMobile = ($area === '86') ? Helpers::verifyMobile($profile) : Helpers::verifyAreaMobile($profile, $area);
if (!$verifyEmail && !$verifyMobile) {
UdpLog::info('【登录】校验账号是否有效auth','email:'.$verifyEmail.'mobile:'.$verifyMobile);
break;
}
... ...
... ... @@ -3,6 +3,7 @@
use Action\AbstractAction;
use LibModels\Wap\Passport\RegData;
use Plugin\Helpers;
use Plugin\UdpLog;
/**
* 注册的控制器
... ... @@ -64,7 +65,7 @@ class RegController extends AbstractAction
'backUrl' => SITE_MAIN . '/?go=1', // 返回的URL链接
'headerText' => '注册', // 头部信息
'isPassportPage' => true, // 模板中模块标识
'areaCode' => $area, // 地区编号
'areaCode' => '+' . $area, // 地区编号
'phoneNum' => $mobile, // 手机号
'token' => $token, // 访问令牌
'serviceUrl'=>'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409&info='//在线客服
... ... @@ -127,12 +128,14 @@ class RegController extends AbstractAction
$area = $this->post('areaCode', '86');
/* 判断参数是否合法 */
if (!is_numeric($mobile) || !is_numeric($area)) {
UdpLog::info('【注册】校验参数传递verfymobile','area:'.$area.'profile:'.$mobile);
break;
}
/* 设置注册有效时间30分钟, 防机器刷 */
$expire = $this->getSession('_REG_EXPIRE');
if (empty($expire) || $expire < time()) {
UdpLog::info('【注册】校验session页面停留时间verfymobile','注册有效时间失效(30min)');
break;
}
... ... @@ -176,12 +179,14 @@ class RegController extends AbstractAction
$code = $this->post('code');
/* 判断参数是否合法 */
if (!is_numeric($mobile) || !is_numeric($area) || !isset($code)) {
UdpLog::info('【注册】校验参数传递verifycode','area:'.$area.'mobile:'.$mobile.'code:'.$code);
break;
}
/* 设置注册有效时间30分钟, 防机器刷 */
$expire = $this->getSession('_REG_EXPIRE');
if (empty($expire) || $expire < time()) {
UdpLog::info('【注册】校验session页面停留时间verifycode','注册有效时间失效(30min)');
break;
}
... ... @@ -224,12 +229,14 @@ class RegController extends AbstractAction
$area = $this->post('areaCode', '86');
/* 判断参数是否合法 */
if (!is_numeric($mobile) || !is_numeric($area)) {
UdpLog::info('【注册】发送验证码sendcode','mobile:'.$mobile.'area:'.$area);
break;
}
/* 设置注册有效时间30分钟, 防机器刷 */
$expire = $this->getSession('_REG_EXPIRE');
if (empty($expire) || $expire < time()) {
UdpLog::info('【注册】发送验证码sendcode','注册有效时间失效(30min)');
break;
}
... ... @@ -268,16 +275,19 @@ class RegController extends AbstractAction
$password = $this->post('password');
/* 判断参数是否合法 */
if (!is_string($token) || !is_numeric($mobile) || !is_numeric($area) || !isset($password)) {
UdpLog::info('【注册】判断参数是否合法setpassword','token:'.$token.'mobile:'.$mobile.'area:'.$area.'passsport:'.$password);
break;
}
/* 判断是否允许访问 */
if (!Helpers::verifyToken($mobile, $token)) {
UdpLog::info('【注册】判断参数是否可访问setpassword','token:'.$token.'mobile:'.$mobile);
break;
}
/* 判断密码是否符合规则 */
if (!Helpers::verifyPassword($password)) {
UdpLog::info('【注册】密码不符合规范setpassword','password:'.$password);
break;
}
... ...