Exemple #1
0
/**
 * @param array $data
 * @param SimpleXMLElement $xml
 * @return SimpleXMLElement
 */
function array2xml(array $data, SimpleXMLElement $xml)
{
    foreach ($data as $k => $v) {
        is_array($v) ? array2xml($v, $xml->addChild($k)) : $xml->addChild($k, $v);
    }
    return $xml;
}
Exemple #2
0
 /**
  * 下单
  */
 function order($order, $orderdetail)
 {
     $goods = array();
     $good = array();
     foreach ($orderdetail as $product) {
         $good['code'] = $product['sku'];
         $good['name'] = $product['productname'];
         $good['unit'] = '个';
         $good['model'] = $product['sku'];
         $good['brand'] = $product['brand'];
         $good['unitPrice'] = $product['unitprice'];
         $good['sourceArea'] = $product['origin'];
         $good['count'] = $product['num'];
         $good['currencyType'] = 'CNY';
     }
     $goods['@attributes'] = $good;
     $xmlArray = array('@attributes' => array('service' => 'OrderService', 'lang' => 'zh_cn', 'printType' => $this->_system->get('printtype', 'shippment')), 'Head' => "sdafssadfsa", 'Body' => array("Order" => array('@attributes' => array('orderSourceSystem' => '3', 'businessLogo' => $this->_system->get('sendername', 'system'), 'customerOrderNo' => $order['orderno'], 'expressType' => '全球顺', 'payType' => '寄方付', 'recCompany' => $order['consignee'], 'recConcact' => $order['consignee'], 'recTelphone' => $order['consigneetel'], 'recMobile' => $order['consigneetel'], 'recCountry' => '中国', 'recProvinoce' => $order['consigneeprovince'], 'recCityCode' => 'CN', 'recCity' => $order['consigneecity'], 'recCounty' => 'CN', 'recZipcode' => $order['zipcode'], 'recAddress' => $order['consigneeaddress'], 'freight' => $order['feeamount'], 'freightCurrency' => 'CNY'), 'Goods' => $goods)));
     print_r($xmlArray);
     $xml = array2xml($xmlArray, "Request");
     // 生成XML
     //echo $xml;
     $arr = array("verifyCode" => '3DE97718-A922-4B74-97AF-9BD2561DF845', 'Servicefun' => 'issuedOrder', 'server' => 'http://cbtitest.sfb2c.com:8003/CBTA/ws/orderService?wsdl', 'authtoken' => 'CD6A98CF20C3C79D2A7F5C789B5F25C1', 'headerNamespace' => 'http://cbtitest.sfb2c.com:8003/CBTA/');
     $Api = new orderService();
     $response = $Api->getOrderData($xml, $arr);
     return $response;
 }
function array2xml($array, $name = 'array', $standalone = TRUE, $beginning = TRUE)
{
    global $nested;
    if ($beginning) {
        if ($standalone) {
            header("content-type:text/xml;charset=utf-8");
        }
        $output .= '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>';
        $output .= '<' . $name . '>';
        $nested = 0;
    }
    // This is required because XML standards do not allow a tag to start with a number or symbol, you can change this value to whatever you like:
    $ArrayNumberPrefix = 'ARRAY_NUMBER_';
    foreach ($array as $root => $child) {
        if (is_array($child)) {
            $output .= str_repeat(" ", 2 * $nested) . '  <' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>';
            $nested++;
            $output .= array2xml($child, NULL, NULL, FALSE);
            $nested--;
            $output .= str_repeat(" ", 2 * $nested) . '  </' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>';
        } else {
            $output .= str_repeat(" ", 2 * $nested) . '  <' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '><![CDATA[' . $child . ']]></' . (is_string($root) ? $root : $ArrayNumberPrefix . $root) . '>';
        }
    }
    if ($beginning) {
        $output .= '</' . $name . '>';
    }
    return $output;
}
Exemple #4
0
/**
 * Convert array to XML format
 *
 * @param $arr    array with data
 * @param $tag    main tag <main tag>XML data</main tag>
 * @return XML presentation of data
 */
function array2xml($arr, $tag = false)
{
    $res = '';
    foreach ($arr as $k => $v) {
        if (is_array($v)) {
            if (!is_numeric($k) && trim($k)) {
                $res .= count($v) ? '<' . $k . '>' . array2xml($v) . '</' . $k . '>' : '<' . $k . '/>';
            } elseif ($tag) {
                $res .= '<' . $tag . '>' . array2xml($v) . '</' . $tag . '>';
            } else {
                $res .= array2xml($v);
            }
        } else {
            if (!is_numeric($k) && trim($k)) {
                $res .= strlen(trim($v)) ? '<' . $k . '>' . $v . '</' . $k . '>' : '<' . $k . '/>';
            } elseif ($tag) {
                $res .= '<' . $tag . '>' . $v . '</' . $tag . '>';
            } else {
                echo 'Error: array without tag';
                exit;
            }
        }
    }
    return $res;
}
 function outputvariables()
 {
     global $_G;
     $variables = array();
     foreach ($this->params as $param) {
         if (substr($param, 0, 1) == '$') {
             if ($param == '$_G') {
                 continue;
             }
             $var = substr($param, 1);
             if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*\$/", $var)) {
                 $variables[$param] = $GLOBALS[$var];
             }
         } else {
             if (preg_replace($this->safevariables, '', $param) !== $param) {
                 continue;
             }
             $variables[$param] = getglobal($param);
         }
     }
     $xml = array('Version' => $this->version, 'Charset' => strtoupper($_G['charset']), 'Variables' => $variables);
     if (!empty($_G['messageparam'])) {
         $xml['Message'] = $_G['messageparam'];
     }
     require_once libfile('class/xml');
     echo array2xml($xml);
     exit;
 }
