Ejemplo n.º 1
0
 /**
  * 
  * @param callable $funcSend
  * @param string $msgFormat
  * @param string $code
  * @throws Exception on update-db failed or send sms failed
  * @return boolean return false on too many times
  */
 public function sendCode($funcSend, $msgFormat, $code = null)
 {
     $sentCounterInHour = sizeof($this->dat['codes']);
     if ($sentCounterInHour > self::$maxCounterPerHour) {
         return false;
     }
     if ($code === null) {
         $code = substr(uniqid(), -6);
     }
     $this->dat['codes'][$code] = $this->dt->timestamp();
     parent::setField('dat', $this->dat);
     $this->update();
     $msgFormat = str_replace('{code}', $code, $msgFormat);
     if (is_array($funcSend) || is_string($funcSend)) {
         $ret = call_user_func($funcSend, current($this->pkey), $msgFormat);
     } else {
         $ret = $funcSend(current($this->pkey), $msgFormat);
     }
     if ($ret === false) {
         throw new \ErrorException('send sms failed:' . $msgFormat);
     }
     return true;
 }
Ejemplo n.º 2
0
 public static function getCopy($code)
 {
     return parent::getCopy(['code' => $code]);
 }
Ejemplo n.º 3
0
 /**
  * 
  * @return  LogStorage
  */
 public static function getCopy($guid)
 {
     return parent::getCopy(array('logGuid' => $guid));
 }
Ejemplo n.º 4
0
 /**
  * @return AccountStorage
  */
 public static function getCopy($accountId)
 {
     return parent::getCopy(array('accountId' => $accountId));
 }
Ejemplo n.º 5
0
 /**
  * @return AccountAlias
  */
 public static function getCopy($loginName, $cameFrom)
 {
     return parent::getCopy(array('loginName' => $loginName, 'cameFrom' => $cameFrom));
 }
Ejemplo n.º 6
0
 public static function getCopy($refreshToken)
 {
     return parent::getCopy(['refreshToken' => $refreshToken]);
 }
Ejemplo n.º 7
0
 /**
  * client getCopy
  * @param string $clientId 客户端ID
  * @param string $clientSecret 客户端密钥
  * @return \Sooh\DB\Base\KVObj
  */
 public static function getCopy($clientId)
 {
     return parent::getCopy(['id' => $clientId]);
 }
