public function parseDeliveryAddress($xml, $charset) { $doc = NULL; $xmlUtil = new XmlParseUtil(); try { $doc = $xmlUtil->parseDoc($xml, $charset); } catch (Exception $e) { throw new SDKRuntimeException('解析xml失败:' . $xml . ',' . $e); } $deliveryAddressInfo = NULL; $addresss = array(); $root = $doc->documentElement; foreach ($root->childNodes as $node) { if ($node->nodeName == 'addressInfos') { foreach ($node->childNodes as $child) { if ($child->nodeName == 'item') { $node = $child; $deliveryAddressInfo = new DeliveryAddressInfo(); foreach ($node->childNodes as $child) { $value = iconv('UTF-8', $charset, $child->nodeValue); $this->setAddressInfoAttr($deliveryAddressInfo, $child->nodeName, $value); } array_push($addresss, $deliveryAddressInfo); } } } } $this->setDeliveryAddresss($addresss); }
/** * 将xml解析为地址列表 * * @param xml 需要解析的XML * @param charset XML的字符集 */ function parseDeliveryAddress($xml, $charset) { $doc = null; $xmlUtil = new XmlParseUtil(); try { $doc = $xmlUtil->parseDoc($xml, $charset); } catch (Exception $e) { throw new SDKRuntimeException("解析xml失败:" . $xml . "," . $e); } $deliveryAddressInfo = null; $addresss = array(); // 提取地址列表 $root = $doc->documentElement; foreach ($root->childNodes as $node) { if ($node->nodeName == "addressInfos") { foreach ($node->childNodes as $child) { if ($child->nodeName == "item") { $node = $child; $deliveryAddressInfo = new DeliveryAddressInfo(); foreach ($node->childNodes as $child) { $value = iconv("UTF-8", $charset, $child->nodeValue); //注意要转码对于中文,因为XML默认为UTF-8格式 $this->setAddressInfoAttr($deliveryAddressInfo, $child->nodeName, $value); } array_push($addresss, $deliveryAddressInfo); } } } } $this->setDeliveryAddresss($addresss); }
function retXmlHttpCall($opposite_address) { $queryXml = null; $objH = new HttpClientUtil(); try { $queryXml = $objH->httpClientCall($this->getURL($opposite_address), $this->getInputCharset()); } catch (Exception $e) { throw new SDKRuntimeException("http请求失败:" + $e . getMessage()); } catch (SDKRuntimeException $e) { die($e->errorMessage()); } $xmlParse = new XmlParseUtil(); return $xmlParse->openapiXmlToMap($queryXml, $this->getInputCharset()); }
/** * 生成支付跳转链接 * * @return Wap支付中心URL * @throws Exception Wap支付中心连接异常, Wap支付中心初始化返回异常 */ function getURL() { $paraString = parent::genParaStr(); $domain = parent::getDomain(); $url = $domain . parent::$this->WAP_PAY_OPPOSITE_ADDRESS . '?' . $paraString; try { $http = new HttpClientUtil(); $util = new XmlParseUtil(); $str = $http->httpClientCall($url, "utf-8"); $wapPayInitResponse = new WapPayInitResponse($util->openapiXmlToMap($str, "utf-8"), parent::getSecretKey()); } catch (SDKRuntimeException $e) { die($e->errorMessage()); throw new SDKRuntimeException('Wap支付中心连接异常.' . $e->getMessage(), e); } if ($wapPayInitResponse && $wapPayInitResponse->isRetCodeOK()) { return $wapPayInitResponse->getURL(); } else { throw new SDKRuntimeException('Wap支付中心初始化返回异常.' . $wapPayInitResponse->getMessage()); } }
function CommonResponse5($xml, $charset, $secretKey, $hasRetcode, $hasSign) { $xmlUtil = new XmlParseUtil(); $this->CommonResponse4($xmlUtil->openapiXmlToMap($xml, $charset), $secretKey, $hasRetcode, $hasSign); }