/**
  * logout
  */
 public function actionClear($tokenid, $clientid)
 {
     $map = $this->getRestMap();
     /**
      * @var AccessToken $token
      */
     try {
         Assert::hasText($tokenid, "tokenid传递参数为空!");
         Assert::hasText($clientid, "clientid传递参数为空!");
         //验证token
         $token = AccessTokenService::validateToken(Yii::app()->request);
         Assert::hasText($token, "token 查询结果为空!");
         //清理
         AccessTokenService::clearToken(Yii::app()->request);
         $map["clientid"] = $token->clientid;
         $map["tokenid"] = $token->tokenid;
         $map[AjaxStatus::PROPERTY_MESSAGES] = "清理成功";
         $map[AjaxStatus::PROPERTY_STATUS] = AjaxStatus::STATUS_SUCCESSFUL;
         $map[AjaxStatus::PROPERTY_CODE] = AjaxStatus::CODE_OK;
     } catch (IllegalArgumentException $e) {
         $map[AjaxStatus::PROPERTY_STATUS] = AjaxStatus::STATUS_FAILED;
         $map[AjaxStatus::PROPERTY_CODE] = AjaxStatus::CODE_503;
         $map[AjaxStatus::PROPERTY_MESSAGES] = $e->getMessage();
     } catch (Exception $e) {
         $map[AjaxStatus::PROPERTY_STATUS] = AjaxStatus::STATUS_FAILED;
         $map[AjaxStatus::PROPERTY_CODE] = AjaxStatus::CODE_503;
         $map[AjaxStatus::PROPERTY_MESSAGES] = $e->getMessage();
     }
     echo SnapshotHelper::encodeArray($map);
 }
Example #2
0
 /**
  * 组合返回JSON数据格式
  * @author wjh
  * @version 2014-5-10
  * @param mixed $data string text or array
  * @param string $err error message
  * @param null $type 返回类型,json | jsonp
  * @param null $jsonpfunc 如果 $type= jsonp ,用来指定回调函数
  * @throws Exception
  * @return array
  */
 public static function encodeJsonReturn($data, $err = null, $type = 'json', $jsonpfunc = 'jsonpCallback')
 {
     if (is_null($data)) {
         $data = array();
     } elseif (BArrayHelper::isCActiveRecord($data)) {
         $data = $data->attributes;
     } elseif (BArrayHelper::isCActiveRecordArray($data)) {
         $data = BArrayHelper::getModelAttributesArray($data);
     } else {
         //$data = array();
     }
     if (is_array($data)) {
         $data = SnapshotHelper::encodeArray($data);
     }
     if (!empty($type) && $type == 'jsonp') {
         $str = sprintf('%s({"err":[%s],"data":%s})', $jsonpfunc, $err, $data);
     } else {
         $str = sprintf('{"err":[%s],"data":%s}', $err, $data);
     }
     return $str;
 }