From e1027d837337948a315c0849bd7733d614b4fe48 Mon Sep 17 00:00:00 2001 From: Joyboo Date: Thu, 14 Apr 2022 21:45:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=B8=BA=E6=8C=87=E5=AE=9A=E5=8C=85=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Classes/FixBugTrait.php | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/Common/Classes/FixBugTrait.php diff --git a/src/Common/Classes/FixBugTrait.php b/src/Common/Classes/FixBugTrait.php new file mode 100644 index 0000000..b949363 --- /dev/null +++ b/src/Common/Classes/FixBugTrait.php @@ -0,0 +1,81 @@ +request()->getRequestParam(); + if (explode('-', $servername)[0] !== 'xjp' + && (isset($input['versioncode']) && intval($input['versioncode']) <= 6) + && (isset($input['pkgbnd']) && $input['pkgbnd'] === $pkgbnd) + && (isset($input['gameid']) && $input['gameid'] == $gameid) + ) { + return $this->proxyServer($pkgbnd); + } + return true; + } + + protected function proxyServer($pkgbnd) + { + $aname = explode('_', APP_NAME)[1]; + /** @var Package $Package */ + $Package = model('Package'); + if ($domain = $Package->cacheInfo(['pkgbnd' => $pkgbnd])['domain'][$aname]) + { + $Uri = $this->request()->getUri(); + $url = rtrim($domain, '/') . $Uri->getPath(); + if ($Uri->getQuery()) { + $url .= '?' . $Uri->getQuery(); + } + + $headers = $this->request()->getHeaders(); + $headerArray = []; + foreach ($headers as $hk => $hd) { + if (is_array($hd)) { + $hd = current($hd); + } + $headerArray[$hk] = $hd; + } + + $HttpClient = new HttpClient($url); + $HttpClient->setHeaders($headerArray, true, false); + $method = strtolower($this->request()->getMethod()); + + /** @var Response $response */ + $response = null; + // 不需要body的方法 + if (in_array($method, ['get', 'head', 'trace', 'delete'])) + { + $response = $HttpClient->$method(); + } + elseif (in_array($method, ['post', 'patch', 'put', 'download'])) + { + $envKey = 'envkeydata'; + $input = $this->request()->getRequestParam(); + unset($input[$envKey]); + $rsa = config('RSA'); + $openssl = LamOpenssl::getInstance($rsa['private'], $rsa['public']); + $post = [$envKey => $openssl->encrypt(json_encode($input))]; + $response = $HttpClient->$method($post); + } + + $array = json_decode($response->getBody(), true); + $this->writeJson($array['code'], $array['result'] ?? [], $array['message']); + return false; + } + return false; + } +}