function array2xml($data, $rootNodeName = 'data', $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 ($xml == null) {
        /** @var \SimpleXMLElement $xml */
        $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 = "unknownNode_" . (string) $key;
        }
        // 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.
            array2xml($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();
}
Exemple #7
0
/**
 * 将数组转换为xml,发送消息到微信
 *
 * @params array $data 发送消息结构数组
 */
function send($data = '')
{
    if (!empty($data)) {
        $xml = array2xml($data, 'xml');
    } else {
        $xml = '';
    }
    echo $xml;
}
Exemple #8
0
function api($core, $app, $func, $type, $id)
{
    $apps = array('wm' => array('flows', 'offers', 'pub', 'land', 'sites', 'stats', 'lead', 'sources', 'add', 'edit', 'del'), 'sale' => array('list', 'view', 'edit'));
    $na = array('wm-pub', 'wm-land');
    $app = $core->text->link($app);
    $func = $core->text->link($func);
    $type = $core->text->link($type);
    if ($id) {
        $ids = explode('-', $id, 2);
        $id = (int) $ids[0];
        $key = $core->text->link($ids[1]);
    } else {
        $id = $key = false;
    }
    if (in_array($func, $apps[$app])) {
        if ($id) {
            $uk = $core->user->get($id, 'user_api');
            if ($uk != $key) {
                $ck = hash_hmac('sha1', http_build_query($core->post), $uk);
                $auth = $ck == $key ? 1 : 0;
            } else {
                $auth = 1;
            }
        } else {
            $auth = in_array("{$app}-{$func}", $na) ? 1 : 0;
        }
        if ($auth) {
            $fname = 'api_' . $app . '_' . $func;
            if (function_exists($fname)) {
                $result = $fname($core, $id);
            } else {
                $result = array('status' => 'error', 'error' => 'func');
            }
        } else {
            $result = array('status' => 'error', 'error' => 'key');
        }
    } else {
        $result = array('status' => 'error', 'error' => 'app');
    }
    switch ($type) {
        case 'text':
            echo http_build_query($result);
            break;
        case 'raw':
            echo $result;
            break;
        case 'xml':
            echo array2xml($result, $func);
            break;
        case 'json':
            echo defined('JSON_UNESCAPED_UNICODE') ? json_encode($result, JSON_UNESCAPED_UNICODE) : json_encode($result);
            break;
        default:
            echo serialize($result);
    }
}
function cl_camara_division2xml_xml($division_id, $original_html = false)
{
    $out = array();
    $division = cl_camara_division2array($division_id);
    $out = $division;
    if (!$original_html) {
        unset($out['original_html']);
    }
    $xml = array2xml($out, 'votainteligente.cl', true);
    return $xml;
}
Exemple #10
0
 public function render($buffer = false)
 {
     // Build Element Structure
     $this->build_element_structure($this->table_elements['header'], $this->table_data['elements']['header']);
     $this->build_element_structure($this->table_elements['body'], $this->table_data['elements']['body']);
     $this->build_element_structure($this->table_elements['footer'], $this->table_data['elements']['footer']);
     // Convert Table Data to XML
     $this->inset_val = array2xml('table_data', $this->table_data);
     // Render Table Element
     parent::render($buffer);
 }
Exemple #11
0
/**
 * 数组转为xML
 * @param $var 数组
 * @param $type xml的根节点
 * @param $tag
 * 返回xml格式
 */
function array2xml($var, $type = 'root', $tag = '')
{
    $ret = '';
    if (!is_int($type)) {
        if ($tag) {
            return array2xml(array($tag => $var), 0, $type);
        } else {
            $tag .= $type;
            $type = 0;
        }
    }
    $level = $type;
    $indent = str_repeat("\t", $level);
    if (!is_array($var)) {
        $ret .= $indent . '<' . $tag;
        $var = strval($var);
        if ($var == '') {
            $ret .= ' />';
        } else {
            if (!preg_match('/[^0-9a-zA-Z@\\._:\\/-]/', $var)) {
                $ret .= '>' . $var . '</' . $tag . '>';
            } else {
                $ret .= "><![CDATA[{$var}]]></{$tag}>";
            }
        }
        $ret .= "\n";
    } else {
        if (!(is_array($var) && count($var) && array_keys($var) !== range(0, sizeof($var) - 1)) && !empty($var)) {
            foreach ($var as $tmp) {
                $ret .= array2xml($tmp, $level, $tag);
            }
        } else {
            $ret .= $indent . '<' . $tag;
            if ($level == 0) {
                $ret .= '';
            }
            if (isset($var['@attributes'])) {
                foreach ($var['@attributes'] as $k => $v) {
                    if (!is_array($v)) {
                        $ret .= sprintf(' %s="%s"', $k, $v);
                    }
                }
                unset($var['@attributes']);
            }
            $ret .= ">\n";
            foreach ($var as $key => $val) {
                $ret .= array2xml($val, $level + 1, $key);
            }
            $ret .= "{$indent}</{$tag}>\n";
        }
    }
    return $ret;
}
Exemple #12
0
function array2xml($arr, $htmlon = TRUE, $isnormal = FALSE, $level = 1) {
	$s = $level == 1 ? "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<root>\r\n" : '';
	$space = str_repeat("\t", $level);
	foreach($arr as $k => $v) {
		if(!is_array($v)) {
			$s .= $space."<item id=\"$k\">".($htmlon ? '<![CDATA[' : '').$v.($htmlon ? ']]>' : '')."</item>\r\n";
		} else {
			$s .= $space."<item id=\"$k\">\r\n".array2xml($v, $htmlon, $isnormal, $level + 1).$space."</item>\r\n";
		}
	}
	$s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
	return $level == 1 ? $s."</root>" : $s;
}
Exemple #13
0
function array2xml($arr, $htmlon = TRUE, $isnormal = FALSE, $level = 1, $encodeing = 'ISO-8859-1')
{
    $s = $level == 1 ? "<?xml version=\"1.0\" encoding=\"" . $encodeing . "\"?>\r\n<root>\r\n" : '';
    $space = str_repeat("\t", $level);
    foreach ($arr as $k => $v) {
        if (!is_array($v)) {
            $s .= $space . "<item id=\"{$k}\">" . ($htmlon ? '<![CDATA[' : '') . $v . ($htmlon ? ']]>' : '') . "</item>\r\n";
        } else {
            $s .= $space . "<item id=\"{$k}\">\r\n" . array2xml($v, $htmlon, $isnormal, $level + 1, $encodeing) . $space . "</item>\r\n";
        }
    }
    $s = preg_replace("/([-\v-\f-])+/", ' ', $s);
    return $level == 1 ? $s . "</root>" : $s;
}
Exemple #14
0
 /**
  *  同步返回的消息
  */
 public function packageData($postData, $paramsData)
 {
     //LogUtil::logs(" index.php send_msg =====> ".$postData, getLogFile('/business.log'));
     $data = array();
     if (!empty($paramsData)) {
         $commData['ToUserName'] = $postData['FromUserName'];
         $commData['FromUserName'] = $postData['ToUserName'];
         $commData['CreateTime'] = time();
         $data = array_merge($commData, $paramsData);
     }
     //LogUtil::logs(" index.php send_msg =====> ".$data, getLogFile('/business.log'));
     if (!empty($data)) {
         $xml = array2xml($data, 'xml');
     } else {
         $xml = '';
     }
     return $xml;
 }
Exemple #15
0
function array2xml($data, $root = 'data', $xml = null)
{
    if ($xml == null) {
        $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$root}/>");
    }
    foreach ($data as $key => $value) {
        if (is_array($value)) {
            if (is_int($key)) {
                $key = 'item';
            }
            $node = $xml->addChild($key);
            array2xml($value, $root, $node);
        } else {
            $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
            $xml->addChild($key, $value);
        }
    }
    return $xml->asXML();
}
Exemple #16
0
/**
 * 
 * @param unknown $root
 * @param unknown $array
 * @param number $level
 * @return string
 */