Ejemplo n.º 8
0
 public function update($callback = null)
 {
     try {
         parent::update($callback);
     } catch (\Sooh\DB\Error $e) {
         if (\Sooh\DB\Broker::errorIs($e, \Sooh\DB\Error::tableNotExists)) {
             $this->createTable();
             parent::update($callback);
         } else {
             throw $e;
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * 
  * @param string $type [idfa|imei|md5|mac]
  * @param string $sn
  * @param string $phone
  * @param string $userIdentifier
  * @param string $contractId
  * @param array $extraData
  * @return \PrjLib\DataDig\Log\Device
  */
 public static function ensureOne($type, $sn, $phone = null, $userIdentifier = null, $contractId = null, $extraData = null)
 {
     $dt = \Sooh\Base\Time::getInstance();
     $deviceId = self::guidMaker($type, $sn);
     $ddd = \Yaf_Dispatcher::getInstance()->getRequest();
     error_log("trace device->ensure(" . $ddd->getModuleName() . '/' . $ddd->getControllerName() . '/' . $ddd->getActionName() . ") " . $deviceId . "  phone:{$phone}  user:{$userIdentifier}");
     $sys = parent::getCopy(array('deviceId' => $deviceId));
     try {
         \Sooh\DB\Broker::errorMarkSkip(\Sooh\DB\Error::tableNotExists);
         $sys->load();
     } catch (\ErrorException $e) {
         if (\Sooh\DB\Broker::errorIs($e, \Sooh\DB\Error::tableNotExists)) {
             $sys->createTable();
         }
     }
     $fields = array('ip' => \Sooh\Base\Tools::remoteIP(), 'ymd' => $dt->YmdFull, 'hhiiss' => $dt->his);
     try {
         if ($sys->exists() === false) {
             foreach ($fields as $k => $v) {
                 $sys->setField($k, $v);
             }
             $sys->setField('phone', empty($phone) ? '0' : $phone);
             $sys->setField('userIdentifier', empty($userIdentifier) ? '' : $userIdentifier);
             $sys->setField('extraData', empty($extraData) ? '' : json_encode($extraData));
             $sys->setField('extraRet', '');
             $sys->setField('contractId', empty($contractId) ? '0' : $contractId);
             try {
                 \Sooh\DB\Broker::errorMarkSkip(\Sooh\DB\Error::duplicateKey);
                 $sys->update();
                 $sys->flgNewCreate = true;
                 return $sys;
             } catch (\ErrorException $e) {
                 $sys->reload();
                 if ($sys->exists() === false) {
                     error_log('error create new device log:' . $e->getMessage() . "\n" . $e->getTraceAsString());
                     return $sys;
                 }
             }
         }
         $oldPhone = $sys->getField('phone', true);
         $oldUser = $sys->getField('userIdentifier', true);
         $oldContractId = $sys->getField('contractId', true);
         if (!empty($phone) && !empty($oldPhone) && $phone != $oldPhone || !empty($oldUser) && !empty($userIdentifier) && $oldUser != $userIdentifier || !empty($oldContractId) && !empty($contractId) && $oldContractId != $contractId) {
             $extraDataOld = $sys->getField('extraData', true);
             $extraRetOld = $sys->getField('extraRet', true);
             $extraRetOld = is_scalar($extraRetOld) === false ? json_encode($extraRetOld) : $extraRetOld;
             \Sooh\DB\Broker::getInstance(\PrjLib\Tbname::db_rpt)->addRecord(\PrjLib\Tbname::tb_device_log, array('deviceId' => $deviceId, 'dtChange' => $dt->YmdFull . sprintf('%06d', $dt->his), 'phoneOld' => $oldPhone, 'userIdentifierOld' => $oldUser, 'extraDataOld' => is_scalar($extraDataOld) === false ? json_encode($extraDataOld) : $extraDataOld, 'extraRetOld' => $extraRetOld, 'contractIdOld' => $oldContractId, 'phoneNew' => $phone, 'userIdentifierNew' => $userIdentifier, 'extraDataNew' => empty($extraData) ? '' : json_encode($extraData), 'extraRetNew' => $extraRetOld, 'contractIdNew' => empty($contractId) ? '0' : $contractId, 'ipOld' => $sys->getField('ip', true), 'ipNew' => $fields['ip']));
         }
         foreach ($fields as $k => $v) {
             $sys->setField($k, $v);
         }
         if (!empty($extraData)) {
             $sys->setField('extraData', empty($extraData) ? '' : json_encode($extraData));
         }
         if (!empty($phone)) {
             $sys->setField('phone', $phone);
         }
         if (!empty($userIdentifier)) {
             $sys->setField('userIdentifier', $userIdentifier);
         }
         //$sys->setField('extraRet', '');
         if (!empty($contractId)) {
             $sys->setField('contractId', $contractId);
         }
         $sys->update();
         //var_log($sys->dump(),'======================log->filled for '.$sys->tbname());
         \Sooh\DB\Broker::errorMarkSkip(\Sooh\DB\Error::tableNotExists);
     } catch (\ErrorException $e) {
         error_log("error: on ensure-device:" . $e->getMessage() . "\n" . $e->getTraceAsString());
     }
     return $sys;
 }
Ejemplo n.º 10
0
 /**
  * 
  * @param \Sooh\DB\Base\KVObj $obj
  * @param int $retry
  */
 public function markInstalled($obj, $retry)
 {
     $obj->setField('callbackRetry', 1);
 }
Ejemplo n.º 11
0
 /**
  * 获取tb_oauth_token
  * @param string $token
  * @return \Sooh\DB\Base\KVObj
  */
 public static function getCopy($token)
 {
     return parent::getCopy(['accessToken' => $token]);
 }
Ejemplo n.º 12
0
 public function setSessionData($arr)
 {
     parent::setField('accountId', $arr['accountId']);
     parent::setField('sessionData', json_encode($arr));
 }