public function fetchini($service) { if ($this->rpc === null) { $ini = \Sooh\Base\Ini::getInstance()->get('RpcConfig'); unset($ini['force']); return $ini; } else { \Sooh\Base\Log\Data::error('Rpcservices should never be called by rpc'); throw new \Sooh\Base\ErrException('Rpcservices should never be called by rpc'); //return $this->rpc->initArgs(array('arg1'=>$arg1))->send();//call('CheckinBook/'.__FUNCTION__, array($withBonus,$userOrAccountId)); } }
public function update($sessionId, $sessData, $trans) { if ($this->rpc !== null) { return $this->rpc->initArgs(array('sessionId' => $sessionId, 'sessData' => $sessData, 'trans' => $trans))->send(__FUNCTION__); } else { try { $err = new \Sooh\Base\ErrException(''); if (!empty($trans['sessionId']) && $trans['sessionId'] != $sessionId) { \Sooh\Base\Log\Data::error("ERROR on update session with sessionId dismatch: {$sessionId}", array('trans' => $trans, 'data' => $sessData)); return 'error'; } else { $obj = \Sooh\DB\Cases\SessionStorage::getCopy($sessionId); //unset($trans['sessionId']); if (!empty($trans['iRecordVerID'])) { $obj->setVerId($trans['iRecordVerID']); } //unset($trans['iRecordVerID']); ksort($sessData); $md5 = md5(json_encode($sessData)); // error_log('[TRACE-session '.$_COOKIE['SoohSessId'].' storage] md5_'.($md5!=$this->md5Last?'NE':'EQ').' old='.$this->md5Last.' vs new '.$md5); if ($md5 != $this->md5Last) { $obj->setSessionData($sessData); $obj->setField('lastUpdate', time()); $obj->update(); } //error_log(">>>>>>>>>>>session>>>$sessionId\n". var_export($sessData,true)."\n". var_export($trans,true)); return 'done'; } } catch (\Exception $e) { \Sooh\Base\Log\Data::error('errorOnUpdateSession', $e); return 'error:' . $e->getMessage(); } } }
/** * 账号登入, 失败抛出异常(密码错误,账号找不到等等) * @param $loginName * @param $cameFrom * @param $password * @param array $customArgs * @return mixed * @throws \ErrorException * @throws \Sooh\Base\ErrException * @throws array */ public function login($loginName, $cameFrom, $password, $customArgs = ['contractId']) { if ($this->rpc !== null) { return $this->rpc->initArgs(['loginName' => $loginName, 'cameFrom' => $cameFrom, 'password' => $password, 'customArgs' => $customArgs])->send(__FUNCTION__); } else { $objLogin = \Sooh\DB\Cases\AccountAlias::getCopy($loginName, $cameFrom); $objLogin->load(); if ($objLogin->exists()) { $accountId = $objLogin->getField('accountId'); $this->setAccountStorage($accountId); $this->account->load(); if ($this->account->exists()) { $dt = \Sooh\Base\Time::getInstance(); $cmp = md5($password . $this->account->getField('passwdSalt')); $loginFailed = $this->account->getField('loginFailed'); if ($loginFailed) { $cd = new \Sooh\Base\CD($loginFailed, 750, 3600); if ($cd->isRed()) { throw new \Sooh\Base\ErrException(self::errAccountOrPasswordError); } } else { $cd = new \Sooh\Base\CD(0, 750, 3600); } $ymdhForbidden = $this->account->getField('dtForbidden'); if ($ymdhForbidden) { if ($dt->YmdH <= $ymdhForbidden) { throw new \Sooh\Base\ErrException(self::errAccountLock, 404); } } if ($cmp != $this->account->getField('passwd')) { $cd->add(1); $ret = new \Sooh\Base\ErrException(self::errAccountOrPasswordError, 404); } else { $nickname = $this->account->getField('nickname'); $ret = array('accountId' => $this->account->getField('accountId'), 'nickname' => $nickname); if (!empty($customArgs)) { if (is_string($customArgs)) { $customArgs = explode(',', $customArgs); } foreach ($customArgs as $k) { $ret[$k] = $this->account->getField('contractId'); } } } $this->account->setField('lastIP', \Sooh\Base\Tools::remoteIP()); $this->account->setField('lastDt', $dt->timestamp()); $this->account->setField('loginFailed', $cd->toString()); try { $this->account->update(); } catch (\ErrorException $ex) { \Sooh\Base\Log\Data::error("error on update account when login:"******"\n" . \Sooh\DB\Broker::lastCmd() . "\n" . $ex->getTraceAsString()); } if (is_array($ret)) { return $ret; } else { throw $ret; } } else { throw new \Sooh\Base\ErrException(self::errAccountOrPasswordError, 400); } } else { throw new \Sooh\Base\ErrException(self::errAccountOrPasswordError, 400); } } }
/** * 发送请求 * @return mixed */ public function send($cmd) { $this->final_cmd = $cmd; $hosts = $this->final_hosts; $timestamp = \Sooh\Base\Time::getInstance()->timestamp(); while (sizeof($hosts)) { $rand = array_rand($hosts); $host = $hosts[$rand]; unset($hosts[$rand]); //if('rpcservices'!=$this->final_service) //error_log("#######rpc-call####{$this->final_protocol}:{$host}, {$this->final_service}, {$this->final_cmd},". json_encode($this->final_args)); $ret = $this->getSender($this->final_protocol)->_send($host, $this->final_service, $this->final_cmd, $this->final_args, $timestamp, $this->clacSign($timestamp)); //error_log("#######rpc-ret####".json_encode($ret)); if (empty($ret)) { \Sooh\Base\Log\Data::error("found_rpc_server_down:" . $host . ' with cmd'); } else { $arr = json_decode($ret, true); if (is_array($arr)) { if ($arr['code'] == 200) { return $arr['data']; } else { $err = new \Sooh\Base\ErrException($arr['msg'], $arr['code']); $err->customData = $arr['data']; throw $err; } } } } throw new \Sooh\Base\ErrException('rpc_failed:' . $this->final_cmd); }