function array2xml($root, $array, $level = 0)
{
    if (is_integer($root)) {
        $root = "entry";
    }
    if (!$level) {
        $xml = "<?xml version='1.0' encoding='utf-8'?><{$root}>";
    } else {
        $xml = "<{$root}>";
    }
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            $xml .= array2xml($key, $value, $level + 1);
        } else {
            $xml .= "<{$key}>" . modify($value) . "</{$key}>";
        }
    }
    $xml .= "</{$root}>";
    return $xml;
}
Exemple #17
0
function array2xml($array, $xml = FALSE, $parent = '')
{
    if ($xml === FALSE) {
        $xml = new SimpleXMLElement('<root/>');
    }
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            if (!is_numeric($key) && is_numeric(key($value))) {
                array2xml($value, $xml, $key);
            } elseif (is_numeric($key)) {
                array2xml($value, $xml->addChild($parent));
            } else {
                array2xml($value, $xml->addChild($key));
            }
        } else {
            $xml->addChild($key, $value);
        }
    }
    return $xml->asXML();
}
Exemple #18
0
function array2xml($array, $level = 0)
{
    $return = '';
    if ($level == 0) {
        $return = '<?xml version="1.0" encoding="utf-8" ?><root>';
    }
    foreach ($array as $key => $item) {
        if (!is_array($item)) {
            $return .= "<item key='{$key}'>{$item}</item>";
        } else {
            $return .= "<item key='{$key}'>";
            $return .= array2xml($item, $level + 1);
            $return .= "</item>";
        }
    }
    if ($level == 0) {
        $return .= '</root>';
    }
    return $return;
}
Exemple #19
0
function getpagelink($city, $page, $updatetype = false)
{
    global $_G;
    require_once libfile('class/xml');
    $goodsxmlfile = MOKUAI_DIR . '/shop/1.0/Data/lashou_' . $city . '.xml';
    $goodss = xml2array(file_get_contents($goodsxmlfile));
    $goodslist_text = file_get_contents('http://' . $city . '.lashou.com/page' . $page);
    $ga0 = explode('<div class="content-list">', $goodslist_text);
    $ga1 = explode('<!-- main end -->', $ga0[1]);
    $ga2 = explode('<div class="com-img">', $ga1[0]);
    foreach ($ga2 as $k => $v) {
        $ga3 = explode('.lashou.com/deal/', $v);
        $ga4 = explode('.html', $ga3[1]);
        if ($ga4[0]) {
            $goodss[$ga4[0]]['oldid'] = $ga4[0];
        }
    }
    file_put_contents($goodsxmlfile, diconv(array2xml($goodss, 1), "UTF-8", $_G['charset'] . "//IGNORE"));
    return $goodss;
}
Exemple #20
0
 /**
  * @abstract Converts an array to XML notation where all indexes are tag elements and values are inserted therein.  
  * String and non-numeric values are wrapped in <![CDATA[value]]>.
  * 
  * @param array $data The array to convert into XML.  Can be multidimensional.
  * @param int $tabDepth Optional.  The number of tabs to prepend before each line (default 0).  This value is managed 
  * by recursivecalls to this function and need not be set (under normal circumstances) by the calling scope.
  * 
  * @return string Returns the formatted XML.
  */
 public static function array2xml($data, $tabDepth = 0)
 {
     $output = '';
     $nl = "\n" . str_repeat("\t", $tabDepth++);
     foreach ($data as $key => $value) {
         $output .= $nl . '<' . $key . ">";
         if (is_bool($value)) {
             $value = (int) $value;
         }
         if (is_array($value)) {
             $output .= array2xml($value, $tabDepth) . $nl;
         } elseif (is_int($value) || is_float($value)) {
             $output .= $value;
         } else {
             $output .= '<![CDATA[' . $value . ']]>';
         }
         $output .= '</' . $key . ">";
     }
     return $output;
 }
