本文整理汇总了PHP中Bitrix\Main\Web\Json::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Json::decode方法的具体用法?PHP Json::decode怎么用?PHP Json::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitrix\Main\Web\Json
的用法示例。
在下文中一共展示了Json::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetAccessToken
public function GetAccessToken()
{
if (($tokens = $this->getStorageTokens()) && is_array($tokens)) {
$this->access_token = $tokens["OATOKEN"];
if ($this->checkAccessToken()) {
return true;
}
}
if ($this->code === false) {
return false;
}
$h = new \Bitrix\Main\Web\HttpClient(array("socketTimeout" => $this->httpTimeout));
$h->setAuthorization($this->appID, $this->appSecret);
$result = $h->post(self::TOKEN_URL, array("grant_type" => "authorization_code", "code" => $this->code, "client_id" => $this->appID));
$this->arResult = \Bitrix\Main\Web\Json::decode($result);
if (isset($this->arResult["access_token"]) && $this->arResult["access_token"] != '') {
// yandex doesn't send refresh tokens but I leave it here in case they will
if (isset($this->arResult["refresh_token"]) && $this->arResult["refresh_token"] != '') {
$this->refresh_token = $this->arResult["refresh_token"];
}
$this->access_token = $this->arResult["access_token"];
$this->accessTokenExpires = $this->arResult["expires_in"] + time();
$_SESSION["OAUTH_DATA"] = array("OATOKEN" => $this->access_token);
return true;
}
return false;
}
示例2: Process
private function Process($service, $id = false, $jsdecode = true)
{
$token = $this->GetToken();
$s = curl_init();
if ($id !== false) {
$service = str_replace("#ID#", $id, $service);
}
curl_setopt($s, CURLOPT_URL, "https://api.ozon.ru/{$service}");
//?applicationid={$this->appID}&token=$token
curl_setopt($s, CURLOPT_HTTPHEADER, array("x-ApiVersion: 0.1", "accept:application/json", "x-applicationid:{$this->appID}", "x-token:{$token}"));
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
$reply = curl_exec($s);
curl_close($s);
if ($jsdecode) {
if (strtoupper(SITE_CHARSET) == "UTF-8") {
$reply = mb_convert_encoding($reply, "utf8", "cp1251");
}
try {
$reply = \Bitrix\Main\Web\Json::decode($reply);
} catch (Exception $e) {
$reply = array();
}
}
return $reply;
}
示例3: __construct
/**
* Response constructor.
* @param $response
*/
public function __construct($response)
{
$this->response = $response;
$this->fields = Json::decode($this->response);
if ($this->fields['error_code']) {
$this->setError($this->fields);
}
$this->state = 'ok';
if ($this->getErrors()) {
$this->state = 'error';
}
}
示例4: verifyGetToken
public function verifyGetToken($domain, $dir)
{
$data = array("verificationMethod" => "FILE", "site" => array("identifier" => self::SCOPE_DOMAIN_PROTOCOL . $domain . $dir, "type" => "SITE"));
$queryResult = $this->queryJson(static::QUERY_VERIFY_TOKEN, "POST", Json::encode($data));
if (!$queryResult) {
return false;
}
if ($queryResult->getStatus() == self::HTTP_STATUS_OK && strlen($queryResult->getResult()) > 0) {
$result = Json::decode($queryResult->getResult());
return $result["token"];
} else {
throw new \Exception('Query error! ' . $queryResult->getStatus() . ': ' . $queryResult->getResult());
}
}
示例5: listFolder
/**
* Lists folder contents
* @param $path
* @param $folderId
* @return mixed
*/
public function listFolder($path, $folderId)
{
if ($path === '/') {
$folderId = '';
} else {
$folderId = $this->getForApiDecodedId($folderId);
}
$http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
$http->setHeader('Content-Type', 'application/json; charset=UTF-8');
$http->setHeader('Authorization', "Bearer {$this->getAccessToken()}");
if ($http->get(self::API_URL . "/metadata/auto/{$folderId}") === false) {
$errorString = implode('; ', array_keys($http->getError()));
$this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_LIST_FOLDER)));
return null;
}
if (!$this->checkHttpResponse($http)) {
return null;
}
$items = Json::decode($http->getResult());
if ($items === null) {
$this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON)));
return null;
}
if (!isset($items['contents'])) {
$this->errorCollection->add(array(new Error('Could not find items in response', self::ERROR_HTTP_LIST_FOLDER)));
return null;
}
$reformatItems = array();
foreach ($items['contents'] as $item) {
$isFolder = (bool) $item['is_dir'];
$dateTime = \DateTime::createFromFormat('D, d M Y H:i:s T', $item['modified']);
$pseudoId = base64_encode($item['path']);
$reformatItems[$pseudoId] = array('id' => $pseudoId, 'name' => bx_basename($item['path']), 'type' => $isFolder ? 'folder' : 'file', 'size' => $isFolder ? '' : \CFile::formatSize($item['bytes']), 'sizeInt' => $isFolder ? '' : $item['bytes'], 'modifyBy' => '', 'modifyDate' => $dateTime->format('d.m.Y'), 'modifyDateInt' => $dateTime->getTimestamp(), 'provider' => static::getCode());
if (!$isFolder) {
$reformatItems[$pseudoId]['storage'] = '';
$reformatItems[$pseudoId]['ext'] = getFileExtension($reformatItems[$pseudoId]['name']);
}
}
unset($item);
return $reformatItems;
}
示例6: getSharedEmbedLink
protected function getSharedEmbedLink(FileData $fileData)
{
if (!$this->checkRequiredInputParams($fileData->toArray(), array('id'))) {
return null;
}
$accessToken = $this->getAccessToken();
$http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1));
$accessToken = urlencode($accessToken);
if ($http->get("https://apis.live.net/v5.0/{$fileData->getId()}/embed?access_token={$accessToken}") === false) {
$errorString = implode('; ', array_keys($http->getError()));
$this->errorCollection->add(array(new Error($errorString, self::ERROR_SHARED_EMBED_LINK)));
return null;
}
if (!$this->checkHttpResponse($http)) {
return null;
}
$finalOutput = Json::decode($http->getResult());
if ($finalOutput === null) {
$this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON)));
return null;
}
if (!preg_match('%src="(.*)"%iuU', $finalOutput['embed_html'], $m)) {
$this->errorCollection->add(array(new Error(Loc::getMessage('DISK_ONE_DRIVE_HANDLER_ERROR_COULD_NOT_FIND_EMBED_LINK'), self::ERROR_COULD_NOT_FIND_EMBED_LINK)));
return null;
}
return $m[1];
}
示例7: prepareAnswer
protected function prepareAnswer($result)
{
return \Bitrix\Main\Web\Json::decode($result);
}
示例8: unsign
public function unsign($signedValue, $salt = null)
{
$encodedValue = parent::unsign($signedValue, $salt);
return Json::decode(base64_decode($encodedValue));
}
示例9: GetAppInfo
public function GetAppInfo()
{
if ($this->access_token === false) {
return false;
}
$h = new \Bitrix\Main\Web\HttpClient();
$h->setTimeout($this->httpTimeout);
$result = $h->post(static::TOKENINFO_URL . '?access_token=' . urlencode($this->access_token));
$result = \Bitrix\Main\Web\Json::decode($result);
if (is_array($result) && $result["audience"]) {
$result["id"] = $result["audience"];
}
return $result;
}
示例10: GetCurrentUser
public function GetCurrentUser()
{
if ($this->access_token === false) {
return false;
}
$h = new \Bitrix\Main\Web\HttpClient();
$h->setHeader("Authorization", "Bearer " . $this->access_token);
$result = $h->get(static::ACCOUNT_URL);
$result = \Bitrix\Main\Web\Json::decode($result);
if (is_array($result)) {
$result["access_token"] = $this->access_token;
}
return $result;
}
示例11: GetAppInfo
public function GetAppInfo()
{
if ($this->access_token === false) {
return false;
}
$h = new \Bitrix\Main\Web\HttpClient();
$h->setTimeout($this->httpTimeout);
$result = $h->get(self::GRAPH_URL . '/debug_token?input_token=' . $this->access_token . '&access_token=' . $this->appID . "|" . $this->appSecret);
$result = \Bitrix\Main\Web\Json::decode($result);
if ($result["data"]["app_id"]) {
$result["id"] = $result["data"]["app_id"];
}
return $result;
}
示例12: GetCurrentUser
public function GetCurrentUser()
{
if ($this->access_token === false) {
return false;
}
$httpClient = new \Bitrix\Main\Web\HttpClient();
$httpClient->setHeader("Authorization", "Bearer " . $this->access_token);
$result = $httpClient->get($this->resource . static::VERSION . static::CONTACTS_URL);
$result = \Bitrix\Main\Web\Json::decode($result);
if (is_array($result)) {
$result["access_token"] = $this->access_token;
$result["refresh_token"] = $this->refresh_token;
$result["expires_in"] = $this->accessTokenExpires;
}
return $result;
}
示例13: prepareAnswer
protected function prepareAnswer($result)
{
return Json::decode($result);
}
示例14: Get
public static function Get($messageId, $params = false)
{
$arResult = array();
if (is_array($messageId)) {
if (!empty($messageId)) {
foreach ($messageId as $key => $value) {
$messageId[$key] = intval($value);
$arResult[$messageId[$key]] = array();
}
} else {
return $arResult;
}
} else {
$messageId = intval($messageId);
if ($messageId <= 0) {
return false;
}
$arResult[$messageId] = array();
}
$filter = array('=MESSAGE_ID' => $messageId);
if ($params && strlen($params) > 0) {
$filter['=PARAM_NAME'] = $params;
}
$messageParameters = IM\MessageParamTable::getList(array('select' => array('ID', 'MESSAGE_ID', 'PARAM_NAME', 'PARAM_VALUE', 'PARAM_JSON'), 'filter' => $filter));
while ($ar = $messageParameters->fetch()) {
if (strlen($ar["PARAM_JSON"])) {
$value = \Bitrix\Main\Web\Json::decode($ar["PARAM_JSON"]);
} else {
$value = $ar["PARAM_VALUE"];
}
$arResult[$ar["MESSAGE_ID"]][$ar["PARAM_NAME"]][] = $value;
}
if (is_array($messageId)) {
foreach ($messageId as $key) {
$arResult[$key] = self::PrepareValues($arResult[$key]);
}
} else {
$arResult = self::PrepareValues($arResult[$messageId]);
}
return $arResult;
}
示例15: getCurrentUser
/**
* Returns current Yandex user data
*
* @return array
*
* @throws SystemException
* @throws YandexException
*/
public function getCurrentUser()
{
if (!array_key_exists('AUTH_USER', $this->engineSettings) || !is_array($this->engineSettings['AUTH_USER'])) {
$queryResult = self::query(self::QUERY_USER);
if ($queryResult->getStatus() == self::HTTP_STATUS_OK && strlen($queryResult->getResult()) > 0) {
$res = Web\Json::decode($queryResult->getResult());
if (is_array($res)) {
$this->engineSettings['AUTH_USER'] = $res;
$this->saveSettings();
return $this->engineSettings['AUTH_USER'];
}
}
throw new Engine\YandexException($queryResult);
} else {
return $this->engineSettings['AUTH_USER'];
}
}