Exemple #1
0
 /**
  * 处理业务
  */
 public function handle()
 {
     $accessToken = md5(PhalconPlusUtil::Guid());
     $secretToken = md5(PhalconPlusUtil::Guid());
     $expiresIn = $this->di->get('apiConfig')->expires_in;
     // 记录数据
     $access = new ApiAccessToken();
     $access->appAccess = $this->appAccess->id;
     $access->accessToken = $accessToken;
     $access->secretToken = $secretToken;
     $access->expiresIn = $expiresIn;
     $access->clientInfo = $this->parameters->postBody ? $this->parameters->postBody : ' ';
     if ($access->save()) {
         // 返回数据
         $this->setResponse(['access_token' => $accessToken, 'secret_token' => $secretToken, 'expires_in' => $expiresIn]);
     } else {
         $error = '';
         foreach ($access->getMessages() as $msg) {
             $error .= $msg . ',';
         }
         $this->error(ResultStatus::DATABASE_ERROR, '数据库异常.');
         $this->di->get('logger')->error('数据库异常, 保存授权信息异常, GET:' . json_encode($_GET) . ', POST:' . $this->request->getRawBody() . ', error: ' . $error);
     }
 }
Exemple #2
0
 /**
  *
  * 验证app_token,并获取相关的信息
  * @return bool
  */
 public function verifyToken()
 {
     $this->apiAccess = ApiAccessToken::query()->where('accessToken = :token:')->bind(['token' => $this->parameters->accessToken])->execute()->getFirst();
     if (!!$this->apiAccess) {
         if ($this->apiAccess->state == 1) {
             $this->secretToken = $this->apiAccess->secretToken;
             return true;
         } else {
             $this->error(ResultStatus::ACCESS_TOKEN_ERROR, 'access token错误..');
             return false;
         }
     }
     $this->error(ResultStatus::ACCESS_TOKEN_ERROR, 'access token错误.');
     return false;
 }