function getAccount($req, $hash, $apiId, $sign) { $af = new AccountManager(); $db = SystemConfig::GetDatabaseInstance(); $db->Query("SELECT `AccountId` FROM `Authorized` WHERE `Hash`=?", $hash); $accountId = $db->Assoc('AccountId'); $acc = $af->GetAccountById($accountId); if ($acc) { $db->Query("SELECT `Secret` FROM `Apps` WHERE `Id`=?d", $api); $key = $db->Assoc('Secret'); $acc = encrypt(toXml($acc), $key); return api_response(array('Account' => $acc)); } }
public static function format($data, $format = 'json', $formatSetting) { $charset = isset($formatSetting['charset']) ? $formatSetting['charset'] : 'utf8'; if (strtolower($format) == 'json') { header("Content-type: " . Response::JSON . ';charset=utf-8'); return json_encode($data); } elseif (strtolower($format) == 'xml') { header("Content-type: " . Response::XML . ';charset=' . $charset); $xmlSetting = array('root' => 'response', 'charset' => $charset, 'num_key' => 'item', 'version' => '1.0'); $formatSetting = is_array($formatSetting) ? $formatSetting : array(); $xmlSetting = array_merge($xmlSetting, $formatSetting); return toXml($data, $xmlSetting); } else { header("Content-type: " . Response::JAVASCRIPT . ';charset=utf-8'); return $format . '(' . json_encode($data) . ');'; } }
function toXML($data, $rootNodeName = 'api', &$xml = null) { // turn off compatibility mode as simple xml throws a wobbly if you don't. if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if (is_null($xml)) { //$xml = simplexml_load_string( "" ); $xml = simplexml_load_string(xml_default($rootNodeName)); } // loop through the data passed in. foreach ($data as $key => $value) { $key = xml_trim($key); $numeric = false; // no numeric keys in our xml please! if (is_numeric($key)) { $numeric = 1; $key = $rootNodeName; } // delete any char not allowed in XML element names $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { $node = isAssoc($value) || $numeric ? $xml->addChild($key) : $xml; // recrusive call. if ($numeric) { $key = 'anon'; } toXml($value, $key, $node); } else { // var_dump($value); // add single node. $value = htmlentities(xml_trim($value)); $xml->addChild($key, $value); } } // pass back as XML // return $xml->asXML(); // if you want the XML to be formatted, use the below instead to return the XML $doc = new DOMDocument('1.0'); $doc->preserveWhiteSpace = false; $doc->loadXML($xml->asXML()); $doc->formatOutput = true; return $doc->saveXML(); }
function toXml(&$xml, $parentnode, $tag, $data) { if (is_assoc($data)) { $node = $xml->createElement($tag); foreach ($data as $key => $val) { toXml($xml, $node, $key, $val); } } else { if (is_array($data)) { $node = $xml->createElement($tag); foreach ($data as $val) { toXml($xml, $node, 'item', $val); } } else { $node = $xml->createElement($tag, $data); } } $parentnode->appendChild($node); }
$wherePattern = '/\\;|\\-\\-|\\$/i'; // Check WHERE for possible malicious characters if (preg_match($wherePattern, $where)) { // Cancel query if found die('Improper WHERE field <br> <a href="javascript:history.back()">Back</a>' . mysql_error()); } // Pattern of acceptable fields in the SELECT statement //$selectPattern = '/\w(id|date|title|alary|name|mail|number|pct|address|code|ity|province)$/i'; $selectPattern = '/(id|date|\\*|title|alary|name|mail|number|pct|address|code|ity|province)$/i'; // Check SELECT for proper fields if (!preg_match($selectPattern, $select)) { // Cancel query if not authorized input die('Improper SELECT field <br> <a href="javascript:history.back()">Back</a>' . mysql_error()); } // Pattern of acceptable fields in the FROM statement $fromPattern = '/^(job_history|jobs|departments|employees|locations|countries|regions)$/'; // Check FROM for proper fields if (!preg_match($fromPattern, $from)) { // Cancel query if not authorized input die('Improper FROM field <br> <a href="javascript:history.back()">Back</a>' . mysql_error()); } // Pass it to the model $things = sqlQuery($input[0], $input[1], $input[2]); // Convert data from the model to xml $xml = toXml($things); // Output the xml to the view; header('Content-Type: text/xml'); echo $xml;
/** * Function to recursively crawl through the array and create the XML nodes * * @param mixed $data * @param mixed $node * @param mixed $cdata * @param mixed $xml */ function toXml($data, $node, $cdata, &$xml) { foreach ($data as $key => $value) { if (is_array($value)) { if (!is_numeric($key)) { $subNode = $xml->addChild($key); toXml($value, $node, $cdata, $subNode); } else { $subNode = $xml->addChild($node); toXml($value, $node, $cdata, $subNode); } } else { if (strpos($value, '<') !== false || strpos($value, '&') !== false) { $value = $cdata ? '[{pop}]<![CDATA[' . str_replace('&', '&', $value) . ']]>[{/pop}]' : htmlentities($value, ENT_QUOTES, 'UTF-8'); } $xml->addChild($key, $value); } } }
function toXml($data, $rootNodeName = 'channel', $xml = null) { if ($xml == null) { $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />"); } // loop through the data passed in. foreach ($data as $key => $value) { // no numeric keys in our xml please! if (is_numeric($key)) { // make string key... $key = "item"; } // replace anything not alpha numeric $key = preg_replace('/[^a-z]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { $node = $xml->addChild($key); // recrusive call. toXml($value, $rootNodeName, $node); } else { // add single node. $value = htmlentities($value); $xml->addChild($key, $value); } } // pass back as string. or simple xml object if you want! return $xml->asXML(); }
echo $dataArray['return_msg']; exit; } echo $dataJson; exit; } else { echo getOrderStu($inf['stu']); } } if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) { $tmpmsg = array('touser' => $to, 'template_id' => 'oMhzLlRCMJ_vXQKQL9Yx12DsG8fXlIUzcz0qz4kb9SI', 'url' => 'http://www.qq.com', 'data' => array('first' => array('value' => '交易成功'), 'product' => array('value' => '测试商品1'), 'price' => array('value' => '1988.00'), 'time' => array('value' => '1月9日16:00'), 'remark' => array('value' => '欢迎再次选购'))); $error = array('return_code' => 'SUCCESS', 'return_msg' => 'OK'); $responseData = xmlToArray($GLOBALS["HTTP_RAW_POST_DATA"]); // mylog(getArrayInf($responseData)); if ('SUCCESS' == $responseData['return_code']) { if ('SUCCESS' == $responseData['result_code']) { if (signVerify($responseData)) { include_once '../wechat/serveManager.php'; $orderId = $responseData['out_trade_no']; pdoUpdate('order_tbl', array('stu' => "1"), array('id' => $orderId)); $payChkArray = array('first' => array('value' => '您在阿诗顿商城的网购订单已支付成功:'), 'orderno' => array('value' => $orderId, 'color' => '#0000ff'), 'amount' => array('value' => '¥' . $responseData['total_fee'] / 100, 'color' => '#0000ff'), 'remark' => array('value' => '商城即将安排发货,请留意物流通知')); $re = sendTemplateMsg($responseData['openid'], $template_key_order, '', $payChkArray); } else { } } else { } } else { } echo toXml($error); exit; }
/** This method converts an array into a xml stirng @access public @throws Exception object @param array $data | Array to be converted @param string $rootNodeName | String with the xml root node @param string $xml | String with the xml @static @return stirng */ public static function array_to_xml($data, $rootNodeName = 'root', $xml = null) { try { //Desligamos essa opção para evitar bugs if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if ($xml == null) { $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />"); } // faz o loop no array foreach ($data as $key => $value) { // se for indice numerico ele renomeia o indice if (is_numeric($key)) { $key = "unknownNode_" . (string) $key; } // substituir qualquer coisa não alfa númerico $key = preg_replace('/[^a-z]/i', '', $key); if (is_array($value)) { $node = $xml->addChild($key); toXml($value, $rootNodeName, $node); } else { $value = htmlentities($value); $xml->addChild($key, $value); } } return $xml->asXML(); } catch (Exception $e) { throw $e; } }
public function toXml(array $options = array()) { $options = array_flip($options); $options['wiki_page_version'] = 'root'; return toXml(array('id' => $this->{$this}->id, 'created_at' => $this->{$this}->created_at, 'updated_at' => $this->updated_at, 'title' => $this->title, 'body' => $this->body, 'updater_id' => $this->user_id, 'locked' => $this->is_locked, 'version' => $this->version, 'post_id' => $this->post_id), $options); }
function updateCart($xml, $cart, $id, $action) { ////update catalog $xpath = new DOMXPath($xml); // //// We starts from the root element $query = "//items/item[id='" . $id . "']"; $entries = $xpath->query($query); foreach ($entries as $entrie) { $qtyGet = 1; if ($action == "Add") { $qtyGet = 1; } elseif ($action == "Remove") { $qtyGet = -1; } $currentQty = $entrie->getElementsByTagName("quantity")->item(0)->nodeValue; $entrie->getElementsByTagName("quantity")->item(0)->nodeValue = $currentQty - $qtyGet; $currentHoldon = $entrie->getElementsByTagName("holdon")->item(0)->nodeValue; $entrie->getElementsByTagName("holdon")->item(0)->nodeValue = $currentHoldon + $qtyGet; $strXml = $xml->saveXML(); $fileXMLPath = $GLOBALS['fileXMLPath']; $xml->save($fileXMLPath); } echo toXml($cart); }