if ($this->bCheckLogin) { // 当前用户 $aCookie = Util_Cookie::get(Yaf_G::getConf('authkey', 'cookie')); if (empty($aCookie)) { return $this->redirect('/admin/login'); } $this->aCurrUser = $aCookie; // 当前城市 $this->iCurrCityID = Util_Cookie::get('city'); if (empty($this->iCurrCityID)) { $this->iCurrCityID = $this->aCurrUser['iCityID']; } $this->aCurrCity = Model_City::getDetail($this->iCurrCityID); } $this->assign('sStaticRoot', 'http://' . Yaf_G::getConf('static', 'domain')); } /** * 执行Action后的操作 * * @see Yaf_Controller::actionAfter() */ public function actionAfter() { if ($this->autoRender() == true) { if (!empty($this->aCurrUser)) { $this->assign('aCurrUser', $this->aCurrUser);
/** * 生成激活码|忘记密码 * * @param unknown $aUser * @return string */ public static function makeCode($aUser, $iType) { $sCryptkey = Util_Common::getConf('cryptkey', 'passwd'); $sActiveCode = md5($sCryptkey . $aUser['sEmail'] . $aUser['iType'] . time()); Model_VerifyCode::addData(array('iUserID' => $aUser['iUserID'], 'iType' => $iType, 'sCode' => $sActiveCode)); return $sActiveCode; }
/** * 清除缓存 */ public function redisAction() { $sType = $this->getParam('type'); $oRedis = Util_Common::getRedis($sType); $oRedis->flushdb(); return $this->showMsg('清除成功!', true); }
/** * 发送手机验证码 * @param unknown $sMobile * @param unknown $iType */ public static function makeSMSCode($sMobile, $iType) { $sKey = self::getSmsKey($iType); $sRand = Util_Tools::passwdGen(4, Util_Tools::FLAG_NUMERIC); Util_Cookie::set($sKey, $sRand, 1800); $iTempID = Util_Common::getConf($iType, 'aSmsTempID'); return Sms_CCP::sendTemplateSMS($sMobile, array($sRand, 10), $iTempID); }
public function __construct($host = '127.0.0.1', $port = 6379, $db = 0) { $this->_sHost = $host; $this->_iPort = $port; $this->_iSelectDb = $db; $this->_oDebug = Util_Common::getDebug(); $this->connect(); $this->_aUseFun = array_flip($this->_aUseFun); }
/** * 初始化REST SDK * @return Ambigous <NULL, unknown> */ public static function getRest() { $aConf = Util_Common::getConf('CCP'); global $accountSid, $accountToken, $appId, $serverIP, $serverPort, $softVersion; $rest = new REST($aConf['host'], $aConf['port'], $aConf['version']); $rest->setAccount($aConf['sid'], $aConf['token']); $rest->setAppId($aConf['appid']); return $rest; }
/** * 执行Action后的操作 * @see Yaf_Controller::actionAfter() */ public function actionAfter() { if ($this->autoRender() == true) { if (!empty($this->aCurrUser)) { } $aDebug = Util_Common::getDebugData(); if ($aDebug) { $this->assign('__showDebugInfo__', 'showDebugInfo(' . json_encode($aDebug) . ');'); } } else { } }
public static function init() { $aConf = Util_Common::getConf('wxpay', null, 'wxpay'); self::$APPID = $aConf['APPID']; self::$MCHID = $aConf['MCHID']; self::$KEY = $aConf['KEY']; self::$APPSECRET = $aConf['APPSECRET']; //self::$JS_API_CALL_URL = $aConf['JS_API_CALL_URL']; self::$SSLCERT_PATH = $aConf['SSLCERT_PATH']; self::$SSLKEY_PATH = $aConf['SSLKEY_PATH']; self::$NOTIFY_URL = $aConf['NOTIFY_URL']; }
public static function getUrl($url, $params) { if ($url != '') { $delimiter = '/'; $url = rtrim($url, $delimiter); if (!empty($params)) { $url .= $delimiter . str_replace(array('&', '='), $delimiter, http_build_query($params)); } $url .= '.html'; } else { $url = Util_Common::getUrl($url, $params, true); } return $url; }
public static function getUrl($url, $params) { if ($url != '') { $url = rtrim($url, '/'); if (!empty($params)) { $delimiter = '/'; foreach ($params as $k => $v) { if (false !== stripos($url, '{' . $k . '}')) { $url = str_replace('{' . $k . '}', $v, $url); } else { $url .= $delimiter . urlencode($k) . $delimiter . urlencode($v); } } } } else { $url = Util_Common::getUrl($url, $params, true); } return $url; }
/** * 发送邮件 * @param unknown $sTo * @param unknown $sSubject * @param unknown $sBody */ public static function send($mTo, $sSubject, $sBody, $aParam = array()) { foreach ($aParam as $k => $v) { $sSubject = str_replace('{' . $k . '}', $v, $sSubject); $sBody = str_replace('{' . $k . '}', $v, $sBody); } if (!is_array($mTo)) { $sTmp = file_get_contents(APP_PATH . '/View/mail.phtml'); $sTmp = str_replace('{email}', $mTo, $sTmp); $sBody = str_replace('{content}', $sBody, $sTmp); } try { $conf = Util_Common::getConf('mailer'); $mail = new Util_PHPMailer(true); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Port = $conf['smtp_port']; $mail->Host = $conf['smtp_host']; $mail->Username = $conf['smtp_user']; $mail->Password = $conf['smtp_pass']; $mail->From = $conf['from_email']; $mail->FromName = $conf['from_name']; $mail->SMTPSecure = $conf['smtp_secure']; $mail->CharSet = "utf-8"; $mail->IsHTML(true); $mail->Subject = $sSubject; $mail->MsgHTML($sBody); $mail->ClearAddresses(); // 发多个人的情况 if (!is_array($mTo)) { $mTo = array($mTo); } foreach ($mTo as $sTo) { $mail->AddAddress($sTo); } $mail->Send(); $mail = null; return true; } catch (Exception $e) { return $e->getMessage(); } }
/** * 执行Action后的操作 * * @see Yaf_Controller::actionAfter() */ public function actionAfter() { if ($this->autoRender() == true) { $aDebug = Util_Common::getDebugData(); if ($aDebug) { $this->assign('__showDebugInfo__', 'showDebugInfo(' . json_encode($aDebug) . ');'); } $this->assign('_iMediaTotal', Model_Media::getCnt(array('where' => array('iStatus' => 1)))); $this->assign('_iYAdTotal', Model_Ad::getYesterdayAdCnt()); $this->assign('_iYUserTotal', Model_Ad::getYesterdayUserCnt()); if (empty($this->aCurrUser)) { $this->aCurrUser = $this->getCurrUser(Model_User::TYPE_AD, false); if (empty($this->aCurrUser)) { $this->aCurrUser = $this->getCurrUser(Model_User::TYPE_MEDIA, false); } } $this->assign('_aCurrUser', $this->aCurrUser); } else { } }
public static function decrypt($txt) { $key = Util_Common::getConf('cryptkey', 'cookie'); $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_."; $ikey = "-8vh4-HGf834-._8"; $knum = 0; $i = 0; $tlen = strlen($txt); while (isset($key[$i])) { $knum += ord($key[$i++]); } $ch1 = $txt[$knum % $tlen]; $nh1 = strpos($chars, $ch1); $txt = substr_replace($txt, '', $knum % $tlen--, 1); $ch2 = $txt[$nh1 % $tlen]; $nh2 = strpos($chars, $ch2); $txt = substr_replace($txt, '', $nh1 % $tlen--, 1); $ch3 = $txt[$nh2 % $tlen]; $nh3 = strpos($chars, $ch3); $txt = substr_replace($txt, '', $nh2 % $tlen--, 1); $nhnum = $nh1 + $nh2 + $nh3; $mdKey = substr(md5(md5(md5($key . $ch1) . $ch2 . $ikey) . $ch3), $nhnum % 8, $knum % 8 + 16); $tmp = ''; $j = 0; $k = 0; $tlen = strlen($txt); $klen = strlen($mdKey); for ($i = 0; $i < $tlen; $i++) { $k = $k == $klen ? 0 : $k; $j = strpos($chars, $txt[$i]) - $nhnum - ord($mdKey[$k++]); while ($j < 0) { $j += 64; } $tmp .= $chars[$j]; } $tmp = str_replace(array('-', '_', '.'), array('+', '/', '='), $tmp); return trim(base64_decode($tmp)); }
public function modelAction() { $dbh = Util_Common::getMySQLDB(); $aTable = $dbh->getCol('SHOW TABLES'); $aFile = glob(APP_PATH . '/Model/*.php'); foreach ($aFile as $k => $sFile) { $aFile[$k] = basename($sFile, '.php'); } $aFile = array_flip($aFile); foreach ($aTable as $sTable) { $aTmp = explode('_', $sTable); unset($aTmp[0]); foreach ($aTmp as $k => $v) { $aTmp[$k] = ucfirst($v); } $sFile = join('', $aTmp); if (isset($aFile[$sFile])) { continue; } $sData = "<?php\n\nclass Model_{$sFile} extends Model_Base\n{\n\n const TABLE_NAME = '{$sTable}';\n}"; file_put_contents(APP_PATH . '/Model/' . $sFile . '.php', $sData); echo $sTable . "=>" . $sFile . "\n"; } }
protected function resizeImage($p_sFileContent, $p_iWidth, $p_iHeight, $p_aDomainDimension, $p_sMimeType, $p_bCrop, $p_bIsWaterMark = true, $p_iWaterMarkPosition = 0, $p_iWaterMarkPath = 0) { $utilImg = Util_ImageFactory::instance('gd'); if ($p_iWidth > 0 && $p_iHeight > 0) { $sDimensionKey = $p_iWidth . 'x' . $p_iHeight; $aDimensionConf = $p_aDomainDimension[$sDimensionKey]; $p_bIsWaterMark = isset($aDimensionConf['waterMark']) ? $aDimensionConf['waterMark'] : true; $sWaterMarkPath = ''; if ($p_iWaterMarkPath > 0) { $aWaterMarkPath = Util_Common::getConf('aWaterMarkPath', 'image', 'file'); if (isset($aWaterMarkPath[$p_iWaterMarkPath])) { $sWaterMarkPath = $aWaterMarkPath[$p_iWaterMarkPath]; } } if (empty($sWaterMarkPath) && isset($aDimensionConf['waterMarkPath'])) { $sWaterMarkPath = $aDimensionConf['waterMarkPath']; } if (!empty($sWaterMarkPath)) { // 设置水印的图片地址 $utilImg->setWaterMarkImg($sWaterMarkPath); } $sWaterMarkPosition = ''; if ($p_iWaterMarkPosition > 0) { $aWaterMarkPosition = Util_Common::getConf('aWaterMarkPosition', 'image', 'file'); if (isset($aWaterMarkPosition[$p_iWaterMarkPosition])) { $sWaterMarkPosition = $aWaterMarkPosition[$p_iWaterMarkPosition]; } } if (!empty($sWaterMarkPosition)) { // 设置水印的图片位置 $utilImg->setWaterMarkPosition($sWaterMarkPosition); } } // 图片操作 $p_sFileContent = $utilImg->resize($p_sFileContent, $p_iWidth, $p_iHeight, $p_bCrop, $p_bIsWaterMark); return $utilImg->getImageBlob($p_sFileContent, $p_sMimeType); }
/** * 获取SlaveDB连接 */ protected function _getSlaveDB() { if (null == $this->_oSlaveDB) { $iStartTime = microtime(true); if ($this->_bStrictMaster) { $this->_oSlaveDB = Util_Common::getPdoDb($this->_sDbName, 'master'); } else { $this->_oSlaveDB = Util_Common::getPdoDb($this->_sDbName, 'salve'); } self::$_iConnentTime += round((microtime(true) - $iStartTime) * 1000, 2); } return $this->_oSlaveDB; }
public function __construct() { $this->_sWaterMarkImgPath = Util_Common::getConf('defaultWaterMarkPath', 'image'); }
/** * 自媒体修改 */ public function editAction() { if ($this->_request->isPost()) { $aMedia = $this->_checkData('update'); if (empty($aMedia)) { return null; } $sTagID = $aMedia['sTagID']; unset($aMedia['sTagID']); //所属类目 $sCategoryID = $aMedia['sCategoryID']; unset($aMedia['sCategoryID']); //行业圈子 $sCricleID = $aMedia['sCricleID']; unset($aMedia['sCricleID']); //城市 $sCityID = $aMedia['sCityID']; unset($aMedia['sCityID']); $aMedia['iMediaID'] = intval($this->getParam('iMediaID')); $aOldCity = Model_Media::getDetail($aMedia['iMediaID']); if (empty($aOldCity)) { return $this->showMsg('自媒体不存在!', false); } if (1 == Model_Media::updData($aMedia)) { if ($sTagID != '') { $sTagID = explode(',', $sTagID); $data_MediaTag = Model_MediaTag::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'], 'iStatus' => 1))); foreach ($data_MediaTag as $val) { $val['iStatus'] = 0; Model_MediaTag::updData($val); } $add = array(); $add['iMediaID'] = $aMedia['iMediaID']; $add['iStatus'] = 1; $add['iCreateTime'] = time(); $add['iUpdateTime'] = time(); foreach ($sTagID as $val) { $add['iTagID'] = $val; Model_MediaTag::addData($add); } } //所属类目 if ($sCategoryID != '') { $sCategoryID = explode(',', $sCategoryID); $data_MediaCategory = Model_MediaCategory::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'], 'iStatus' => 1))); foreach ($data_MediaCategory as $val) { $val['iStatus'] = 0; Model_MediaCategory::updData($val); } $add = array(); $add['iMediaID'] = $aMedia['iMediaID']; $add['iStatus'] = 1; $add['iCreateTime'] = time(); $add['iUpdateTime'] = time(); foreach ($sCategoryID as $val) { $add['iCategoryID'] = $val; Model_MediaCategory::addData($add); } } //行业圈子 if ($sCricleID != '') { $sCricleID = explode(',', $sCricleID); $data_MediaCricle = Model_MediaCricle::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'], 'iStatus' => 1))); foreach ($data_MediaCricle as $val) { $val['iStatus'] = 0; Model_MediaCricle::updData($val); } $add = array(); $add['iMediaID'] = $aMedia['iMediaID']; $add['iStatus'] = 1; $add['iCreateTime'] = time(); $add['iUpdateTime'] = time(); foreach ($sCricleID as $val) { $add['iCricleID'] = $val; Model_MediaCricle::addData($add); } } //城市 if ($sCityID != '') { $sCityID = explode(',', $sCityID); $data_MediaCity = Model_MediaCity::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'], 'iStatus' => 1))); foreach ($data_MediaCity as $val) { $val['iStatus'] = 0; Model_MediaCity::updData($val); } $add = array(); $add['iMediaID'] = $aMedia['iMediaID']; $add['iCityID'] = $val; $add['iStatus'] = 1; $add['iCreateTime'] = time(); $add['iUpdateTime'] = time(); foreach ($sCityID as $val) { $add['iCityID'] = $val; Model_MediaCity::addData($add); } } $this->assign('add', $add); if ($aOldCity['iStatus'] == 2 || $aOldCity['iStatus'] == 3 && $aMedia['iStatus'] == 1) { // 邮件通知 $sTitle = Model_Kv::getValue('media_approve_email_title'); $sContent = Model_Kv::getValue('media_approve_email_content'); $aUser = Model_Media::getDetail($aMedia['iMediaID']); $email = Model_User::getDetail($aUser['iUserID']); // 短信通知 $iTempID = Util_Common::getConf(1, 'aSmsTempID'); Util_Mail::send($email['sEmail'], $sTitle, $sContent, array($aUser['sMediaName'])); Util_Sms::sendTemplateSms($email['sMobile'], array($aUser['sMediaName']), $iTempID); } return $this->showMsg('自媒体信息审核成功!', true); } else { return $this->showMsg('自媒体信息审核失败!', false); } } else { $iMediaID = intval($this->getParam('id')); $aMedia = Model_Media::getDetail($iMediaID); //属性 if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aAttribute', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_ATTRIBUTE)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aAttribute', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_ATTRIBUTE)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aAttribute', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_ATTRIBUTE)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aAttribute', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_ATTRIBUTE)); } } } } //分类 if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aTypeInfo', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_CATEGORY)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aTypeInfo', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_CATEGORY)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aTypeInfo', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_CATEGORY)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aTypeInfo', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_CATEGORY)); } } } } //合作等级 if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aCooperateLevel', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_COOPERATELEVEL)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aCooperateLevel', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_COOPERATELEVEL)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aCooperateLevel', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_COOPERATELEVEL)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aCooperateLevel', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_COOPERATELEVEL)); } } } } //行业圈子 if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aIndustryCircle', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_INDUSTRY)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aIndustryCircle', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_INDUSTRY)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aIndustryCircle', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_INDUSTRY)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aIndustryCircle', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_INDUSTRY)); } } } } //认证 if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aVerifyState', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_VERIFY)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aVerifyState', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_VERIFY)); } } //标签 if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aTag', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_TAG)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aTag', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_TAG)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aTag', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_TAG)); } else { if ($aMedia['iMediaType'] == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aTag', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_TAG)); } } } } $aUser = Model_User::getDetail($aMedia['iUserID']); //分类 $dataCategory = Model_MediaCategory::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'], 'iStatus' => 1))); $aCategoryID = array(); foreach ($dataCategory as $key => $val) { $aCategoryID[] = $val['iCategoryID']; } if (count($aCategoryID) > 0) { $aMedia['aCategoryID'] = array_unique($aCategoryID); } //标签 $dataTag = Model_MediaTag::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'], 'iStatus' => 1))); $aTagID = array(); foreach ($dataTag as $key => $val) { $aTagID[] = $val['iTagID']; } if (count($aTagID) > 0) { $aMedia['iTagID'] = array_unique($aTagID); } //城市 $dataCity = Model_MediaCity::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'], 'iStatus' => 1))); $aCityID = array(); foreach ($dataCity as $key => $val) { $aCityID[] = $val['iCityID']; } if (count($aCityID) > 0) { $aMedia['aCityID'] = array_unique($aCityID); } //价格 // $dataPrice = Model_MediaPrice::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'] , 'iStatus' => 1))); // if(count($dataPrice) > 0){ // $aMedia['dataPrice'] = $dataPrice; // } //圈子 $dataCricle = Model_MediaCricle::getAll(array('where' => array('iMediaID' => $aMedia['iMediaID'], 'iStatus' => 1))); $aCricleID = array(); foreach ($dataCricle as $key => $val) { $aCricleID[] = $val['iCricleID']; } if (count($aCricleID) > 0) { $aMedia['aCricleID'] = array_unique($aCricleID); } $aMedia['aTypeInfo'] = explode(',', $aMedia['sTypeInfo']); $aMedia['aCooperateLevelInfo'] = explode(',', $aMedia['sCooperateLevelInfo']); $this->assign('aMedia', $aMedia); $this->assign('aUser', $aUser); } $this->assign('MediaType', Model_Media::$aType); $aRecommend = Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_RECOMMEND); $this->assign('aRecommend', $aRecommend); //后台管理用户 $adminData = Model_Admin::getAll(array('where' => array('iStatus' => 1))); $this->assign('adminData', $adminData); //城市 $this->assign('aCity', Model_City::getPairCitys()); }
/** * 开始一个新的任务进程 * * @param string $route * 任务文件名 * @param int $pid * 任务PID * @return void */ public static function newProcess($route, $pid = -1) { self::log("start {$route} ... \n"); $cmd = self::getRunCmd($route, $pid); $cmd .= ' >> '; $cmd .= Util_Common::getConf('sBaseDir', 'logger') . '/' . self::$sLogName . '/' . str_replace('/', '_', trim($route, '/')) . '.log '; $cmd .= '2>&1 &'; self::log("{$cmd}\n"); exec($cmd); self::log("ok\n"); }
private static function curl($sDomain, $sRoute, $aParam, $method, $iCacheTime) { if ($iCacheTime > 0) { $sCacheKey = md5($sDomain . $sRoute . serialize($aParam) . $method); $aRet = Util_Common::getCache()->get($sCacheKey); if (!empty($aRet)) { return $aRet; } } $time1 = microtime(true); $aParam['_time'] = time(); $aParam['_sign'] = md5($aParam['_time'] . Yaf_G::getConf('signkey', 'sdk')); $sHost = Yaf_G::getConf($sDomain, 'sdkdomain'); if (!$sHost) { throw new Exception('配置[sdkdomain][' . $sDomain . ']未找到!'); return false; } $sRoute = trim($sRoute, '/?& '); $sUrl = 'http://' . $sHost . '/' . $sRoute; if (!self::$_hCurl) { self::$_hCurl = curl_init(); } curl_setopt(self::$_hCurl, CURLOPT_DNS_USE_GLOBAL_CACHE, true); curl_setopt(self::$_hCurl, CURLOPT_HEADER, false); curl_setopt(self::$_hCurl, CURLOPT_RETURNTRANSFER, true); curl_setopt(self::$_hCurl, CURLOPT_FOLLOWLOCATION, true); curl_setopt(self::$_hCurl, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt(self::$_hCurl, CURLOPT_TIMEOUT, 30); if ($method == 'post') { curl_setopt(self::$_hCurl, CURLOPT_POST, 1); curl_setopt(self::$_hCurl, CURLOPT_POSTFIELDS, http_build_query($aParam)); } else { $sUrl .= strpos($sUrl, '?') === false ? '?' : '&'; $sUrl .= http_build_query($aParam); $aParam = null; } $aCookie = array(); if (Yaf_G::getEnv() == 'beta') { $aCookie[] = 'fjdp_version=beta'; } if (Yaf_G::isDebug()) { $aCookie[] = 'debug=2k9j38h#4'; } if (!empty($aCookie)) { curl_setopt(self::$_hCurl, CURLOPT_COOKIE, join('; ', $aCookie)); } curl_setopt(self::$_hCurl, CURLOPT_URL, $sUrl); $sData = curl_exec(self::$_hCurl); $aRet = array('status' => false, 'data' => '数据请求失败,返回为空!'); if (!empty($sData)) { $aData = json_decode($sData, true); if (isset($aData['code'])) { //兼容mapi没有status if ($aData['code'] === 0) { $aData['status'] = true; } else { $aData['status'] = false; //unset($aData['msg']); } if (isset($aData['data'])) { $aData['data']['msg'] = $aData['msg']; } else { $aData['data'] = array('msg' => $aData['msg']); } unset($aData['msg']); unset($aData['code']); } if (isset($aData['status']) && isset($aData['data'])) { $aRet = $aData; } else { $aRet = array('status' => false, 'data' => '数据请求错误:' . $sData); } } $oDebug = Util_Common::getDebug(); if ($oDebug) { $time2 = microtime(true); $use_time = round(($time2 - $time1) * 1000, 2); self::$_iOptCnt++; self::$_iUseTime += $use_time; $oDebug->groupCollapsed('Api: ' . $sUrl . ' ' . $use_time . '毫秒'); if (!empty($aParam)) { $oDebug->debug($aParam); } $oDebug->debug($aRet['data']); if (isset($aRet['debug'])) { foreach ($aRet['debug'] as $v) { if (is_array($v)) { $oDebug->add($v[0], $v[1]); } else { $oDebug->groupCollapsed($v); } } $oDebug->groupEnd(); unset($aRet['debug']); } $oDebug->groupEnd(); } if ($iCacheTime > 0 && $aRet['status']) { Util_Common::getCache()->set($sCacheKey, $aRet, $iCacheTime); } return $aRet; }
/** * 提交效果 * * @return boolean */ public function effectAction() { $iAutoID = (int) $this->getParam('id'); $aAdMedia = Model_AdMedia::getDetail($iAutoID); if (empty($aAdMedia)) { return $this->show404(); } if ($aAdMedia['iStatus'] != Model_AdMedia::STATUS_SUBMIT_EFFECT) { return $this->show404(); } if ($this->isPost()) { $sEffectImg = $this->getParam('sEffectImg'); $aErr = array(); if (empty($sEffectImg)) { $aErr['sEffectImg'] = '请上传效果图'; } if (!empty($aErr)) { return $this->showMsg($aErr, false); } Model_AdMedia::updData(array('iAutoID' => $iAutoID, 'sEffectImg' => $sEffectImg, 'iStatus' => Model_AdMedia::STATUS_CONFIRM_EFFECT)); // 邮件通知 $sTitle = Model_Kv::getValue('media_runing_email_title'); $sContent = Model_Kv::getValue('media_runing_email_content'); // 短信通知 $iTempID = Util_Common::getConf(7, 'aSmsTempID'); $aUser = Model_User::getDetail($aAdMedia['iAUserID']); $aMedia = Model_Media::getDetail($aAdMedia['iMediaID']); Util_Tools::sendMail($aUser['sEmail'], $sTitle, $sContent, array($aMedia['sMediaName'])); Util_Sms::sendTemplateSms($aUser['sMobile'], array($aMedia['sMediaName']), $iTempID); return $this->showMsg('执行效果图提交成功', true); } else { $this->assign('aAdMedia', $aAdMedia); $this->setMeta('mcenter_page', array('sTitle' => '自媒体中心 - 提交效果图')); } }
public function connect() { $this->oDbh = Util_Common::getPdoDb($this->sDbName); }
/** * 生成用户密码 * * @param unknown $sPassword * @return string */ public static function makePassword($sPassword) { $sCryptkey = Util_Common::getConf('cryptkey', 'passwd'); return md5($sCryptkey . $sPassword); }
/** * 获取列表 * * @param array $aParam * @param string $sOrder * @return array */ public static function getList($aWhere, $iPage, $sOrder = '', $iPageSize = 20, $sUrl = '', $aArg = array(), $bReturnPager = true) { $iPage = max($iPage, 1); $aRet = array(); $aParam = array('where' => $aWhere, 'limit' => ($iPage - 1) * $iPageSize . ',' . $iPageSize, 'order' => $sOrder); $aRet['aList'] = self::getOrm()->fetchAll($aParam); if ($iPage == 1 && count($aRet['aList']) < $iPageSize) { $aRet['iTotal'] = count($aRet['aList']); if ($bReturnPager) { $aRet['aPager'] = null; } } else { unset($aParam['limit'], $aParam['order']); $aRet['iTotal'] = self::getOrm()->fetchCnt($aParam); if ($bReturnPager) { if (empty($sUrl)) { $sUrl = Util_Common::getUrl(); } if (empty($aArg)) { $aArg = $_REQUEST; } $aRet['aPager'] = Util_Page::getPage($aRet['iTotal'], $iPage, $iPageSize, $sUrl, $aArg); } } return $aRet; }
/** * Ajax或API请求时,返回json数据 * @param unknown $mMsg * @param unknown $bRet */ protected function showMsg($mMsg, $bRet) { $aData = array('data' => $mMsg, 'status' => $bRet); $sDebug = Util_Common::getDebugData(); if ($sDebug) { $aData['debug'] = $sDebug; } $response = $this->getResponse(); $response->appendBody(json_encode($aData, JSON_UNESCAPED_UNICODE)); $this->autoRender(false); return false; }
/** * 获取当天文章分享量(分享量前10) */ public static function getDayShareNewsList($iCityID = 0, $iSize = 10) { $iKey = $iCityID . '_s_' . date('Ymd'); $redis = Util_Common::getRedis(); $aHotNews = $redis->ZREVRANGE($iKey, 0, $iSize - 1, 'WITHSCORES'); //当前城市的新闻 if ($iCityID > 0 && count($aHotNews) < $iSize) { //全国的新闻排名 $aHotNewsAlL = $redis->ZREVRANGE('0_v_' . date('Ymd'), 0, $iSize - 1, 'WITHSCORES'); if (!empty($aHotNewsAlL)) { //array_merge,不适合这里的合并数组 foreach ($aHotNewsAlL as $iKey => $value) { if (isset($aHotNews[$iKey])) { return array(); //请求失败; } $aHotNews[$iKey] = $value; } } } if (count($aHotNews) < $iSize) { //如果不足所需,通过总访问量判断 $iNeedSize = $iSize - count($aHotNews); $aMHots = self::getHotNewsList($iCityID, $iNeedSize, array_keys($aHotNews)); if (!empty($aMHots)) { $tmp = $aHotNews; $aHotNews = array(); $aHotNews['redis'] = $tmp; $aHotNews['mysql'] = $aMHots; } } return $aHotNews; }
/** * 广告修改 */ public function editAction() { if ($this->_request->isPost()) { $aAd = $this->_checkData('update'); if (empty($aAd)) { return null; } $aAd['iAdID'] = intval($this->getParam('iAdID')); $aOldAd = Model_Ad::getDetail($aAd['iAdID']); if (empty($aOldAd)) { return $this->showMsg('广告不存在!', false); } if (1 == Model_Ad::updData($aAd)) { if ($aOldAd['iStatus'] == Model_Ad::STATUS_WAIT_APPROVE || $aOldAd['iStatus'] == Model_Ad::STATUS_APPROVE_NO && $aAd['iStatus'] == Model_Ad::STATUS_APPROVE_OK) { $aMediaList = Model_AdMedia::getMediaByAd($aAd['iAdID'], Model_AdMedia::STATUS_CHECK, 1); foreach ($aMediaList as $aMedia) { Model_AdMedia::updStatus($aMedia['iAutoID'], Model_AdMedia::STATUS_RECEIVE); } // 邮件通知 $sTitle = Model_Kv::getValue('media_receive_order_email_title'); $sContent = Model_Kv::getValue('media_receive_order_email_content'); // 短信通知 $iTempID = Util_Common::getConf(3, 'aSmsTempID'); foreach ($aMediaList as $aMedia) { $aUser = Model_User::getDetail($aMedia['iMUserID']); Util_Mail::send($aUser['sEmail'], $sTitle, $sContent, array($aMedia['iMoney'])); Util_Sms::sendTemplateSms($aUser['sMobile'], array($aMedia['iMoney']), $iTempID); // echo $sTitle, "\n", $sContent, "\n", $aUser['sEmail'], $aUser['sMobile'], $iTempID; } } return $this->showMsg('广告更新成功!', true); } else { return $this->showMsg('广告更新失败!', false); } } else { $iAdID = intval($this->getParam('id')); $aAd = Model_Ad::getDetail($iAdID); $aAd['iMoney'] = Model_AdMedia::getDetail($aAd['iAdID'])['iMoney']; $aAd['sCatID'] = isset($aAd['sCatID']) && sCatID != '' ? explode(',', $aAd['sCatID']) : ''; $aAd['sCityID'] = isset($aAd['sCityID']) && sCatID != '' ? explode(',', $aAd['sCityID']) : ''; $iType = $aAd['iMediaType']; $aCategory = array(); switch ($iType) { case Model_Media::TYPE_WEIXIN: $aCategory = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIXIN_CATEGORY); break; case Model_Media::TYPE_FRIEND: $aCategory = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_FRIEND_CATEGORY); break; case Model_Media::TYPE_WEIBO: $aCategory = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIBO_CATEGORY); break; case Model_Media::TYPE_NEWS: $aCategory = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_NEWS_CATEGORY); break; } $aCity = Model_City::getPairCitys(Model_City::TYPE_FRONT); $aUser = Model_User::getDetail($aAd['iUserID']); $this->assign('aUser', $aUser); $this->assign('aAd', $aAd); $this->assign('aCategory', $aCategory); $this->assign('aCity', $aCity); } }
/** * 搜索自媒体 * * @param unknown $aParam * @param string $sOrder * @param number $iPageSize * @return Ambigous <NULL, boolean, string, multitype:multitype: Ambigous <> , multitype:, array/string, int/false, number, unknown, unknown> */ public static function search($aParam, $sOrder = '', $iPageSize = 20) { $aRule = array(); $aTable = array('t_media m'); $aWhere = array('m.iStatus=1', 'm.iPut=1', 'm.iMediaType=' . intval($aParam['type'])); if (!empty($aParam['name'])) { $aWhere[] = '(m.sMediaName LIKE "%' . $aParam['name'] . '%" OR m.sOpenName LIKE "%' . $aParam['name'] . '%")'; } if (!empty($aParam['catid'])) { $aTable[] = 't_media_category c'; $aWhere[] = 'c.iMediaID=m.iMediaID'; $aWhere[] = 'c.iCategoryID=' . intval($aParam['catid']); //$aWhere[] = 'c.iCategoryID IN(' . join(',', $aParam['catid']) . ')'; } if (!empty($aParam['price'])) { $aPrice = Model_Price::parsePrice($aParam['price']); $aWhere[] = '(m.iPrice1>=' . $aPrice[0] . ' AND m.iPrice1<' . $aPrice[1] . ' OR m.iPrice2>=' . $aPrice[0] . ' AND m.iPrice2<' . $aPrice[1] . ')'; } if (!empty($aParam['follower'])) { $aFollower = explode('~', $aParam['follower']); $aWhere[] = '(m.iFollowerNum>=' . $aFollower[0] . ' AND m.iFollowerNum<' . $aFollower[1] . ')'; } if (!empty($aParam['city'])) { $aTable[] = 't_media_city ct'; $aWhere[] = 'ct.iMediaID=m.iMediaID'; $aWhere[] = 'ct.iCityID IN(' . join(',', $aParam['city']) . ')'; } if (!empty($aParam['readnum0'])) { $aWhere[] = 'm.iReadAvgNum >=' . intval($aParam['readnum0']); } if (!empty($aParam['readnum1'])) { $aWhere[] = 'm.iReadAvgNum <=' . intval($aParam['readnum1']); } if (!empty($aParam['score'])) { $aWhere[] = 'm.iScore >=' . intval($aParam['score']); } if (!empty($aParam['tag'])) { $aTable[] = 't_media_tag t'; $aWhere[] = 't.iMediaID=m.iMediaID'; $aWhere[] = 't.iTagID IN(' . join(',', $aParam['tag']) . ')'; } /* if (! empty($aParam['aCriceID'])) { $aTable[] = 't_media_cricle cr'; $aWhere[] = 'cr.iMediaID=m.iMediaID'; $aWhere[] = 'cr.iCricleID IN(' . join(',', $aParam['aCriceID']) . ')'; } */ $iPage = max(intval($aParam['page']), 1); $sLimit = ' LIMIT ' . ($iPage - 1) * $iPageSize . ',' . $iPageSize; $sOrder = empty($sOrder) ? '' : ' ORDER BY ' . $sOrder; $sSQL = 'SELECT m.* FROM ' . join(',', $aTable) . ' WHERE ' . join(' AND ', $aWhere) . ' GROUP BY m.iMediaID' . $sOrder . $sLimit; $aRet['aList'] = self::query($sSQL); if ($iPage == 1 && count($aRet['aList']) < $iPageSize) { $aRet['iTotal'] = count($aRet['aList']); $aRet['aPager'] = null; } else { unset($aParam['limit'], $aParam['order']); $sSQL = 'SELECT COUNT(DISTINCT m.iMediaID) FROM ' . join(',', $aTable) . ' WHERE ' . join(' AND ', $aWhere); $aRet['iTotal'] = self::query($sSQL, 'one'); $sUrl = Util_Common::getUrl(); $aRet['aPager'] = Util_Page::getPage($aRet['iTotal'], $iPage, $iPageSize, $sUrl, $aParam); } return $aRet; }
/** * 构造函数 * * @param unknown $sKey */ public function __construct($aConf) { $this->aConf = $aConf; $this->oDebug = Util_Common::getDebug(); $this->connect(); }
/** * 生成验证码图片 * * @param int $p_iWidth * @param int $p_iHeight * @param string $p_sStr * @param int $p_iFontSize * @param int $p_iPointDensity * @param int $p_iCircleDensity * @param int $p_iFontAngle */ static function createIdentifyCodeImage($p_iWidth, $p_iHeight, $p_sStr, $p_iFontSize = 0, $p_iPointDensity = 0, $p_iCircleDensity = 0, $p_iFontAngle = 0) { // 获取各种默认值 $sTextFont = Util_Common::getConfig('sImgFont'); if (0 == $p_iFontSize) { $p_iFontSize = round($p_iHeight * 3 / 5); } if (0 == $p_iPointDensity) { $p_iPointDensity = round($p_iHeight * $p_iWidth / 100); } if (0 == $p_iCircleDensity) { $p_iCircleDensity = round($p_iHeight * $p_iWidth / 200); } // 生成画布 $oImg = imagecreatetruecolor($p_iWidth, $p_iHeight); // 填充颜色 $bgc = imagecolorallocate($oImg, 255, 255, 255); imagefill($oImg, 0, 0, $bgc); // 获取字体范围大小 $aTextSize = imagettfbbox($p_iFontSize, $p_iFontAngle, $sTextFont, $p_sStr); $iTextHeight = max($aTextSize[1], $aTextSize[3]) - min($aTextSize[5], $aTextSize[7]); $iTextWidth = max($aTextSize[4], $aTextSize[2]) - min($aTextSize[0], $aTextSize[6]); // 字体起始位置 $iTextStartLeft = ($p_iWidth - $iTextWidth) / 2; $iTextStartHeight = $p_iHeight / 2 + $iTextHeight / 2; // 字体颜色 $colors = [[0, 10, 210], [24, 157, 10], [177, 70, 20]]; $colorsValue = $colors[array_rand($colors)]; $oTextColor = imagecolorallocate($oImg, $colorsValue[0], $colorsValue[1], $colorsValue[2]); // 往画布上画字符串 // imagettftext($oImg, $p_iFontSize, $p_iFontAngle, $iTextStartLeft, $iTextStartHeight, $oTextColor, $sTextFont, $p_sStr); $len = strlen($p_sStr); $_x = ($p_iWidth - 40) / $len; for ($i = 0; $i < $len; $i++) { $iTextStartLeft = $_x * $i + mt_rand(20, 25); imagettftext($oImg, $p_iFontSize, mt_rand(-10, 10), $iTextStartLeft, $iTextStartHeight, $oTextColor, $sTextFont, $p_sStr[$i]); } for ($i = 0; $i < 100; $i++) { $color = imagecolorallocate($oImg, rand(50, 220), rand(50, 220), rand(50, 220)); imagesetpixel($oImg, rand(0, $p_iWidth), rand(0, $p_iHeight), $color); } // 往画布上画线条 for ($i = 0; $i < 5; $i++) { $color = imagecolorallocate($oImg, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156)); imageline($oImg, mt_rand(0, $p_iWidth), mt_rand(0, $p_iHeight), mt_rand(0, $p_iWidth), mt_rand(0, $p_iHeight), $color); } ob_start(); imagegif($oImg); $blImage = ob_get_contents(); ob_end_clean(); imagedestroy($oImg); return $blImage; }