Browse Source

check feihan code

stanley-king 1 year ago
parent
commit
f3d7ca6ecb
2 changed files with 27 additions and 10 deletions
  1. 11 1
      helper/refill/api/xyz/feihan/RefillOil.php
  2. 16 9
      test/TestRefill.php

+ 11 - 1
helper/refill/api/xyz/feihan/RefillOil.php

@@ -149,7 +149,17 @@ class RefillOil extends refill\IRefillPhone
 
     public function xmlToArray($xml, $encode = 'GBK')
     {
-        $replace_str = str_replace(' ','','encoding="'.$encode.'"');
+        $getEncoder = function ($xml,$default_encode)
+        {
+            $ret = preg_match("/<?xml\s+[\s\S]*(encoding=[\"']([^\"']*)[\"'])[\s\S]*?>/", $xml, $res);
+            if($ret !== false && count($res) === 3) {
+                return [$res[2], $res[1]];
+            } else {
+                return [$default_encode,'encoding="' . $default_encode . '"'];
+            }
+        };
+
+        [$encode, $replace_str] = $getEncoder($xml, $encode);
         $xml = mb_convert_encoding($xml,"utf-8","{$encode}");
         $xml = str_replace($replace_str, "encoding='utf-8'", $xml);
         return refill\util::xmlToArray($xml);

+ 16 - 9
test/TestRefill.php

@@ -3319,18 +3319,25 @@ class TestRefill extends TestCase
 //        $resp = $provider->notify($params);
     }
 
+    public function testGetXMLEncoding()
+    {
+        $header = '<?xml version="1.0" encoding="GB2312"?>';
+/*        $ret = preg_match("/<?xml\s+[\s\S]*?>/", $header, $res);*/
+        $ret = preg_match("/<?xml\s+[\s\S]*encoding=[\"']([^\"']*)[\"'][\s\S]*?>/", $header, $res);
+    }
+
     public function testfeihan()
     {
-//        $provider = $this->getProvider('feihan', 'RefillOil');
-//        $resp = $provider->balance();
-//        $resp = $provider->add(9030230005180327, 1, 200, ['order_sn' => $this->make_sn()]);
-//        $resp = $provider->query(['order_sn' => '18141682668825332400']);
+        $provider = $this->getProvider('feihan', 'RefillOil');
+        $resp = $provider->balance();
+        $resp = $provider->add(9030230005180327, 1, 200, ['order_sn' => $this->make_sn()]);
+        $resp = $provider->query(['order_sn' => '18141682668825332400']);
 
-        $body = '{"err_msg":"","ordersuccesstime":"20230428161615","sporder_id":"18141682668825332400","ret_code":"1"}';
-        $params = json_decode($body, true);
-        $provider = $this->getProvider('feihan', 'RefillCallBack');
-        $ret = $provider->verify($params);
-        $resp = $provider->notify($params);
+//        $body = '{"err_msg":"","ordersuccesstime":"20230428161615","sporder_id":"18141682668825332400","ret_code":"1"}';
+//        $params = json_decode($body, true);
+//        $provider = $this->getProvider('feihan', 'RefillCallBack');
+//        $ret = $provider->verify($params);
+//        $resp = $provider->notify($params);
     }
 
     public function testAmingjd()