From 499f51dc148632e5382b62f68fd4ba7ffb8d6c03 Mon Sep 17 00:00:00 2001 From: ZweiCD <416931358@qq.com> Date: Mon, 11 May 2020 10:11:02 +0800 Subject: [PATCH] update --- src/QimenWms.php | 19 ++++++++++++------- src/XinyiWms.php | 34 +++++++++++++++------------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/QimenWms.php b/src/QimenWms.php index 855463c..a4a78c0 100644 --- a/src/QimenWms.php +++ b/src/QimenWms.php @@ -401,14 +401,8 @@ class QimenWms extends BaseWms implements WmsInterface $query['sign'] = $sign; $response = $this->post($body, $query); $content = $response->getBody()->getContents(); - $result = XML2Array::createArray($content); - $isSuccess = (empty($result) || !is_array($result) || $result['response']['flag'] != 'success') ? false : true; - $result = [ - 'success' => $isSuccess, - 'response' => $isSuccess ? $result['response'] : $result, - ]; - return $result; + return $this->getResponse($content); } final protected function post($body, $params = [], $headers = ['content-type' => 'text/xml; charset = utf-8'], $ret = []) { @@ -423,6 +417,17 @@ class QimenWms extends BaseWms implements WmsInterface return $result; } + function getResponse($content) { + $result = XML2Array::createArray($content); + + $isSuccess = (empty($result) || !is_array($result) || $result['response']['flag'] != 'success') ? false : true; + $result = [ + 'success' => $isSuccess, + 'response' => $isSuccess ? $result['response'] : $result, + ]; + return $result; + } + /** * 确认回传方法 * @var array diff --git a/src/XinyiWms.php b/src/XinyiWms.php index 1560f2a..5e07e3f 100644 --- a/src/XinyiWms.php +++ b/src/XinyiWms.php @@ -433,16 +433,6 @@ class XinyiWms extends BaseWms implements WmsInterface return $params; } - /** - * @发送请求 - * @param $body - * @param array $params - * @param array $headers - * @param array $ret - * @return array|\DOMDocument - * @throws \Exception - * @throws \GuzzleHttp\Exception\GuzzleException - */ final protected function post($body, $params = [], $headers = ['content-type' => 'text/xml; charset = utf-8'], $ret = []) { $url = $this->config['base_uri']; $url = $url . http_build_query($params); @@ -453,8 +443,19 @@ class XinyiWms extends BaseWms implements WmsInterface $client = new Client(); $response = $client->request('POST', $url, $data); $content = $response->getBody()->getContents(); - $ret = XML2Array::createArray($content); - return $ret; + + return $content; + } + + function getResponse($content) { + $result = XML2Array::createArray($content); + $isSuccess = (empty($result) || !is_array($result) || $result['response']['flag'] != 'success') ? false : true; + $response = [ + 'success' => $isSuccess, + 'response' => $isSuccess ? $result['response'] : $result, + ]; + + return $response; } public function xmlPost($method, $params) @@ -462,14 +463,9 @@ class XinyiWms extends BaseWms implements WmsInterface $xml = Array2XML::createXML('request', $params); $body = $xml->saveXML(); $res = $this->createSign($method, $body); - $result = $this->post($body, $res); + $content = $this->post($body, $res); - $isSuccess = (empty($result) || !is_array($result) || $result['response']['flag'] != 'success') ? false : true; - $response = [ - 'success' => $isSuccess, - 'response' => $isSuccess ? $result['response'] : $result, - ]; - return $response; + return $this->getResponse($content); } /**