Exemple #21
0
function render_result($array, $wrapper = "array", $type = "json")
{
    switch ($type) {
        // XML
        case "xml":
            echo array2xml($array, $wrapper);
            break;
            //JSON
        //JSON
        case "json":
            echo json_encode($array);
            // php internal function, input is array
            break;
            //JSON - human-readable ( only for debug)
        //JSON - human-readable ( only for debug)
        case "json_read":
            echo make_readable(json_encode($array));
            // php internal function, input is array
            break;
            //HTML
        //HTML
        case "html":
            html_show_array($array);
            break;
            //HTML Table
        //HTML Table
        case "html_table":
            html_table_show_array($array);
            break;
            //RAW
        //RAW
        case "raw":
            print_r($array);
            // php internal function, input is array (only for debug)
            break;
    }
}
 public static function array2xml($array, $xml = null)
 {
     if (!isset($xml)) {
         $xml = new SimpleXMLElement('<params/>');
     }
     foreach ($array as $key => $value) {
         if (is_array($value) || is_object($value)) {
             array2xml($value, $xml);
         } else {
             if (is_numeric($key)) {
                 if (is_string($value)) {
                     $xml->addChild('item', htmlentities($value, ENT_NOQUOTES, "UTF-8"));
                 } else {
                     $xml->addChild('item', $value);
                 }
             } elseif (is_string($value)) {
                 $xml->addChild($key, htmlentities($value, ENT_NOQUOTES, "UTF-8"));
             } else {
                 $xml->addChild($key, $value);
             }
         }
     }
     return $xml->asXML();
 }
 public function db_optimize()
 {
     global $DB, $error_ar;
     echo "Archive non billed Orders ...\n";
     $start_time = microtime(1);
     $n = 0;
     if ($file = fopen(iHOMEDIR . 'log/orders.xml', 'a')) {
         /* fwrite($file, '<?xml version="1.0" encoding="utf-8"?><Orders>'); */
         $res = $DB->make_select('Orders', '', '`AccountID` IS NULL AND UNIX_TIMESTAMP(opentime)<=' . (iNOW_UNIX - 2 * iMON));
         while ($data = $DB->row($res)) {
             $n++;
             $data['info'] = unserialize($data['info']);
             $xml_obj = array2xml($data, 'Order');
             fwrite($file, $xml_obj);
         }
         fclose($file);
         $DB->make_delete('Orders', '`AccountID` IS NULL AND UNIX_TIMESTAMP(opentime)<=' . (iNOW_UNIX - 3 * iMON));
     }
     echo "Finished Step. Archive {$n} orders. Time " . intval((microtime(1) - $start_time) * 1000) . "ms.\n\n";
     echo "Archive deleted packages...\n";
     $start_time = microtime(1);
     $n = 0;
     if ($file = fopen(iHOMEDIR . 'log/packages.xml', 'a')) {
         $res = $DB->make_select('Packages', '', "`status`='Deleted'");
         while ($data = $DB->row($res)) {
             if ($DB->count_objs('Accounts', "`PackageID`='{$data['PackageID']}' AND `Status`!='Deleted'") == 0) {
                 $n++;
                 $xml_obj = array2xml($data, 'Package');
                 fwrite($file, $xml_obj);
                 $DB->make_delete('Packages', "`PackageID`='{$data['PackageID']}'");
                 $DB->make_delete('Tarifs', "`PackageID`='{$data['PackageID']}'");
             }
         }
         fclose($file);
     }
     echo "Finished Step. Archive {$n} packages. Time " . intval((microtime(1) - $start_time) * 1000) . "ms.\n\n";
     echo "Change status to Deleted for packages what not in Reseller Tarif table...\n";
     $start_time = microtime(1);
     $n = 0;
     $res = $DB->query_adv('SELECT *,`Packages`.`PackageID` as PackageID FROM `Packages` LEFT OUTER JOIN `Tarifs` ON `Packages`.`PackageID` = `Tarifs`.`PackageID` WHERE `Tarifs`.`PackageID` IS NULL');
     while ($data = $DB->row($res)) {
         $DB->make_update('Packages', "`PackageID`='{$data['PackageID']}'", array('status' => 'Deleted'));
         $n++;
     }
     echo "Finished Step. Change {$n} packages. Time " . intval((microtime(1) - $start_time) * 1000) . "ms.\n\n";
     echo "Optimize Databse ...\n";
     $start_time = microtime(1);
     $DB->query_adv('OPTIMIZE TABLE `Accounts`, `Amount`, `Companys`, `Resellers`, `Domains`, `Pool`, `History`, `Letters`, `Notes`, `Packages`, `Payments`, `Servers`, `Services`, `Statistic`, `Orders`, `Users`, `whmaccts`, `wm_payment`, `WrongOrders`');
     echo "Finished Step. Time " . intval((microtime(1) - $start_time) * 1000) . "ms.\n\n";
 }
