Browse Source

add to local

stanley-king 4 years atrás
parent
commit
8170877d15
2 changed files with 36 additions and 46 deletions
  1. 17 21
      test/TestRBridge.php
  2. 19 25
      wsd_bridge.php

File diff suppressed because it is too large
+ 17 - 21
test/TestRBridge.php


+ 19 - 25
wsd_bridge.php

@@ -42,18 +42,14 @@ class WSDBridge
                 socket_set_option($client, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 8, 'usec' => 0]);
 
                 $body = $this->read_order($client);
-                if(!empty($body)) {
-                    Log::record("req:{$body}",Log::DEBUG);
-                    $response = $this->relay_request($body);
-
-                    $encode = mb_detect_encoding($response, ['GB2312','GBK','UTF-8']);
-                    $response = mb_convert_encoding($response,$encode, 'GBK');
-
-                    socket_write($client,$response);
-                    Log::record("resp:{$response}",Log::DEBUG);
-                }
-                else {
-                    Log::record("不合法的包",Log::DEBUG);
+                if (!empty($body)) {
+                    Log::record("req:{$body}", Log::DEBUG);
+                    $resp = $this->relay_request($body);
+                    $resp = mb_convert_encoding($resp, 'GBK', 'UTF-8');
+                    socket_write($client, $resp);
+                    Log::record("resp:{$resp}", Log::DEBUG);
+                } else {
+                    Log::record("不合法的包", Log::DEBUG);
                 }
 
                 socket_close($client);
@@ -66,12 +62,11 @@ class WSDBridge
         $url = BASE_SITE_URL . "/mobile/bridge_shr.php";
         $headers = ['Content-Type: application/json'];
 
-        $resp = http_post_data($url,$body,$headers);
-        if($resp === false) {
-            Log::record("Net error.",Log::ERR);
+        $resp = http_post_data($url, $body, $headers);
+        if ($resp === false) {
+            Log::record("Net error.", Log::ERR);
             return $this->err_body($body);
-        }
-        else {
+        } else {
             return $resp;
         }
     }
@@ -87,9 +82,9 @@ class WSDBridge
         $result = [
             'action' => 'CZ',
             'chargeId' => $params['chargeId'],
-            'retCode'  => $retCode,
+            'retCode' => $retCode,
             'retDetail' => $retDetail,
-            'retRsn' => $params['retRsn'] ];
+            'retRsn' => $params['retRsn']];
 
         $body = "{$params['chargeId']}{$retCode}{$params['retRsn']}" . WSDBridge::KEY;
         $sign = md5($body);
@@ -109,15 +104,14 @@ class WSDBridge
         } else {
             $content .= $buf;
         }
-        Log::record("buf={$buf}",Log::DEBUG);
-        $content = mb_convert_encoding($content,'GBK', 'UTF-8');
-        Log::record("content={$content}",Log::DEBUG);
+        Log::record("buf={$buf}", Log::DEBUG);
+        $content = mb_convert_encoding($content, 'UTF-8', 'GBK');
+        Log::record("content={$content}", Log::DEBUG);
 
         if ($this->isbody($content)) {
             return $content;
-        }
-        else {
-            Log::record("err body = {$content}",Log::DEBUG);
+        } else {
+            Log::record("err body = {$content}", Log::DEBUG);
             return false;
         }
     }