-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace WonderGame\EsUtility\Common\Classes; | ||
|
||
use App\Model\Package; | ||
use EasySwoole\HttpClient\Bean\Response; | ||
use EasySwoole\HttpClient\HttpClient; | ||
use EasySwoole\Http\AbstractInterface\Controller; | ||
|
||
/** | ||
* @extends Controller | ||
*/ | ||
trait FixBugTrait | ||
{ | ||
protected function fixProxyUrl() | ||
{ | ||
$servername = config('SERVNAME');; | ||
$pkgbnd = 'com.wonderland.bombtankad'; | ||
$gameid = 5; | ||
$input = $this->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; | ||
} | ||
} |