Exemple #24
0
function array2xml($arr, $level = 1)
{
    $s = $level == 1 ? "<xml>" : '';
    foreach ($arr as $tagname => $value) {
        if (is_numeric($tagname)) {
            $tagname = $value['TagName'];
            unset($value['TagName']);
        }
        if (!is_array($value)) {
            $s .= "<{$tagname}>" . (!is_numeric($value) ? '<![CDATA[' : '') . $value . (!is_numeric($value) ? ']]>' : '') . "</{$tagname}>";
        } else {
            $s .= "<{$tagname}>" . array2xml($value, $level + 1) . "</{$tagname}>";
        }
    }
    $s = preg_replace("/([-\v-\f-])+/", ' ', $s);
    return $level == 1 ? $s . "</xml>" : $s;
}
Exemple #25
0
function wechat_build($params, $wechat)
{
    global $_W;
    load()->func('communication');
    if (empty($wechat['version']) && !empty($wechat['signkey'])) {
        $wechat['version'] = 1;
    }
    $wOpt = array();
    if ($wechat['version'] == 1) {
        $wOpt['appId'] = $wechat['appid'];
        $wOpt['timeStamp'] = TIMESTAMP;
        $wOpt['nonceStr'] = random(8);
        $package = array();
        $package['bank_type'] = 'WX';
        $package['body'] = $params['title'];
        $package['attach'] = $_W['uniacid'];
        $package['partner'] = $wechat['partner'];
        $package['out_trade_no'] = $params['tid'];
        $package['total_fee'] = $params['fee'] * 100;
        $package['fee_type'] = '1';
        $package['notify_url'] = $_W['siteroot'] . 'payment/wechat/notify.php';
        $package['spbill_create_ip'] = CLIENT_IP;
        $package['time_start'] = date('YmdHis', TIMESTAMP);
        $package['time_expire'] = date('YmdHis', TIMESTAMP + 600);
        $package['input_charset'] = 'UTF-8';
        ksort($package);
        $string1 = '';
        foreach ($package as $key => $v) {
            $string1 .= "{$key}={$v}&";
        }
        $string1 .= "key={$wechat['key']}";
        $sign = strtoupper(md5($string1));
        $string2 = '';
        foreach ($package as $key => $v) {
            $v = urlencode($v);
            $string2 .= "{$key}={$v}&";
        }
        $string2 .= "sign={$sign}";
        $wOpt['package'] = $string2;
        $string = '';
        $keys = array('appId', 'timeStamp', 'nonceStr', 'package', 'appKey');
        sort($keys);
        foreach ($keys as $key) {
            $v = $wOpt[$key];
            if ($key == 'appKey') {
                $v = $wechat['signkey'];
            }
            $key = strtolower($key);
            $string .= "{$key}={$v}&";
        }
        $string = rtrim($string, '&');
        $wOpt['signType'] = 'SHA1';
        $wOpt['paySign'] = sha1($string);
        return $wOpt;
    } else {
        $package = array();
        $package['appid'] = $wechat['appid'];
        $package['mch_id'] = $wechat['mchid'];
        $package['nonce_str'] = random(8);
        $package['body'] = $params['title'];
        $package['attach'] = $_W['uniacid'];
        $package['out_trade_no'] = $params['tid'];
        $package['total_fee'] = $params['fee'] * 100;
        $package['spbill_create_ip'] = CLIENT_IP;
        $package['time_start'] = date('YmdHis', TIMESTAMP);
        $package['time_expire'] = date('YmdHis', TIMESTAMP + 600);
        $package['notify_url'] = $_W['siteroot'] . 'payment/wechat/notify.php';
        $package['trade_type'] = 'JSAPI';
        $package['openid'] = $_W['fans']['from_user'];
        ksort($package, SORT_STRING);
        $string1 = '';
        foreach ($package as $key => $v) {
            $string1 .= "{$key}={$v}&";
        }
        $string1 .= "key={$wechat['signkey']}";
        $package['sign'] = strtoupper(md5($string1));
        $dat = array2xml($package);
        $response = ihttp_request('https://api.mch.weixin.qq.com/pay/unifiedorder', $dat);
        if (is_error($response)) {
            return $response;
        }
        $xml = @simplexml_load_string($response['content'], 'SimpleXMLElement', LIBXML_NOCDATA);
        if (strval($xml->return_code) == 'FAIL') {
            return error(-1, strval($xml->return_msg));
        }
        if (strval($xml->result_code) == 'FAIL') {
            return error(-1, strval($xml->err_code) . ': ' . strval($xml->err_code_des));
        }
        $prepayid = $xml->prepay_id;
        $wOpt['appId'] = $wechat['appid'];
        $wOpt['timeStamp'] = TIMESTAMP;
        $wOpt['nonceStr'] = random(8);
        $wOpt['package'] = 'prepay_id=' . $prepayid;
        $wOpt['signType'] = 'MD5';
        ksort($wOpt, SORT_STRING);
        foreach ($wOpt as $key => $v) {
            $string .= "{$key}={$v}&";
        }
        $string .= "key={$wechat['signkey']}";
        $wOpt['paySign'] = strtoupper(md5($string));
        return $wOpt;
    }
}
function cloudaddons_savemd5($md5file, $end, $md5)
{
    global $_G;
    parse_str($end, $r);
    require_once libfile('class/xml');
    $xml = implode('', @file(DISCUZ_ROOT . './data/addonmd5/' . $md5file . '.xml'));
    $array = xml2array($xml);
    $ridexists = false;
    $data = array();
    if ($array['RevisionID']) {
        foreach (explode(',', $array['RevisionID']) as $i => $rid) {
            $sns = explode(',', $array['SN']);
            $datalines = explode(',', $array['RevisionDateline']);
            $data[$rid]['SN'] = $sns[$i];
            $data[$rid]['RevisionDateline'] = $datalines[$i];
        }
    }
    $data[$r['RevisionID']]['SN'] = $r['SN'];
    $data[$r['RevisionID']]['RevisionDateline'] = $r['RevisionDateline'];
    $array['Title'] = 'Discuz! Addon MD5';
    $array['ID'] = $r['ID'];
    $array['RevisionDateline'] = $array['SN'] = $array['RevisionID'] = array();
    foreach ($data as $rid => $tmp) {
        $array['RevisionID'][] = $rid;
        $array['SN'][] = $tmp['SN'];
        $array['RevisionDateline'][] = $tmp['RevisionDateline'];
    }
    $array['RevisionID'] = implode(',', $array['RevisionID']);
    $array['SN'] = implode(',', $array['SN']);
    $array['RevisionDateline'] = implode(',', $array['RevisionDateline']);
    $array['Data'] = $array['Data'] ? array_merge($array['Data'], $md5) : $md5;
    if (!isset($_G['siteftp'])) {
        dmkdir(DISCUZ_ROOT . './data/addonmd5/', 0777, false);
        $fp = fopen(DISCUZ_ROOT . './data/addonmd5/' . $md5file . '.xml', 'w');
        fwrite($fp, array2xml($array));
        fclose($fp);
    } else {
        $localfile = DISCUZ_ROOT . './data/' . random(5);
        $fp = fopen($localfile, 'w');
        fwrite($fp, array2xml($array));
        fclose($fp);
        dmkdir(DISCUZ_ROOT . './data/addonmd5/', 0777, false);
        siteftp_upload($localfile, 'data/addonmd5/' . $md5file . '.xml');
        @unlink($localfile);
    }
}
 /**
  * The direct way to make an API call. This allows developers to include new API
  * methods that might not yet have a wrapper method as part of the package.
  *
  * @param string $action The API call.
  * @param array $options An associative array of values to send as part of the request.
  * @return array The parsed XML of the request.
  */
 function makeCall($action = '', $options = array())
 {
     // NEW [2008-06-24]: switch to soap automatically for these calls
     $old_method = $this->method;
     if ($action == 'Subscriber.AddWithCustomFields' || $action == 'Subscriber.AddAndResubscribeWithCustomFields' || $action == 'Campaign.Create') {
         $this->method = 'soap';
     }
     if (!$action) {
         return null;
     }
     $url = $this->url;
     // DONE: like facebook's client, allow for get/post through the file wrappers
     // if curl isn't available. (or maybe have curl-emulating functions defined
     // at the bottom of this script.)
     //$ch = curl_init();
     if (!isset($options['header'])) {
         $options['header'] = array();
     }
     $options['header'][] = 'User-Agent: CMBase URL Handler 1.5';
     $postdata = '';
     $method = 'GET';
     if ($this->method == 'soap') {
         $options['header'][] = 'Content-Type: text/xml; charset=utf-8';
         $options['header'][] = 'SOAPAction: "' . $this->soapAction . $action . '"';
         $postdata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
         $postdata .= "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
         $postdata .= " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"";
         $postdata .= " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
         $postdata .= "<soap:Body>\n";
         $postdata .= "\t<{$action} xmlns=\"{$this->soapAction}\">\n";
         $postdata .= "\t\t<ApiKey>{$this->api}</ApiKey>\n";
         if (isset($options['params'])) {
             $postdata .= array2xml($options['params'], "\t\t");
         }
         $postdata .= "\t</{$action}>\n";
         $postdata .= "</soap:Body>\n";
         $postdata .= "</soap:Envelope>";
         $method = 'POST';
         //curl_setopt( $ch, CURLOPT_POST, 1 );
         //curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
     } else {
         $postdata = "ApiKey={$this->api}";
         $url .= "/{$action}";
         // NOTE: since this is GET, the assumption is that params is a set of simple key-value pairs.
         if (isset($options['params'])) {
             foreach ($options['params'] as $k => $v) {
                 $postdata .= '&' . $k . '=' . rawurlencode(utf8_encode($v));
             }
         }
         if ($this->method == 'get') {
             $url .= '?' . $postdata;
             $postdata = '';
         } else {
             $options['header'][] = 'Content-Type: application/x-www-form-urlencoded';
             $method = 'POST';
             //curl_setopt( $ch, CURLOPT_POST, 1 );
             //curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
         }
     }
     $res = '';
     // WARNING: using fopen() does not recognize stream contexts in PHP 4.x, so
     // my guess is using fopen() in PHP 4.x implies that POST is not supported
     // (otherwise, how do you tell fopen() to use POST?). tried fsockopen(), but
     // response time was terrible. if someone has more experience with working
     // directly with streams, please troubleshoot that.
     // NOTE: fsockopen() needs a small timeout to force the socket to close.
     // it's defined in SOCKET_TIMEOUT.
     // preferred method is curl, only if it exists and $this->curl is true.
     if ($this->curl && $this->curlExists) {
         $ch = curl_init();
         if ($this->method != 'get') {
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
         }
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $options['header']);
         curl_setopt($ch, CURLOPT_HEADER, $this->show_response_headers);
         // except for the response, all other information will be stored when debugging is on.
         $res = curl_exec($ch);
         if ($this->debug_level) {
             $this->debug_url = $url;
             $this->debug_request = $postdata;
             $this->debug_info = curl_getinfo($ch);
             $this->debug_info['headers_sent'] = $options['header'];
         }
         $this->debug_response = $res;
         curl_close($ch);
     } else {
         // 'header' is actually the entire HTTP payload. as such, you need
         // Content-Length header, otherwise you'll get errors returned/emitted.
         $postLen = strlen($postdata);
         $ctx = array('method' => $method, 'header' => implode("\n", $options['header']) . "\nContent-Length: " . $postLen . "\n\n" . $postdata);
         if ($this->debug_level) {
             $this->debug_url = $url;
             $this->debug_request = $postdata;
             $this->debug_info['overview'] = 'Used stream_context_create()/fopen() to make request. Content length=' . $postLen;
             $this->debug_info['headers_sent'] = $options['header'];
             //$this->debug_info['complete_content'] = $ctx;
         }
         $pv = PHPVER;
         // the preferred non-cURL way if user is using PHP 5.x
         if ($pv[0] == '5') {
             $context = stream_context_create(array('http' => $ctx));
             $fp = fopen($url, 'r', false, $context);
             ob_start();
             fpassthru($fp);
             fclose($fp);
             $res = ob_get_clean();
         } else {
             // this should work with PHP 4, but it seems to take forever to get data back this way
             // NOTE: setting the default_socket_timeout seems to alleviate this issue [finally].
             list($protocol, $url) = explode('//', $url, 2);
             list($domain, $path) = explode('/', $url, 2);
             $fp = fsockopen($domain, 80, $tvar, $tvar2, SOCKET_TIMEOUT);
             if ($fp) {
                 $payload = "{$method} /{$path} HTTP/1.1\n" . "Host: {$domain}\n" . $ctx['header'];
                 fwrite($fp, $payload);
                 // even with the socket timeout set, using fgets() isn't playing nice, but
                 // fpassthru() seems to be doing the right thing.
                 ob_start();
                 fpassthru($fp);
                 list($headers, $res) = explode("\r\n\r\n", ob_get_clean(), 2);
                 if ($this->debug_level) {
                     $this->debug_info['headers_received'] = $headers;
                 }
                 fclose($fp);
             } elseif ($this->debug_level) {
                 $this->debug_info['overview'] .= "\nOpening {$domain}/{$path} failed!";
             }
         }
     }
     //$this->method = $old_method;
     if ($res) {
         if ($this->method == 'soap') {
             $tmp = xml2array($res, '/soap:Envelope/soap:Body');
             if (!is_array($tmp)) {
                 return $tmp;
             } else {
                 return $tmp[$action . 'Response'][$action . 'Result'];
             }
         } else {
             return xml2array($res);
         }
     } else {
         return null;
     }
 }
