master
elf 3 years ago
commit 6a16789964

@ -66,10 +66,17 @@ class GameApiController extends Think {
public function send() public function send()
{ {
$order = M('rebate_orders', 'tab_')->where(['id' => 106])->find(); $role = [
$service = new GameRebateService(); 'role_id' => '93323379',
$result = $service->sendByOrder($order); 'server_id' => '89',
];
$order = [
'ref_amount' => 10,
];
$client = new XyyClient();
$result = $client->apply($order, $role);
var_dump($result); var_dump($result);
return; return;
$game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => 291])->find(); $game = M('game', 'tab_')->field(['id', 'sdk_version'])->where(['id' => 291])->find();
$role = [ $role = [

@ -3,7 +3,7 @@ namespace Base\Service;
use Base\Tool\GameResource\SbcqClient; use Base\Tool\GameResource\SbcqClient;
use Base\Tool\GameResource\XlqyClient; use Base\Tool\GameResource\XlqyClient;
use Base\Tool\GameResource\XyyClient; use Base\Tool\GameResource\XyyXmjsClient;
use Exception; use Exception;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Think\Model; use Think\Model;
@ -115,7 +115,7 @@ class GameRebateService
$client = null; $client = null;
switch ($baseGameId) { switch ($baseGameId) {
case 70: case 70:
$client = new XyyClient(); $client = new XyyXmjsClient();
break; break;
case 73: case 73:
$client = new SbcqClient(); $client = new SbcqClient();

@ -9,6 +9,7 @@ use Base\Tool\GameResource\YzchzbClient;
use Base\Tool\GameResource\LsxxClient; use Base\Tool\GameResource\LsxxClient;
use Base\Tool\GameResource\LeyouClient; use Base\Tool\GameResource\LeyouClient;
use Base\Tool\GameResource\XlqyClient; use Base\Tool\GameResource\XlqyClient;
use Base\Tool\GameResource\XyyClient;
/** /**
* 游戏资源接口 * 游戏资源接口
@ -37,6 +38,8 @@ class GameResource
286 => LeyouClient::class, // 烈火长歌行(安卓版) 286 => LeyouClient::class, // 烈火长歌行(安卓版)
291 => XlqyClient::class, // 玄灵契约(安卓版) 291 => XlqyClient::class, // 玄灵契约(安卓版)
292 => XlqyClient::class, // 玄灵契约(苹果版) 292 => XlqyClient::class, // 玄灵契约(苹果版)
256 => XyyClient::class, // 逍遥游(安卓版)
257 => XyyClient::class, // 逍遥游(苹果版)
]; ];
public function __construct($game) public function __construct($game)

@ -4,30 +4,27 @@ namespace Base\Tool\GameResource;
use Base\Tool\Log; use Base\Tool\Log;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
/** /**
* 逍遥游之仙魔降世-测试资源接口 * 逍遥游-测试资源接口
*/ */
class XyyClient class XyyClient
{ {
const SIGN_NAME = 'sign'; const SIGN_NAME = 'sign';
const SUCCESS = '0000'; const SUCCESS = '0000';
const SIGN_KEY = 'Eza65532qaOIAAWasdq962aqweasd'; const SIGN_KEY = '51a447dc409b785af03e41a2d5014879';
protected $client; protected $client;
private $apis = [ private $apis = [
'send-gold' => ['uri' => '', 'method' => 'get'], 'provide' => ['uri' => '/Api/Statis/sendgold', 'method' => 'post'],
'send-email' => ['uri' => '', 'method' => 'get'],
'self-apply-foster' => ['uri' => '', 'method' => 'get'],
]; ];
public function __construct() public function __construct()
{ {
$this->client = new Client([ $this->client = new Client([
'base_uri' => 'http://rebate.99you.cn/xyy_apply.php/23400/', 'base_uri' => 'http://x3wm.dgcgame.com:82',
'timeout' => 10.0, 'timeout' => 10.0,
]); ]);
} }
@ -38,12 +35,12 @@ class XyyClient
if (is_null($api)) { if (is_null($api)) {
throw new \Exception('接口不存在'); throw new \Exception('接口不存在');
} }
$params[self::SIGN_NAME] = $this->sign($name, $params); $params[self::SIGN_NAME] = $this->sign($params);
try { try {
return $this->request($api, $params); return $this->request($api, $params);
} catch (\Exception $e) { } catch (\Exception $e) {
$env = C('APP_ENV', null, 'prod'); $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' => []]; return ['code' => 3, 'msg' => '接口请求错误。' . ($env == 'prod' ? '' : $e->getMessage()) , 'data' => []];
} }
} }
@ -64,7 +61,7 @@ class XyyClient
'form_params' => $params, 'form_params' => $params,
]); ]);
$result = (string)$response->getBody(); $result = (string)$response->getBody();
Log::info('rebate:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); Log::info('ts:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
return json_decode($result, true); return json_decode($result, true);
} }
@ -75,50 +72,29 @@ class XyyClient
'query' => $params, 'query' => $params,
]); ]);
$result = (string)$response->getBody(); $result = (string)$response->getBody();
Log::info('rebate:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result); Log::info('ts:XYY ' . $uri . ' -- '. json_encode($params) . ' -- '. $result);
return json_decode($result, true); return json_decode($result, true);
} }
protected function sign($name, $params) protected function sign($params)
{ {
if ($name == 'send-email') { $signStr =
return md5($params['prop_id'].$params['serverid'].$params['role_id'].self::SIGN_KEY); $params['actors'] .
} elseif ($name == 'send-gold') { $params['pfrom_id'] .
return md5($params['money'].$params['serverid'].$params['role_id'].self::SIGN_KEY); $params['server_id'] .
} else { $params['sendnum_yb'] .
return ''; $params['sendnum_by'] .
} urlencode($params['email_title']) .
} urlencode($params['email_content']) .
self::SIGN_KEY .
public function sendEmail($giftItem, $order) $params['time'].
{ $params['type'];
$data = [ return md5($signStr);
'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) private function getCommonResult($result)
{ {
if ($result['code'] == 1) { if ($result['code'] == 0) {
return [ return [
'status' => true, 'status' => true,
'message' => $result['msg'], 'message' => $result['msg'],
@ -133,12 +109,22 @@ class XyyClient
} }
} }
/**
* @todo 暂时没有测试资源
*/
public function apply($order, $role) 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) public function getResourceTypes($deviceType)

@ -0,0 +1,171 @@
<?php
namespace Base\Tool\GameResource;
use Base\Tool\Log;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
/**
* 逍遥游之仙魔降世-测试资源接口
*/
class XyyXmjsClient
{
const SIGN_NAME = 'sign';
const SUCCESS = '0000';
const SIGN_KEY = 'Eza65532qaOIAAWasdq962aqweasd';
protected $client;
private $apis = [
'send-gold' => ['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],
];
}
}
Loading…
Cancel
Save