From 8443f20710d278edf5c6a33fbcbc8bdefac333dc Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Thu, 14 Oct 2021 11:02:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=8D=E9=81=A5?= =?UTF-8?q?=E6=B8=B8=E6=B5=8B=E8=AF=95=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/GameApiController.class.php | 1 - .../Base/Service/GameRebateService.class.php | 4 +- Application/Base/Tool/GameResource.class.php | 3 + .../Tool/GameResource/XyyClient.class.php | 100 +++++----- .../Tool/GameResource/XyyXmjsClient.class.php | 171 ++++++++++++++++++ 5 files changed, 225 insertions(+), 54 deletions(-) create mode 100644 Application/Base/Tool/GameResource/XyyXmjsClient.class.php diff --git a/Application/Admin/Controller/GameApiController.class.php b/Application/Admin/Controller/GameApiController.class.php index b5f5f153f..16d8e43bd 100644 --- a/Application/Admin/Controller/GameApiController.class.php +++ b/Application/Admin/Controller/GameApiController.class.php @@ -14,7 +14,6 @@ use think\Db; use Base\Tool\GameResource; use Base\Tool\GameResource\SbcqClient; use Base\Tool\GameResource\XlqyClient; -use Base\Tool\GameResource\XyyClient; class GameApiController extends Think { diff --git a/Application/Base/Service/GameRebateService.class.php b/Application/Base/Service/GameRebateService.class.php index 6dc49bfea..d9149ffd2 100644 --- a/Application/Base/Service/GameRebateService.class.php +++ b/Application/Base/Service/GameRebateService.class.php @@ -3,7 +3,7 @@ namespace Base\Service; use Base\Tool\GameResource\SbcqClient; use Base\Tool\GameResource\XlqyClient; -use Base\Tool\GameResource\XyyClient; +use Base\Tool\GameResource\XyyXmjsClient; use Exception; use GuzzleHttp\Client; @@ -93,7 +93,7 @@ class GameRebateService $client = null; switch ($baseGameId) { case 70: - $client = new XyyClient(); + $client = new XyyXmjsClient(); break; case 73: $client = new SbcqClient(); diff --git a/Application/Base/Tool/GameResource.class.php b/Application/Base/Tool/GameResource.class.php index d61643907..451e4afc4 100644 --- a/Application/Base/Tool/GameResource.class.php +++ b/Application/Base/Tool/GameResource.class.php @@ -9,6 +9,7 @@ use Base\Tool\GameResource\YzchzbClient; use Base\Tool\GameResource\LsxxClient; use Base\Tool\GameResource\LeyouClient; use Base\Tool\GameResource\XlqyClient; +use Base\Tool\GameResource\XyyClient; /** * 游戏资源接口 @@ -37,6 +38,8 @@ class GameResource 286 => LeyouClient::class, // 烈火长歌行(安卓版) 291 => XlqyClient::class, // 玄灵契约(安卓版) 292 => XlqyClient::class, // 玄灵契约(苹果版) + 256 => XyyClient::class, // 逍遥游(安卓版) + 257 => XyyClient::class, // 逍遥游(苹果版) ]; public function __construct($game) diff --git a/Application/Base/Tool/GameResource/XyyClient.class.php b/Application/Base/Tool/GameResource/XyyClient.class.php index 91dbfe513..8a2e9dfb1 100644 --- a/Application/Base/Tool/GameResource/XyyClient.class.php +++ b/Application/Base/Tool/GameResource/XyyClient.class.php @@ -4,30 +4,39 @@ namespace Base\Tool\GameResource; use Base\Tool\Log; use GuzzleHttp\Client; -use GuzzleHttp\Exception\RequestException; /** - * 逍遥游之仙魔降世-测试资源接口 + * 逍遥游-测试资源接口 */ class XyyClient { const SIGN_NAME = 'sign'; const SUCCESS = '0000'; - const SIGN_KEY = 'Eza65532qaOIAAWasdq962aqweasd'; + const SIGN_KEY = '51a447dc409b785af03e41a2d5014879'; protected $client; private $apis = [ - 'send-gold' => ['uri' => '', 'method' => 'get'], - 'send-email' => ['uri' => '', 'method' => 'get'], - 'self-apply-foster' => ['uri' => '', 'method' => 'get'], + 'provide' => ['uri' => '/Api/Statis/sendgold', 'method' => 'post'], + ]; + + private $messages = [ + 0 => '发送成功', + -1 => '参数传递不完整', + -2 => '奖金池元宝数量不足', + -3 => '奖金池绑定元宝数量不足', + -4 => '元宝发送失败,联系管理员', + -5 => '签名校验失败,检查加密串', + -6 => '请求超时,当前时间戳超过300ms', + -7 => '角色不存在', + -9 => '重复发送,同一角色重复发送时间间隔10s', ]; public function __construct() { $this->client = new Client([ - 'base_uri' => 'http://rebate.99you.cn/xyy_apply.php/23400/', + 'base_uri' => 'http://x3wm.dgcgame.com:82', 'timeout' => 10.0, ]); } @@ -43,7 +52,7 @@ class XyyClient return $this->request($api, $params); } catch (\Exception $e) { $env = C('APP_ENV', null, 'prod'); - Log::error('rebate:XYY ' . $e->getMessage()); + Log::error('ts:XYY ' . $e->getMessage()); return ['code' => 3, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []]; } } @@ -64,8 +73,8 @@ class XyyClient 'form_params' => $params, ]); $result = (string)$response->getBody(); - Log::info('rebate:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); - return json_decode($result, true); + Log::info('ts:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); + return ['code' => $result, 'msg' => $this->messages[$result] ?? '未知错误' , 'data' => []]; } protected function get($uri, array $params = []) @@ -75,50 +84,29 @@ class XyyClient 'query' => $params, ]); $result = (string)$response->getBody(); - Log::info('rebate:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); - return json_decode($result, true); + Log::info('ts:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); + return ['code' => $result, 'msg' => $this->messages[$result] ?? '未知错误' , 'data' => []]; } - protected function sign($name, $params) + protected function sign($params) { - if ($name == 'send-email') { - return md5($params['prop_id'].$params['serverid'].$params['role_id'].self::SIGN_KEY); - } elseif ($name == 'send-gold') { - return md5($params['money'].$params['serverid'].$params['role_id'].self::SIGN_KEY); - } else { - return ''; - } - } - - public function sendEmail($giftItem, $order) - { - $data = [ - 'act' => 'send_email', - 'serverid' => $order['server_id'], - 'role_id' => $order['role_id'], - 'prop_id' => $giftItem['id'], - ]; - - $result = $this->api('send-email', $data); - return $this->getCommonResult($result); - } - - public function sendGold($gold, $order) - { - $data = [ - 'act' => 'sendgold', - 'serverid' => $order['server_id'], - 'role_id' => $order['role_id'], - 'money' => $gold, - ]; - - $result = $this->api('send-gold', $data); - return $this->getCommonResult($result); + return md5( + $params['actors'] . + $params['pfrom_id'] . + $params['server_id'] . + $params['sendnum_yb'] . + $params['sendnum_by'] . + $params['email_title'] . + $params['email_content'] . + self::SIGN_KEY . + $params['time']. + $params['type'] + ); } private function getCommonResult($result) { - if ($result['code'] == 1) { + if ($result['code'] == 0) { return [ 'status' => true, 'message' => $result['msg'], @@ -133,12 +121,22 @@ class XyyClient } } - /** - * @todo 暂时没有测试资源 - */ public function apply($order, $role) { - return $this->sendGold($order['ref_amount'], $role); + $data = [ + 'pfrom_id' => 600, + 'server_id' => $role['server_id'], + 'actors' => $role['role_id'], + 'sendnum_yb' => intval($order['ref_amount']) * 10, + 'sendnum_by' => 0, + 'email_title' => '扶持元宝', + 'email_content' => '请查收', + 'time' => time(), + 'type' => 0, + // 'rebate' => 2, + ]; + $result = $this->api('provide', $data); + return $this->getCommonResult($result); } public function getResourceTypes($deviceType) diff --git a/Application/Base/Tool/GameResource/XyyXmjsClient.class.php b/Application/Base/Tool/GameResource/XyyXmjsClient.class.php new file mode 100644 index 000000000..b7b7163c6 --- /dev/null +++ b/Application/Base/Tool/GameResource/XyyXmjsClient.class.php @@ -0,0 +1,171 @@ + ['uri' => '', 'method' => 'get'], + 'send-email' => ['uri' => '', 'method' => 'get'], + 'self-apply-foster' => ['uri' => '', 'method' => 'get'], + ]; + + public function __construct() + { + $this->client = new Client([ + 'base_uri' => 'http://rebate.99you.cn/xyy_apply.php/23400/', + 'timeout' => 10.0, + ]); + } + + public function api($name, array $params = []) + { + $api = $this->apis[$name] ?? null; + if (is_null($api)) { + throw new \Exception('接口不存在'); + } + $params[self::SIGN_NAME] = $this->sign($name, $params); + try { + return $this->request($api, $params); + } catch (\Exception $e) { + $env = C('APP_ENV', null, 'prod'); + Log::error('rebate:XYYXMJS ' . $e->getMessage()); + return ['code' => 3, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []]; + } + } + + public function request($api, $params) + { + if ($api['method'] == 'get') { + return $this->get($api['uri'], $params); + } else { + return $this->post($api['uri'], $params); + } + } + + protected function post($uri, array $params = []) + { + $response = $this->client->post($uri, [ + 'verify' => false, + 'form_params' => $params, + ]); + $result = (string)$response->getBody(); + Log::info('rebate:XYYXMJS ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); + return json_decode($result, true); + } + + protected function get($uri, array $params = []) + { + $response = $this->client->get($uri, [ + 'verify' => false, + 'query' => $params, + ]); + $result = (string)$response->getBody(); + Log::info('rebate:XYYXMJS ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); + return json_decode($result, true); + } + + protected function sign($name, $params) + { + if ($name == 'send-email') { + return md5($params['prop_id'].$params['serverid'].$params['role_id'].self::SIGN_KEY); + } elseif ($name == 'send-gold') { + return md5($params['money'].$params['serverid'].$params['role_id'].self::SIGN_KEY); + } else { + return ''; + } + } + + public function sendEmail($giftItem, $order) + { + $data = [ + 'act' => 'send_email', + 'serverid' => $order['server_id'], + 'role_id' => $order['role_id'], + 'prop_id' => $giftItem['id'], + ]; + + $result = $this->api('send-email', $data); + return $this->getCommonResult($result); + } + + public function sendGold($gold, $order) + { + $data = [ + 'act' => 'sendgold', + 'serverid' => $order['server_id'], + 'role_id' => $order['role_id'], + 'money' => $gold, + ]; + + $result = $this->api('send-gold', $data); + return $this->getCommonResult($result); + } + + private function getCommonResult($result) + { + if ($result['code'] == 1) { + return [ + 'status' => true, + 'message' => $result['msg'], + 'result' => $result + ]; + } else { + return [ + 'status' => false, + 'message' => $result['msg'], + 'result' => $result + ]; + } + } + + /** + * @todo 暂时没有测试资源 + */ + public function apply($order, $role) + { + return $this->sendGold($order['ref_amount'], $role); + } + + public function getResourceTypes($deviceType) + { + if ($deviceType == 'andriod') { + return [['id' => 1, 'name' => '通用', 'device_type' => 'andriod']]; + } elseif ($deviceType == 'ios') { + return [['id' => 2, 'name' => '通用', 'device_type' => 'ios']]; + } + } + + public function getResources($typeId, $deviceType) + { + return [ + 1 => ['ref_id' => 1, 'name' => '60元宝', 'amount' => 6], + 2 => ['ref_id' => 2, 'name' => '300元宝', 'amount' => 30], + 3 => ['ref_id' => 3, 'name' => '980元宝', 'amount' => 98], + 4 => ['ref_id' => 4, 'name' => '1280元宝', 'amount' => 128], + 5 => ['ref_id' => 5, 'name' => '1980元宝', 'amount' => 198], + 6 => ['ref_id' => 6, 'name' => '3280元宝', 'amount' => 328], + 7 => ['ref_id' => 7, 'name' => '6480元宝', 'amount' => 648], + 8 => ['ref_id' => 8, 'name' => '10000元宝', 'amount' => 1000], + 9 => ['ref_id' => 9, 'name' => '20000元宝', 'amount' => 2000], + 10 => ['ref_id' => 10, 'name' => '30000元宝', 'amount' => 3000], + 11 => ['ref_id' => 11, 'name' => '50000元宝', 'amount' => 5000], + 12 => ['ref_id' => 12, 'name' => '100000元宝', 'amount' => 10000], + 13 => ['ref_id' => 13, 'name' => '200000元宝', 'amount' => 20000], + ]; + } +} \ No newline at end of file From efce5e7aa8a6b0c15f0f0c94304530f43e23edc1 Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Fri, 15 Oct 2021 13:41:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/GameApiController.class.php | 13 +++++++++ .../Tool/GameResource/XyyClient.class.php | 28 ++++++------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Application/Admin/Controller/GameApiController.class.php b/Application/Admin/Controller/GameApiController.class.php index 16d8e43bd..46389cc44 100644 --- a/Application/Admin/Controller/GameApiController.class.php +++ b/Application/Admin/Controller/GameApiController.class.php @@ -14,6 +14,7 @@ use think\Db; use Base\Tool\GameResource; use Base\Tool\GameResource\SbcqClient; use Base\Tool\GameResource\XlqyClient; +use Base\Tool\GameResource\XyyClient; class GameApiController extends Think { @@ -65,6 +66,18 @@ class GameApiController extends Think { public function send() { + $role = [ + 'role_id' => '93323379', + 'server_id' => '89', + ]; + $order = [ + 'ref_amount' => 10, + ]; + $client = new XyyClient(); + $result = $client->apply($order, $role); + var_dump($result); + + return; $game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => 291])->find(); $role = [ 'role_id' => '829403', diff --git a/Application/Base/Tool/GameResource/XyyClient.class.php b/Application/Base/Tool/GameResource/XyyClient.class.php index 8a2e9dfb1..c7d71976d 100644 --- a/Application/Base/Tool/GameResource/XyyClient.class.php +++ b/Application/Base/Tool/GameResource/XyyClient.class.php @@ -21,18 +21,6 @@ class XyyClient 'provide' => ['uri' => '/Api/Statis/sendgold', 'method' => 'post'], ]; - private $messages = [ - 0 => '发送成功', - -1 => '参数传递不完整', - -2 => '奖金池元宝数量不足', - -3 => '奖金池绑定元宝数量不足', - -4 => '元宝发送失败,联系管理员', - -5 => '签名校验失败,检查加密串', - -6 => '请求超时,当前时间戳超过300ms', - -7 => '角色不存在', - -9 => '重复发送,同一角色重复发送时间间隔10s', - ]; - public function __construct() { $this->client = new Client([ @@ -47,7 +35,7 @@ class XyyClient if (is_null($api)) { throw new \Exception('接口不存在'); } - $params[self::SIGN_NAME] = $this->sign($name, $params); + $params[self::SIGN_NAME] = $this->sign($params); try { return $this->request($api, $params); } catch (\Exception $e) { @@ -74,7 +62,7 @@ class XyyClient ]); $result = (string)$response->getBody(); Log::info('ts:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); - return ['code' => $result, 'msg' => $this->messages[$result] ?? '未知错误' , 'data' => []]; + return json_decode($result, true); } protected function get($uri, array $params = []) @@ -85,23 +73,23 @@ class XyyClient ]); $result = (string)$response->getBody(); Log::info('ts:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); - return ['code' => $result, 'msg' => $this->messages[$result] ?? '未知错误' , 'data' => []]; + return json_decode($result, true); } protected function sign($params) { - return md5( + $signStr = $params['actors'] . $params['pfrom_id'] . $params['server_id'] . $params['sendnum_yb'] . $params['sendnum_by'] . - $params['email_title'] . - $params['email_content'] . + urlencode($params['email_title']) . + urlencode($params['email_content']) . self::SIGN_KEY . $params['time']. - $params['type'] - ); + $params['type']; + return md5($signStr); } private function getCommonResult($result)