/** * Seguridad programada completamente */ function evt__form__enviar($datos) { $carpeta = dirname(__FILE__); //--1- Arma el mensaje (incluyendo los headers) $this->s__echo = $datos; $clave = xml_encode($datos['clave']); $valor = xml_encode($datos['valor']); $payload = <<<XML <ns1:test xmlns:ns1="http://siu.edu.ar/toba_referencia/serv_pruebas"> \t<texto>{$clave} {$valor}</texto> </ns1:test> XML; $mensaje = new toba_servicio_web_mensaje($payload); //--2- Arma el servicio indicando certificado del server y clave privada del cliente $cert_server = ws_get_cert_from_file($carpeta . '/servidor.crt'); $clave_privada = ws_get_key_from_file($carpeta . "/cliente.pkey"); $cert_cliente = ws_get_cert_from_file($carpeta . "/cliente.crt"); $seguridad = array("sign" => true, "encrypt" => true, "algorithmSuite" => "Basic256Rsa15", "securityTokenReference" => "IssuerSerial"); $policy = new WSPolicy(array("security" => $seguridad)); $security_token = new WSSecurityToken(array("privateKey" => $clave_privada, "receiverCertificate" => $cert_server, "certificate" => $cert_cliente)); $opciones = array('to' => 'http://localhost/' . toba_recurso::url_proyecto() . '/servicios.php/serv_seguro_codigo', 'action' => 'http://siu.edu.ar/toba_referencia/serv_pruebas/test', 'policy' => $policy, 'securityToken' => $security_token); $servicio = toba::servicio_web('cli_seguro', $opciones); //-- 3 - Muestra la respuesta $respuesta = $servicio->request($mensaje); toba::notificacion()->info($respuesta->get_payload()); }
function xml_encode($mixed, $domElement = null, $DOMDocument = null) { if (is_null($DOMDocument)) { $DOMDocument = new DOMDocument(); $DOMDocument->formatOutput = true; xml_encode($mixed, $DOMDocument, $DOMDocument); echo $DOMDocument->saveXML(); } else { if (is_array($mixed)) { foreach ($mixed as $index => $mixedElement) { if (is_int($index)) { if ($index === 0) { $node = $domElement; } else { $node = $DOMDocument->createElement($domElement->tagName); $domElement->parentNode->appendChild($node); } } else { $plural = $DOMDocument->createElement($index); $domElement->appendChild($plural); $node = $plural; if (!(rtrim($index, 's') === $index)) { $singular = $DOMDocument->createElement(rtrim($index, 's')); $plural->appendChild($singular); $node = $singular; } } xml_encode($mixedElement, $node, $DOMDocument); } } else { $domElement->appendChild($DOMDocument->createTextNode($mixed)); } } }
/** * Ajax方式返回数据到客户端 * @access protected * @param mixed $data 要返回的数据 * @param String $type AJAX返回数据格式 * @return void */ protected function ajaxReturn($data, $type = '') { if (empty($type)) { $type = C('DEFAULT_AJAX_RETURN'); } switch (strtoupper($type)) { case 'JSON': // 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:application/json; charset=utf-8'); exit(json_encode($data)); case 'XML': // 返回xml格式数据 header('Content-Type:text/xml; charset=utf-8'); exit(xml_encode($data)); case 'JSONP': // 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:application/json; charset=utf-8'); $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER'); exit($handler . '(' . json_encode($data) . ');'); case 'EVAL': // 返回可执行的js脚本 header('Content-Type:text/html; charset=utf-8'); exit($data); } }
function evt__form_adjunto__enviar($datos) { //--1 -Guarda el archivo en un temporal if (isset($datos['adjunto'])) { $this->s__adjunto['archivo'] = $datos['adjunto']['name']; $img = toba::proyecto()->get_www_temp($this->s__adjunto['archivo']); // Mover los archivos subidos al servidor del directorio temporal PHP a uno propio. move_uploaded_file($datos['adjunto']['tmp_name'], $img['path']); } $this->s__adjunto['texto'] = xml_encode($datos['texto']); //--2 -Arma el mensaje $payload = <<<XML <ns1:upload xmlns:ns1="http://siu.edu.ar/toba_referencia/serv_pruebas"> \t<texto>{$this->s__adjunto['texto']}</texto> <ns1:fileName>{$this->s__adjunto['archivo']}</ns1:fileName> \t<ns1:image xmlmime:contentType="image/png" xmlns:xmlmime="http://www.w3.org/2004/06/xmlmime"> \t<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:myid1"></xop:Include> \t</ns1:image> </ns1:upload> XML; //--3 -Pide el servicio $opciones = array('to' => 'http://localhost/' . toba_recurso::url_proyecto() . '/servicios.php/serv_sin_seguridad'); $servicio = toba::servicio_web('cli_sin_seguridad', $opciones); $imagen = toba::proyecto()->get_www_temp($this->s__adjunto['archivo']); $imagen_contenido = file_get_contents($imagen['path']); $opciones = array('attachments' => array('myid1' => $imagen_contenido)); $mensaje = new toba_servicio_web_mensaje($payload, $opciones); $respuesta = $servicio->request($mensaje); //--4 - Guarda la respuesta en un temporal $this->adjunto_respuesta = toba::proyecto()->get_www_temp('salida.png'); file_put_contents($this->adjunto_respuesta['path'], current($respuesta->wsf()->attachments)); }
public function ajaxReturn($data, $type = "") { if (empty($type)) { $type = "json"; } switch (strtoupper($type)) { case "JSON": header("Content-Type:application/json; charset=" . CHARSET); exit(CJSON::encode($data)); break; case "XML": header("Content-Type:text/xml; charset=" . CHARSET); exit(xml_encode($data)); break; case "JSONP": header("Content-Type:text/html; charset=" . CHARSET); $handler = isset($_GET["callback"]) ? $_GET["callback"] : self::DEFAULT_JSONP_HANDLER; exit($handler . "(" . (!empty($data) ? CJSON::encode($data) : "") . ");"); break; case "EVAL": header("Content-Type:text/html; charset=" . CHARSET); exit($data); break; default: exit($data); break; } }
/** * Ajax方式返回数据到客户端 * @access protected * @param mixed $data 要返回的数据 * @param String $type AJAX返回数据格式 * @return void */ protected function ajaxReturn($data, $type = '', $json_option = 0) { $data['referer'] = $data['url'] ? $data['url'] : ""; $data['state'] = $data['status'] ? "success" : "fail"; if (empty($type)) { $type = C('DEFAULT_AJAX_RETURN'); } switch (strtoupper($type)) { case 'JSON': // 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:application/json; charset=utf-8'); exit(json_encode($data, $json_option)); case 'XML': // 返回xml格式数据 header('Content-Type:text/xml; charset=utf-8'); exit(xml_encode($data)); case 'JSONP': // 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:application/json; charset=utf-8'); $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER'); exit($handler . '(' . json_encode($data, $json_option) . ');'); case 'EVAL': // 返回可执行的js脚本 header('Content-Type:text/html; charset=utf-8'); exit($data); case 'AJAX_UPLOAD': // 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:text/html; charset=utf-8'); exit(json_encode($data, $json_option)); default: // 用于扩展其他返回格式数据 Hook::listen('ajax_return', $data); } }
public function mtReturn($status, $info, $navTabId = "", $closeCurrent = true) { $result = array(); $result['statusCode'] = $status; $result['message'] = $info; $result['tabid'] = $navTabId . '/index'; $result['forward'] = ''; $result['forwardConfirm'] = ''; $result['closeCurrent'] = $closeCurrent; if (empty($type)) { $type = C('DEFAULT_AJAX_RETURN'); } if (strtoupper($type) == 'JSON') { // 返回JSON数据格式到客户端 包含状态信息 header("Content-Type:text/html; charset=utf-8"); exit(json_encode($result)); } elseif (strtoupper($type) == 'XML') { // 返回xml格式数据 header("Content-Type:text/xml; charset=utf-8"); exit(xml_encode($result)); } elseif (strtoupper($type) == 'EVAL') { // 返回可执行的js脚本 header("Content-Type:text/html; charset=utf-8"); exit($data); } else { // TODO 增加其它格式 } }
/** * Responde exactamente con la misma cadena enviada * @param string $texto texto a repetir * (maps to the xs:string XML schema type ) * @return string $texto total price *(maps to the xs:string XML schema type ) */ function op__test(toba_servicio_web_mensaje $mensaje) { $xml = new SimpleXMLElement($mensaje->get_payload()); $texto = xml_encode((string) $xml->texto); $payload = <<<XML <ns1:eco xmlns:ns1="http://siu.edu.ar/toba_referencia/pruebas"> \t<texto>Respuesta: {$texto}</texto> </ns1:eco> XML; return new toba_servicio_web_mensaje($payload); }
/** * Converte um objeto ou um array em uma string XML * @param mixed $data dados a serem convertidos em XML * @return string retorna uma string XML */ function xml_encode($data) { if (!is_array($data) && !is_object($data)) { return $data; } $encoded = "\n"; foreach ($data as $k => $d) { $e = is_string($k) ? $k : 'n'; $encoded .= "\t<" . $e . ">" . xml_encode($d) . "</" . $e . ">\n"; } return $encoded . ""; }
/** * @param array $mensaje * @return string */ function op__test(toba_servicio_web_mensaje $mensaje) { $array = $mensaje->get_array(); $id = $this->get_id_cliente(); if (isset($id)) { $id = "No presente"; } else { $id = var_export($id); } $id = xml_encode($id); $payload = array("Clave: {$array['clave']}. Valor: {$array['valor']}. ID: {$id}"); return new toba_servicio_web_mensaje($payload); }
public static function ResponsetoApp($retcode, $msg_body) { global $req_token; // 授权码 global $au_token; // 动态码 global $req_version; // 版本号 global $req_bkenv; // 银联环境 global $req_time; global $api_name; global $api_name_func; global $reqcontext; global $authorid; global $authortruename; global $g_sdcrid; $arr_retmsg = array('0' => '成功', '500' => '执行代码错误', '600' => '客户端调用错误', '700' => '数据库出错', '900' => '引用延迟', '800' => '银行卡交易代码请求错误,请填写正确的银行卡信息', '400' => '商户权限不足', '300' => '停留时间太长,请重新登录!', '404' => '请求功能不存在', '505' => '用户信息已被异地篡改,请重新登录', '200' => '自定义错误', '100' => '商户权限不足'); if ($retcode != '200' && $retcode != '0' && $retcode != '300') { $retmsg = $arr_retmsg[$retcode]; } else { if ($retcode != '700' or $retcode != '800') { $retmsg = $msg_body['msgbody']['message']; } } if ($g_sdcrid >= '100') { $req_bkenv = '01'; //测试环境 } else { $req_bkenv = '00'; //正式环境 } $msg_header = array('msgheader' => array('au_token' => $au_token, 'req_token' => $req_token, 'req_bkenv' => $req_bkenv, 'retinfo' => array('rettype' => $retcode, 'retcode' => $retcode, 'retmsg' => $retmsg))); $Responsecontext['operation_response'] = array_merge($msg_header, $msg_body); $rqvalue = xml_encode($Responsecontext, 'utf-8'); //$returnval =""; $reqcry = TfbAuthRequest::getReqDatatype($reqcontext); //请求的数据流 $TfbAuthRequest = new TfbAuthRequest(); if ($reqcry == 'E') { $returnval = $TfbAuthRequest->desEncryptStr($rqvalue); } else { $returnval = $rqvalue; } $authorid = $authorid + 0; $file = "../../" . CONST_LOGDIR . "/" . date('md') . "-" . $authortruename . "log" . ".txt"; $filehandle = fopen($file, "a"); fwrite($filehandle, "\r\n======响应内容:\r\n" . $rqvalue . "\r\n\r\n" . $returnval . "\r\n\r\n<!--------------结束------------>\r\n\r\n\r\n"); fclose($filehandle); return $returnval; }
function test_servicio_eco() { $mensaje = xml_encode("Holá Mundo"); $payload = <<<XML <ns1:eco xmlns:ns1="http://siu.edu.ar/toba_referencia/serv_pruebas"> \t<texto>{$mensaje}</texto> </ns1:eco> XML; $opciones = array('to' => 'http://localhost/' . toba_recurso::url_proyecto($this->get_proyecto()) . '/servicios.php/serv_sin_seguridad'); $servicio = toba::servicio_web('cli_sin_seguridad', $opciones); $mensaje = $servicio->request(new toba_servicio_web_mensaje($payload)); $xml = new SimpleXMLElement($mensaje->get_payload()); $this->AssertEqual(xml_decode((string) $xml->texto), "Respuesta: Holá Mundo"); }
function _parseWidgets() { $widget_path = LIB_PATH . 'Widgets/'; $dirs = glob($widget_path . '*', GLOB_ONLYDIR); if ($dirs) { $xml = array(); foreach ($dirs as $key => $row) { $info_file = $row . '/info.php'; if (file_exists($info_file)) { $xml[basename($row)]['info'] = (include $info_file); } } file_put_contents($widget_path . 'widgets.xml', xml_encode($xml)); return $xml; } }
/** * 服务器响应 * * @param integer $errno 错误码 * @param string $errmsg 提示信息 * @param mixed $data 数据 * @param string $type 格式类型 (json,xml) * @return int */ public static function response($errno = 0, $errmsg = 'ok', $data = null, $type = 'json') { $res = array("errno" => $errno, 'errmsg' => $errmsg); $data = array_merge($res, array('data' => $data)); switch ($type) { case 'xml': echo xml_encode($data, 'root'); break; case 'json': echo json_encode($data); break; default: exit("Invalid format type."); break; } return $errno; }
/** * Ajax方式返回数据到客户端 * @access protected * @param mixed $data 要返回的数据 * @param String $type AJAX返回数据格式 * @return void */ protected function ajaxReturn($data, $type = '') { if (func_num_args() > 2) { // 兼容3.0之前用法 $args = func_get_args(); array_shift($args); $info = array(); $info['data'] = $data; $info['info'] = array_shift($args); $info['status'] = array_shift($args); $data = $info; $type = $args ? array_shift($args) : ''; } //返回格式 $return = array("referer" => $data['url'] ? $data['url'] : "", "state" => $data['status'] ? "success" : "fail", "info" => $data['info'], "status" => $data['status'], "data" => $data['data']); if (empty($type)) { $type = C('DEFAULT_AJAX_RETURN'); } switch (strtoupper($type)) { case 'JSON': // 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:application/json; charset=utf-8'); exit(json_encode($return)); case 'XML': // 返回xml格式数据 header('Content-Type:text/xml; charset=utf-8'); exit(xml_encode($return)); case 'JSONP': // 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:application/json; charset=utf-8'); $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER'); exit($handler . '(' . json_encode($return) . ');'); case 'EVAL': // 返回可执行的js脚本 header('Content-Type:text/html; charset=utf-8'); exit($return); case 'AJAX_UPLOAD': // 返回JSON数据格式到客户端 包含状态信息 header('Content-Type:text/html; charset=utf-8'); exit(json_encode($return)); default: // 用于扩展其他返回格式数据 tag('ajax_return', $return); } }
function xml_encode($name, $content = '', $indent = '') { // Check for entity name validity if (empty($content)) { return $indent . "<{$name}/>\n"; } else { if (is_array($content)) { $ent_block = $indent . "<{$name}>\n"; foreach ($content as $k => $v) { $ent_block .= xml_encode($k, $v, $indent . "\t"); } $ent_block .= $indent . "</{$name}>\n"; return $ent_block; } else { return $indent . "<{$name}>" . htmlspecialchars($content, ENT_QUOTES) . "</{$name}>\n"; } } }
public function run($types, $virtual_path) { $result = array(); if ($this->setting_list['caching'] && $this->get_cache_handler != NULL && ($result = $this->get_cache_handler->__invoke(base64_encode(serialize($_REQUEST)), $this->setting_list['cache_time']))) { } else { $types = explode(',', strtoupper($types)); foreach ($types as $type) { if (isset($this->list[$type])) { foreach ($this->list[$type] as $path => $callback) { if (preg_match("#^" . $path . "\$#simU", $virtual_path, $x1)) { if (is_callable($callback)) { //header($type . " 200 OK"); if (phpversion() >= 5.3) { $result = $callback($x1); } else { call_user_func_array($callback, array($x1)); } } } } } } if (!$result) { //header($type . " 404 Not Found"); $result = "-1"; } if ($this->set_cache_handler) { $this->set_cache_handler->__invoke(base64_encode(serialize($_REQUEST)), $result); } } if ($this->format == "XML") { header("Content-Type: text/xml"); echo xml_encode($result, "response"); } else { if ($this->format == "JSON") { header("Content-Type: text/plain"); if (isset($_GET['callback'])) { echo $_GET['callback'] . '(' . json_encode($result) . ');'; } else { echo json_encode($result); } } } }
/** * ajax返回 * Enter description here ... * @param unknown_type $data * @param unknown_type $info * @param unknown_type $type */ public function ajaxReturn($data = array(), $status, $type = "xml") { if (array_key_exists("title", $data)) { $datas["title"] = $data["title"]; } if (array_key_exists("message", $data)) { $datas["message"] = $data["message"]; } $datas["status"] = $status; if ($type == "json") { //输出json header("Content-Type:text/html; charset=utf-8"); exit(json_encode($datas)); } elseif ($type == "xml") { //输出xml header("Content-Type:text/xml; charset=utf-8"); exit(xml_encode($datas)); } }
public function mtReturn($status, $info, $navTabId = '', $callbackType = 'closeCurrent', $forwardUrl = '', $rel = '', $type = '') { // 保证AJAX返回后也能保存日志 $result = array(); if ($navTabId == '') { $navTabId = $_REQUEST['navTabId']; } if ($status == '200') { $this->sysLogs('', $info); } if ($status == '201') { $status = 200; } $result['statusCode'] = $status; // dwzjs $result['navTabId'] = $navTabId; // dwzjs $result['callbackType'] = $callbackType; // dwzjs $result['message'] = $info; // dwzjs $result['forwardUrl'] = $forwardUrl; $result['rel'] = $rel; if (empty($type)) { $type = C('DEFAULT_AJAX_RETURN'); } if (strtoupper($type) == 'JSON') { // 返回JSON数据格式到客户端 包含状态信息 header("Content-Type:text/html; charset=utf-8"); exit(json_encode($result)); } elseif (strtoupper($type) == 'XML') { // 返回xml格式数据 header("Content-Type:text/xml; charset=utf-8"); exit(xml_encode($result)); } elseif (strtoupper($type) == 'EVAL') { // 返回可执行的js脚本 header("Content-Type:text/html; charset=utf-8"); exit($data); } else { // TODO 增加其它格式 } }
protected function mtReturn($status, $info, $navTabId = "", $closeCurrent = true) { // 写入日志 // $udata['id']=session('uid'); $udata['update_time'] = time(); $Rs = M("user")->save($udata); // $dat['username'] = session('username'); $dat['content'] = $info; $dat['os'] = $_SERVER['HTTP_USER_AGENT']; $dat['url'] = U(); $dat['addtime'] = date("Y-m-d H:i:s", time()); $dat['ip'] = get_client_ip(); M("log")->add($dat); // 回调 $result = array(); $result['statusCode'] = $status; $result['message'] = $info; $result['tabid'] = strtolower($navTabId) . '/index'; $result['forward'] = ''; $result['forwardConfirm'] = ''; $result['closeCurrent'] = $closeCurrent; if (empty($type)) { $type = C('DEFAULT_AJAX_RETURN'); // var_dump($type); } if (strtoupper($type) == 'JSON') { // 返回JSON数据格式到客户端 包含状态信息 header("Content-Type:text/html; charset=utf-8"); exit(json_encode($result)); } elseif (strtoupper($type) == 'XML') { // 返回xml格式数据 header("Content-Type:text/xml; charset=utf-8"); exit(xml_encode($result)); } elseif (strtoupper($type) == 'EVAL') { // 返回可执行的js脚本 header("Content-Type:text/html; charset=utf-8"); exit($data); } else { // TODO 增加其它格式 } }
/** * 编码数据 * @access protected * @param mixed $data 要返回的数据 * @param String $type 返回类型 JSON XML * @return string */ protected function encodeData($data, $type = '') { if ('json' == $type) { // 返回JSON数据格式到客户端 包含状态信息 $data = json_encode($data); if (I('get.jsonpcallback')) { $data = I('get.jsonpcallback') . '(' . $data . ')'; } if (I('get.fileiframetransport', '')) { $data = I('get.jsonpcallback') . '<textarea data-type="application/json">' . "\n" . $data . "\n" . '</textarea>'; } } elseif ('xml' == $type) { // 返回xml格式数据 $data = xml_encode($data); // }elseif('php'==$type){ // $data = serialize($data); } // 默认直接输出 $this->setContentType($type); //header('Content-Length: ' . strlen($data)); return $data; }
/** * Encode xml output. * * @param mixed $mixed * @param DOMDocument $domElement * @param DOMDocument $domDocument * * @see http://darklaunch.com/2009/05/23/php-xml-encode-using-domdocument-convert-array-to-xml-json-encode * * @return string */ function xml_encode($mixed, $domElement = null, $domDocument = null) { if (is_null($domDocument)) { $domDocument = new DOMDocument(); $domDocument->formatOutput = true; xml_encode($mixed, $domDocument, $domDocument); return $domDocument->saveXML(); } else { if (is_object($mixed)) { $mixed = get_object_vars($mixed); } if (is_array($mixed)) { foreach ($mixed as $index => $mixedElement) { if (is_int($index)) { if ($index === 0) { $node = $domElement; } else { $node = $domDocument->createElement($domElement->tagName); $domElement->parentNode->appendChild($node); } } else { $plural = $domDocument->createElement($index); $domElement->appendChild($plural); $node = $plural; if (rtrim($index, 's') !== $index && count($mixedElement) > 1) { $singular = $domDocument->createElement(rtrim($index, 's')); $plural->appendChild($singular); $node = $singular; } } xml_encode($mixedElement, $node, $domDocument); } } else { $mixed = is_bool($mixed) ? $mixed ? 'true' : 'false' : $mixed; $domElement->appendChild($domDocument->createTextNode($mixed)); } } }
public function format($parameter, $format = 'json') { $flag = $this->input->get_post("flag", TRUE); if ($flag !== FALSE) { $parameter['flag'] = $flag; } if ($format == 'json') { return json_encode($parameter); } elseif ($format == 'text') { $ret = ''; foreach ($parameter as $key => $value) { if (is_array($parameter)) { $ret .= $this->format($parameter, $format); } else { $ret .= "&{$key}={$value}"; } } return $ret; } elseif ($format == 'xml') { $this->load->helper('xml'); return xml_encode($parameter); } }
protected function apiReturn($success, $error_code = 0, $message = null, $redirect = null, $extra = null) { //生成返回信息 $result = array(); $result['success'] = $success; $result['error_code'] = $error_code; if ($message !== null) { $result['message'] = $message; } if ($redirect !== null) { $result['redirect'] = $redirect; } foreach ($extra as $key => $value) { $result[$key] = $value; } //将返回信息进行编码 $format = $_REQUEST['format'] ? $_REQUEST['format'] : 'json'; //返回值格式,默认json if ($this->isInternalCall) { throw new ReturnException($result); } else { if ($format == 'json') { $this->response($result, 'json'); //echo json_encode($result); exit; } else { if ($format == 'xml') { echo xml_encode($result); exit; } else { $_GET['format'] = 'json'; $_REQUEST['format'] = 'json'; return $this->apiError(400, "format参数错误"); } } } }
public function ajaxReturn($data, $type = '') { if (empty($type)) { $type = C("DEFAULT_AJAX_RETURN"); } switch ($type) { case 'JSON': header('Content-Type:application/json; charset=utf-8'); exit(json_encode($data)); break; case 'XML': header('Content-Type:text/xml; charset=utf-8'); exit(xml_encode($data)); break; case "JSONP": header("Content-Type:application/json; charset=utf-8"); $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER'); exit($handler . '(' . json_encode($data) . ');'); break; case "EVAL": exit($data); break; } }
protected function returnResult($data, $type = '') { if ($type) { if (is_callable($type)) { return call_user_func($type, $data); } switch (strtolower($type)) { case 'json': return json_encode($data); case 'xml': return xml_encode($data); } } return $data; }
/** * 编码数据 * @access protected * @param mixed $data 要返回的数据 * @param String $type 返回类型 JSON XML * @return string */ protected function encodeData($data, $type = '') { if (empty($data)) { return ''; } if ('json' == $type) { // 返回JSON数据格式到客户端 包含状态信息 $data = json_encode($data); } elseif ('xml' == $type) { // 返回xml格式数据 $data = xml_encode($data); } elseif ('php' == $type) { $data = serialize($data); } // 默认直接输出 $this->setContentType($type); //header('Content-Length: ' . strlen($data)); return $data; }
protected function dwzajaxReturn($data, $type = '') { $udata['id'] = session('uid'); setcookie("uid", session('uid')); $udata['update_time'] = date("Y-m-d H:i:s", time()); $Rs = M("user")->save($udata); //echo M("user")->getLastSql(); $dat['username'] = session('uid'); $dat['content'] = $data['message']; $dat['os'] = $_SERVER['HTTP_USER_AGENT']; $dat['url'] = U(); $dat['addtime'] = date("Y-m-d H:i:s", time()); $dat['ip'] = get_client_ip(); M("log")->add($dat); $result = array(); $result['statusCode'] = $data['statusCode']; $result['tabid'] = $data['tabid']; $result['dialogid'] = $data['dialogid']; $result['closeCurrent'] = $data['closeCurrent']; $result['message'] = $data['message']; $result['forward'] = $data['forward']; $result['forwardConfirm'] = $data['forwardConfirm']; $result['divid'] = $data['divid']; //var_dump($_COOKIE); if (empty($type)) { $type = C('DEFAULT_AJAX_RETURN'); } if (strtoupper($type) == 'JSON') { // 返回JSON数据格式到客户端 包含状态信息 header("Content-Type:text/html; charset=utf-8"); exit(json_encode($result)); } elseif (strtoupper($type) == 'XML') { // 返回xml格式数据 header("Content-Type:text/xml; charset=utf-8"); exit(xml_encode($result)); } elseif (strtoupper($type) == 'EVAL') { // 返回可执行的js脚本 header("Content-Type:text/html; charset=utf-8"); exit($data); } else { // TODO 增加其它格式 } }
/** +---------------------------------------------------------- * Ajax方式返回数据到客户端 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $data 要返回的数据 * @param String $info 提示信息 * @param boolean $status 返回状态 * @param String $status ajax返回类型 JSON XML +---------------------------------------------------------- * @return void +---------------------------------------------------------- */ protected function ajaxReturn($data, $info = '', $status = 1, $type = '') { // 保证AJAX返回后也能保存日志 //if(C('LOG_RECORD')) Log::save(); $result = array(); $result['status'] = $status; $result['statusCode'] = $status; // zhanghuihua@msn.com $result['navTabId'] = $_REQUEST['navTabId']; // zhanghuihua@msn.com $result['callbackType'] = $_REQUEST['callbackType']; // zhanghuihua@msn.com $result['forwardUrl'] = $_REQUEST['forwardUrl']; // zhanghuihua@msn.com $result['message'] = $info; // zhanghuihua@msn.com $result['info'] = $info; $result['data'] = $data; if (empty($type)) { $type = C('DEFAULT_AJAX_RETURN'); } if (strtoupper($type) == 'JSON') { // 返回JSON数据格式到客户端 包含状态信息 header("Content-Type:text/html; charset=utf-8"); exit(json_encode($result)); } elseif (strtoupper($type) == 'XML') { // 返回xml格式数据 header("Content-Type:text/xml; charset=utf-8"); exit(xml_encode($result)); } elseif (strtoupper($type) == 'EVAL') { // 返回可执行的js脚本 header("Content-Type:text/html; charset=utf-8"); exit($data); } else { // TODO 增加其它格式 } }
/** * Responde exactamente con la misma cadena enviada * @param string $texto texto a repetir * @return string $texto texto repetido */ function op__test(toba_servicio_web_mensaje $mensaje) { $xml = new SimpleXMLElement($mensaje->get_payload()); $texto = xml_encode(xml_decode($xml->texto)); $dependencia = xml_encode($this->get_id_cliente('dependencia')); $payload = <<<XML <ns1:test xmlns:ns1="http://siu.edu.ar/toba_referencia/pruebas"> \t<texto>Texto: {$texto} \tDependencia: {$dependencia}</texto> </ns1:test> XML; return new toba_servicio_web_mensaje($payload); }