本文整理汇总了PHP中Safe::json_decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::json_decode方法的具体用法?PHP Safe::json_decode怎么用?PHP Safe::json_decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Safe
的用法示例。
在下文中一共展示了Safe::json_decode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_start_url
/**
* the URL to start and to join the meeting
*
* @see overlays/events/start.php
*
* @return string the URL to redirect the user to the meeting, or NULL on error
*/
function get_start_url()
{
global $context;
// almost random passwords
$this->initialize_passwords();
// link to authenticate
$url = 'https://my.dimdim.com/api/auth/login';
// parameters to authenticate
$parameters = array();
$parameters['account'] = $this->attributes['account'];
$parameters['password'] = $this->attributes['password'];
$parameters['group'] = 'all';
// encode in json
$data = array('request' => Safe::json_encode($parameters));
// do authenticate
if ($response = http::proceed($url, '', $data)) {
// successful authentication
$output = Safe::json_decode($response);
if (isset($output['result']) && $output['result']) {
// remember the authentication token
$fields = array('token' => $output['response']['authToken']);
$this->set_values($fields);
// link to create a meeting
$url = 'https://my.dimdim.com/api/conf/start_meeting';
// provide authentication token
$headers = 'X-Dimdim-Auth-Token: ' . $this->attributes['token'] . CRLF;
// parameters to create a meeting
$parameters = array();
$parameters['authToken'] = $this->attributes['token'];
$parameters['account'] = $this->attributes['account'];
$parameters['clientId'] = Surfer::get_id();
$parameters['displayName'] = Surfer::get_name();
$parameters['meetingName'] = $this->anchor->get_title();
$parameters['roomName'] = $this->anchor->get_title();
$parameters['meetingLengthMinutes'] = $this->attributes['duration'];
$parameters['attendeeKey'] = $this->attendee_password;
$parameters['assistantEnabled'] = 'false';
// disable some features
$parameters['displayDialInfo'] = 'false';
// message displayed within the BigBlueButton session
$welcome = '';
// meeting title
if (is_object($this->anchor)) {
$welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Title'), $this->anchor->get_title()) . "\n";
}
// meeting date
if (isset($this->attributes['date_stamp'])) {
$welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Date'), Skin::build_date($this->attributes['date_stamp'], 'standalone')) . "\n";
}
// meeting duration
if (isset($this->attributes['duration'])) {
$welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Duration'), $this->attributes['duration'] . ' ' . i18n::s('minutes')) . "\n";
}
// build a link to the owner page, if any
if (is_object($this->anchor) && ($user = Users::get($this->anchor->get_value('owner_id')))) {
$welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Chairman'), $user['full_name']) . "\n";
}
// welcome message
$parameters['agenda'] = $welcome;
// return URL
if (is_callable(array($this->anchor, 'get_url'))) {
$parameters['returnurl'] = $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url();
}
// encode in json
$data = array('request' => Safe::json_encode($parameters));
// do the transaction
if ($response = http::proceed($url, $headers, $data)) {
// successful transaction
$output = Safe::json_decode($response);
if (isset($output['result']) && $output['result']) {
// redirect to the target page
return 'https://my.dimdim.com/redirect?clientId=' . urlencode(Surfer::get_id()) . '&account=' . urlencode($this->attributes['account']);
}
}
}
}
// don't know where to go
return NULL;
}
示例2: import_response
/**
* parse a response on client side
*
* @param string the received HTTP body
* @param string the received HTTP headers
* @param mixed the submitted parameters
* @return an array of which the first value indicates call success or failure
*/
function import_response($data, $headers = NULL, $parameters = NULL)
{
if ($decoded = Safe::json_decode($data)) {
// remove JSON-RPC signature
if (isset($decoded['version'])) {
unset($decoded['version']);
}
if (isset($decoded['jsonrpc'])) {
unset($decoded['jsonrpc']);
}
// error is reported
if (!empty($decoded['error'])) {
// ensure no result is provided
if (isset($decoded['result'])) {
unset($decoded['result']);
}
// regular case
} else {
// ensure no error is reported
if (isset($decoded['error'])) {
unset($decoded['error']);
}
// no id in parameters, so strip it off from response
if (empty($parameters['id']) && isset($decoded['id'])) {
unset($decoded['id']);
}
}
// job done
return array(TRUE, $decoded);
}
return array(FALSE, 'No way to decode the response');
}
示例3: load_skin
*/
include_once '../shared/global.php';
// load a skin engine
load_skin('services');
// process raw content
$raw_data = file_get_contents("php://input");
// save the raw request if debug mode
if (isset($context['debug_rpc']) && $context['debug_rpc'] == 'Y') {
Logger::remember('services/json_rpc.php: json_rpc request', rawurldecode($raw_data), 'debug');
}
// transcode to our internal charset
if ($context['charset'] == 'utf-8') {
$raw_data = utf8::from_unicode($raw_data);
}
// decode request components -- use rawurldecode() instead urldecode(), else you will loose + signs
$parameters = Safe::json_decode(rawurldecode($raw_data));
// prepare the response
$response = array();
// replicate version, if any (JSON-RPC 1.1)
if (!empty($parameters['version'])) {
$response['version'] = $parameters['version'];
}
// replicate keyword, if any (JSON-RPC 2.0)
if (!empty($parameters['jsonrpc'])) {
$response['jsonrpc'] = $parameters['jsonrpc'];
}
// no result yet
$response['result'] = NULL;
// no error either
$response['error'] = NULL;
// nothing to parse
示例4: elseif
// look for credentials
$credentials = NULL;
if (isset($_REQUEST['credentials'])) {
$credentials = $_REQUEST['credentials'];
} elseif (isset($context['arguments'][0])) {
$credentials = $context['arguments'][0];
}
$credentials = strip_tags($credentials);
// fix credentials if followed by text
if ($credentials && ($position = strpos($credentials, '-'))) {
$credentials = substr($credentials, 0, $position);
}
// data has been serialized, then base64 encoded
if ($credentials && ($credentials = base64_decode($credentials))) {
// json is more efficient, but we may have to fall-back to php serialization
if (!($credentials = Safe::json_decode($credentials))) {
$credentials = Safe::unserialize($credentials);
}
}
// load localized strings
if (is_callable(array('i18n', 'bind'))) {
i18n::bind('users');
}
// load the skin
load_skin('users');
// page title
if (!Surfer::is_logged()) {
$context['page_title'] = i18n::s('Who are you?');
} else {
$context['page_title'] = i18n::s('You are') . ' ' . Surfer::get_name();
}