From 778d95087dce84a55c8f4480b0c9e92c0ecd38a0 Mon Sep 17 00:00:00 2001 From: gongfuxiang <2499232802@qq.com> Date: Tue, 23 Oct 2018 01:48:43 +0800 Subject: [PATCH] debug --- .../Controller/AlipayLifeController.class.php | 1 + .../Application/Library/AlipayLife.class.php | 42 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/service/Application/Api/Controller/AlipayLifeController.class.php b/service/Application/Api/Controller/AlipayLifeController.class.php index 742d7977e..0d69b6955 100644 --- a/service/Application/Api/Controller/AlipayLifeController.class.php +++ b/service/Application/Api/Controller/AlipayLifeController.class.php @@ -39,6 +39,7 @@ class AlipayLifeController extends CommonController // 参数 $params = $_POST; + $obj = new \Library\AlipayLife($params); if(empty($params['service'])) { die('service error'); diff --git a/service/Application/Library/AlipayLife.class.php b/service/Application/Library/AlipayLife.class.php index f4261c0c7..119c159a6 100644 --- a/service/Application/Library/AlipayLife.class.php +++ b/service/Application/Library/AlipayLife.class.php @@ -36,7 +36,7 @@ class AlipayLife $this->params = $params; $this->xml_data = isset($params['biz_content']) ? $this->xmlToArray($params['biz_content']) : ''; - $this->xml_data = json_decode(json_encode((array) simplexml_load_string($params['biz_content'])), true); + $this->xml_data = $this->xml_to_array($params['biz_content']); file_put_contents('./pppppp.php', "xml_data, true).";\n\r?>"); $this->life_data = isset($this->xml_data['AppId']) ? AlipayLifeService::AppidLifeRow(['appid'=>$this->xml_data['AppId']]) : ''; @@ -47,6 +47,46 @@ class AlipayLife } } + public function xml_to_array($xml) + { + // 创建解析器 + $parser = xml_parser_create(); + // 将 XML 数据解析到数组中 + xml_parse_into_struct($parser, $xml, $vals, $index); + // 释放解析器 + xml_parser_free($parser); + // 数组处理 + $arr = array(); + $t=0; + foreach($vals as $value) { + $type = $value['type']; + $tag = $value['tag']; + $level = $value['level']; + $attributes = isset($value['attributes'])?$value['attributes']:""; + $val = isset($value['value'])?$value['value']:""; + switch ($type) { + case 'open': + if ($attributes != "" || $val != "") { + $arr[$t]['tag'] = $tag; + $arr[$t]['attributes'] = $attributes; + $arr[$t]['level'] = $level; + $t++; + } + break; + case "complete": + if ($attributes != "" || $val != "") { + $arr[$t]['tag'] = $tag; + $arr[$t]['attributes'] = $attributes; + $arr[$t]['val'] = $val; + $arr[$t]['level'] = $level; + $t++; + } + break; + } + } + return $arr; + } + /** * [MyRsaSign 签名字符串] * @author Devil