Exemple #28
0
function import_diy($importfile, $primaltplname, $targettplname)
{
    global $_G;
    $css = $html = '';
    $arr = array();
    $content = file_get_contents(realpath($importfile));
    if (empty($content)) {
        return $arr;
    }
    require_once DISCUZ_ROOT . './source/class/class_xml.php';
    $diycontent = xml2array($content);
    if ($diycontent) {
        foreach ($diycontent['layoutdata'] as $key => $value) {
            if (!empty($value)) {
                getframeblock($value);
            }
        }
        $newframe = array();
        foreach ($_G['curtplframe'] as $value) {
            $newframe[] = $value['type'] . random(6);
        }
        $mapping = array();
        if (!empty($diycontent['blockdata'])) {
            $mapping = block_import($diycontent['blockdata']);
            unset($diycontent['bockdata']);
        }
        $oldbids = $newbids = array();
        if (!empty($mapping)) {
            foreach ($mapping as $obid => $nbid) {
                $oldbids[] = 'portal_block_' . $obid;
                $newbids[] = 'portal_block_' . $nbid;
            }
        }
        require_once DISCUZ_ROOT . './source/class/class_xml.php';
        $xml = array2xml($diycontent['layoutdata'], true);
        $xml = str_replace($oldbids, $newbids, $xml);
        $xml = str_replace((array) array_keys($_G['curtplframe']), $newframe, $xml);
        $diycontent['layoutdata'] = xml2array($xml);
        $css = str_replace($oldbids, $newbids, $diycontent['spacecss']);
        $css = str_replace((array) array_keys($_G['curtplframe']), $newframe, $css);
        $arr['spacecss'] = $css;
        $arr['layoutdata'] = $diycontent['layoutdata'];
        $arr['style'] = $diycontent['style'];
        save_diy_data($primaltplname, $targettplname, $arr, true);
    }
    return $arr;
}
            }
            $res_ajout = $myCart->pointe_item($item, "EXPL", $form_cb_expl, "EXPL_CB");
            // form de saisie cb exemplaire
            if ($expl_ajout_ok) {
                if ($res_ajout == CADDIE_ITEM_OK) {
                    $param->message_ajout_expl = $msg["caddie_" . $myCart->type . "_pointe"];
                }
                if ($res_ajout == CADDIE_ITEM_NULL) {
                    $param->message_ajout_expl = $msg[caddie_item_null];
                }
                if ($res_ajout == CADDIE_ITEM_IMPOSSIBLE_BULLETIN) {
                    $param->message_ajout_expl = $msg[caddie_pointe_item_impossible_bulletin];
                }
                if ($res_ajout == CADDIE_ITEM_INEXISTANT) {
                    $param->message_ajout_expl = $msg[caddie_pointe_inconnu_panier];
                }
            }
            break;
        default:
            break;
    }
}
$param->nb_item = $myCart->nb_item;
$param->nb_item_pointe = $myCart->nb_item_pointe;
$param->nb_item_base = $myCart->nb_item_base;
$param->nb_item_base_pointe = $myCart->nb_item_base_pointe;
$param->nb_item_blob = $myCart->nb_item_blob;
$param->nb_item_blob_pointe = $myCart->nb_item_blob_pointe;
$array[0] = $param;
$buf_xml = array2xml($array);
ajax_http_send_response("{$buf_xml}", "text/xml");
Exemple #30
0
function array2xml(&$parent, $a)
{
    foreach ($a as $key => $val) {
        if (is_integer($key)) {
            $keystr = "record";
        } else {
            $keystr = $key;
        }
        if (is_object($val)) {
            $el = new DOMElement($keystr);
            $parent->appendChild($el);
            obj2xml($el, $val);
        } elseif (is_array($val)) {
            $el = new DOMElement($keystr);
            $parent->appendChild($el);
            array2xml($el, $val);
        } else {
            $parent->appendChild(new DOMElement($keystr, $val));
        }
    }
}