From 0927cfd3bb8cf87d8eebedea7e907d4e61baab86 Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Wed, 20 Sep 2023 01:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=94=E5=88=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Base/Service/GameRebateService.class.php | 6 +- .../Tool/GameResource/YjlyClient.class.php | 220 ++++++++++++++++++ tt.php | 43 ++++ 3 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 Application/Base/Tool/GameResource/YjlyClient.class.php create mode 100644 tt.php diff --git a/Application/Base/Service/GameRebateService.class.php b/Application/Base/Service/GameRebateService.class.php index 2272eb377..53f7c1b14 100644 --- a/Application/Base/Service/GameRebateService.class.php +++ b/Application/Base/Service/GameRebateService.class.php @@ -2,6 +2,7 @@ namespace Base\Service; use Base\Tool\GameResource\JmxyClient; +use Base\Tool\GameResource\YjlyClient; use Base\Tool\GameResource\ZzylClient; use Think\Model; @@ -50,7 +51,7 @@ class GameRebateService 'L' => 'roleLevel', ]; - public $rebateBaseGameIds = [11, 17]; + public $rebateBaseGameIds = [11, 17, 21]; public function isGiftItemSend($order, $item) { @@ -123,6 +124,9 @@ class GameRebateService case 17: $client = new JmxyClient(); break; + case 21: + $client = new YjlyClient(); + break; default: throw new \Exception('客户端未实现'); break; diff --git a/Application/Base/Tool/GameResource/YjlyClient.class.php b/Application/Base/Tool/GameResource/YjlyClient.class.php new file mode 100644 index 000000000..830708229 --- /dev/null +++ b/Application/Base/Tool/GameResource/YjlyClient.class.php @@ -0,0 +1,220 @@ + ['uri' => '/9vjh/player_mail', 'method' => 'get', 'with' => [ + 'act' => 'send_email' + ]], + ]; + + public function __construct($game = null) + { + $this->client = new Client([ + 'base_uri' => $this->baseUrl, + 'timeout' => 10.0, + ]); + } + + public function api($api, array $params = []) + { + $tmpApi = $api; + $api = $this->apis[$api] ?? null; + if (is_null($api)) { + throw new \Exception('接口不存在'); + } + + $params['appId'] = self::APP_ID; + $params[self::SIGN_NAME] = $this->sign($tmpApi, $params); + if (is_array($api['with'])) { + $params = array_merge($params, $api['with']); + } + + try { + return $this->request($api, $params); + } catch (\Exception $e) { + $env = C('APP_ENV', null, 'prod'); + Log::error('Yjzx ' . $e->getMessage()); + return ['status' => 0, '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('Yjzx ' . 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('Yjzx ' . json_encode($params) . ' ' . $result); + return json_decode($result, true); + } + + protected function sign($name, $params) + { + $signString = ''; + $signString .= $params['appId']; + $signString .= $params['serverId']; + $signString .= $params['roleId']; + $signString .= $params['userId']; + if ($name == 'send-gold') { + $signString .= $params['moneyFen']; + } elseif ($name == 'send-email') { + $signString .= $params['mailData']; + } elseif ($name == 'send-props') { + $signString .= $params['propData']; + } + $signString .= $params['orderNum']; + $signString .= $params['time']; + $signString .= self::SIGN_KEY; + return md5($signString); + } + + // 测试资源 + public function apply($order, $role) + { + throw new Exception('没有接口'); + } + + // + public function sendGold($order, $role) + { + $result = $this->api('send-gold', [ + 'roleId' => $role['role_id'], + 'moneyFen' => intval($order['ref_amount'] * 100), // TODO + 'serverId' => $role['server_id'], + 'userId' => $role['user_id'], + 'orderNum' => $order['order_no'] + ]); + if (intval($result['code']) == 0) { + return [ + 'status' => true, + 'message' => $result['msg'], + 'result' => $result + ]; + } else { + return [ + 'status' => false, + 'message' => $result['msg'], + 'result' => $result ?? [] + ]; + } + } + + public function sendProps($order) + { + $props = []; + $order['props'] = json_decode($order['props'], true); + foreach ($order['props'] as $prop) { + $props[] = [ + 'propId' => $prop['ref_id'], + 'count' => $prop['num'], + ]; + } + $result = $this->api('send-prop', [ + 'roleId' => $order['role_id'], + 'propData' => json_encode($props), + 'serverId' => $order['server_id'], + 'userId' => $order['user_id'], + 'orderNum' => $this->generateOrderNumber($order), + 'time' => time(), + ]); + + if (intval($result['code']) == 0) { + return [ + 'status' => true, + 'message' => $result['msg'], + 'result' => $result + ]; + } else { + return [ + 'status' => false, + 'message' => $result['msg'], + 'result' => $result ?? [] + ]; + } + } + + protected function generateOrderNumber($order, $index = 0) + { + $length = 8 - strlen(strval($order['id'])); + $indexLength = 3 - strlen(strval($index)); + return date('Ymd') . str_repeat('0', $length) . $order['id'] . str_repeat('0', $indexLength) . $index; + } + + public function sendEmail($giftItem, $order) + { + $result = $this->api('send-email', [ + 'serverId' => $order['server_id'], + 'roleId' => $order['role_id'], + 'userId' => $order['user_id'], + 'mailData' => json_encode([['mailId' => $giftItem['id']]]), + 'orderNum' => date("YmdHis").$order['id'].$order['user_id'].$giftItem['id'].rand(1000, 9999), + 'time' => time(), + ]); + if (intval($result['code']) === 0) { + return [ + 'status' => true, + 'message' => $result['msg'], + 'result' => $result + ]; + } else { + return [ + 'status' => false, + 'message' => $result['msg'], + 'result' => $result ?? [] + ]; + } + } + + 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 []; + } +} \ No newline at end of file diff --git a/tt.php b/tt.php new file mode 100644 index 000000000..9e65405fd --- /dev/null +++ b/tt.php @@ -0,0 +1,43 @@ + 'chengfeng', + 'userId' => 5141, // ljl654321 + 'orderNum' => time() . rand(1000, 9999), + 'title' => '测试邮件', + 'content' => '测试礼包发送', + 'packages' => json_encode([ + [ + 'packageId' => '29044', + 'count' => 10, + ], + + ]), + 'serverId' => 1, + 'roleId' => 65740, + 'time' => time(), + ]; + $data['sign'] = sign($data); + var_dump($data); + $ch = curl_init (); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + $response = curl_exec ($ch); + curl_close($ch); + var_dump($response); +} + +function sign($params) { + unset($params['sign']); + ksort($params); + $signString = ''; + foreach ($params as $key => $value) { + $signString .= $value; + } + return md5($signString . 'a3f579b5add2342a7ac07017b7650c45'); +} \ No newline at end of file